firefox 升级策略

/************************************************************************/
//firefox 升级策略

//http://wiki.mozilla.org/Software_Update

//使用HTTPS协议下载升级文件
Downloading the Update [edit]

Firefox will periodically check the Mozilla.org update servers (AUS) for available updates. The update server will return a manifest file (which is a simple XML file) over HTTPS that will point Firefox at the right update package to download.

In silent download mode, Firefox will use byte-range requests (supported by the Mozilla.org mirror network) to download the update package in small pieces. Each time Firefox starts up it will check to see if it should resume downloading the update package. It will not try to download the update package while Firefox is not running. This simplifies the implementation of the downloading system because it enables us to make use of the Firefox networking stack. Firefox will try to minimally impact the user's network bandwidth in the process.

Once the update package has been completely downloaded, it's integrity will be verified by computing a hash (e.g., SHA-2) over the entire update package. This hash will be compared to a hash included in the XML file received from AUS. If the hash checks out, then assuming that Firefox has permission from the user, it will unpack the update package and signal Firefox to start the upgrade process.

//用manifest文件确定升级具体做法 add remove patch replace(在源码中没有发现)
Processing the Update [edit]

At startup, Firefox will look for an update manifest in a fixed location. If it finds the manifest, then assuming it has permission from the user it will launch the update executable to process that manifest.

Before making any changes to the existing Firefox installation, the update executable will scan all files to be modified and verify that they are the expected version. If it finds that any files are not in sync with what it expects to find, then it will not apply the update. Otherwise, it will proceed to either: add, remove, replace, or patch existing files.

Before the update executable exits, it will record status to a log file that will be read by Firefox on next launch to determine if the update was successfully applied. This will allow Firefox to present good UI to the user in the advent of an unexpected problem.

//升级程序要做到以下几点:
Requirements  [edit]

* track current and past updates
* show information on past updates such as time of install, name, etc
* store metadata that allows current updates to be resumed after an application restart
* minimize connection to update server to single connection on initial discovery of update
* remind the user to restart manually stopped updates

//更新检测方法
//1.程序启动检测 2. 每隔24小时检测
The Background Timer  [edit]

The system will automatically check for updates without user intervention:

* every 24 hours
* on the first startup following an update, to check to see if the patch applied is the newest possible update or if there are newer ones.

Regarding critical security updates, it would be useful to the user, if we could display a pop-up or similar sort (like what we have for-- " New updates available ") with the importance of this critical security update. This way we can inform the user the urgent need for the upgrade.

//URL地址详细内容信息
//URL地址有点过于复杂。。。
Update Service URL  [edit]

The Service URL needs to incorporate data in these dimensions so as to reduce the complexity of the processing on the client side:

* service URL schema version (so we can change it in the future)
* app name
* app version
* app buildid (for distinguishing between nightlies on a "tester" build stream for example)
* app buildtarget
* app locale
* aus channel
* distribution name
* distribution version

e.g.,

/update/3/Firefox/3.0a8pre/2007083015/Darwin_x86-gcc3/en-US/default/Darwin%208.10.1/testpartner/1.0/update.xml

See app.update.url below for the template used in creating the Service URL.

//执行过程中的方法:
//支持断点续传,考虑安全方面可以不理会
When an update is stopped or the application is closed, the Software Update Manager stops pending downloads and notes progress so that when the application is started the next time, the download can be restarted at the point it left off.

//将版本信息(update.xml)保存下来,以免我们多次连接服务器
Attributes like hashvalue etc are cached here from the update.xml file so that on subsequent application starts we do not need to reconnect to the Update server to determine these values when the download is complete.

//没有看明白,应该还是断点续传
The Software Update Manager looks for the Active Download, then skips to the set of patches whose currbytes attribute is less than their maxbytes attribute, and resumes downloading.

//没有明白意思,英语太差
Service Recording Implementation  [edit]

A preference can be used to record whether or not we were performing updates during the last application run, and if this value is true, then we can load the update download history file from an XML file in the application directory (rather than the profile - the reason for this should be obvious). The metadata file lives in:

bin/update/updates.xml

This file is the same format as the one used for the remote XML update files except has additional fields for things such as install date etc. It is read into a DOM document which is used to build an in-memory cache of update objects.

A thin nsIRDFDataSource API is layered on top of said cache to provide a way for a front end to show the list of in progress (downloading) and previously installed updates.

//如果用户停止更新,至少会提示一次更新未完成(检测时间间隔)
Reminders  [edit]

If the user stops the update manually, the application should remind the user at least once every (update check interval) that the update is not yet complete and should be resumed.

//应该是firefox的几种类型版本
Software Update:Channels
From MozillaWiki

    * Release Channel (default)
    * Beta Channel
    * Nightly Channel

Which channel you are in is determined by the app.update.channel pref, which can currently be set to ‘release’, ‘beta’ and ‘nightly’. This setting is passed along in the software update URL.

A "Channel Manager" extension that offers a UI for managing the channel setting, and preferences such as update frequency etc can be offered to people wishing to join the Beta/Alpha/Nightly channels.

Software update URL: https://aus2.mozilla.org/update/3/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/%OS_VERSION%/%DISTRIBUTION%/%DISTRIBUTION_VERSION%/update.xml

See Software_Update:Checking_For_Updates and Software_Update:Nightly_update_infrastructure for more information on the update URL.

/升级服务用到的几个组件(组成部分)
Software Update:Service Components
From MozillaWiki

    * Application Update Service (nsIApplicationUpdateService)

    User interface interacts primarily through this management service.

    * Update Object

    An object which represents a patch file, as represented by the server.

    * Checker

    Contacts the update server and determines if there are available updates. If there are, returns one or more Update Objects representing the sequence of actions needed to update the application

    * Downloader

    Given one or more Update Objects, initiates or resumes download of each patch file. Synchronizes state with Update Manager

    * Manager

    Manages metadata about current and previous updates. Provides an interface for adding and removing items, and updating item properties.

    * Verifier

    Verifies the integrity of the downloaded Update Object using the supplied hashvalue/function

    * Installer

    Extracts the downloaded items into the appropriate directories for discovery at the next startup.

    * Wizard/Manager UI

    Shows progress notifications, requests decisions/input from user. Completion Notifier.

    * Browser UI

    Menu item to invoke/view actions, status icon on toolbar to show processing update.

//下载完升级包后执行的过程,firefox启动后进行windows组件注册
Overview  [edit]

At startup or shutdown, a routine called from XRE_main may perform the following steps to process pending updates:

    * Check for the existance of an "updates" folder in the main application folder.
    * Enumerate its subfolders and build a list sorted by folder name.
    * Select the first folder in the list that is marked as pending.
    * Mark the selected folder as applying.
    * Copy the updater application into the folder for the update being applied.
    * Spawn the copy of the updater application to apply the selected update.
    * At this point, XRE_main exits. (NOTE: spawning the updater application may in fact mean that we call execv to load the updater image into the current process, but that is just an implementation detail.)
    * The updater takes over, applies the update (recording information to a log file for debugging purposes -- named update.log), and marks the update as either succeeded or failed.
    * The updater then (optionally) re-launches Firefox with a specified command line to resume execution.
    * Firefox then performs any post-install work, including for example fixing up any Windows registry keys.

//更新状态
Update Status  [edit]

As described above, each update will have a status associated with it. The states consist of the following:

pending</dt>
    The update is ready to be applied</dd>
applying</dt>
    The update is being applied</dd>
succeeded</dt>
    The update was successfully applied</dd>
failed</dt>
    The update could not be applied</dd>

This information is recorded in a text file named update.status stored in each update folder.

//MAR文件  源码路径  mozilla/modules/libmar
//用的是bzip2压缩文件
Mozilla ARchive  [edit]

This document describes the Mozilla ARchive (MAR) format used by the update system to deliver update packages. It is basically a series of files with an index tacked on to the end.

//升级中时间设置
INTEGER - app.update.timer                Default: 5000//不太明白
   the number of milliseconds between checker update interval expiry checks
   NOTE: this is NOT the time between service URL pings!
INTEGER - app.update.interval             Default: 86400
   the number of seconds between service XML pings. expiry of this interval
   is checked with a separate timer determined by |app.update.timer|
INTEGER - app.update.nagTimer.download    Default: 86400
   the number of seconds after a user chooses the "Later" button in the
   update available nag UI to wait before annoying them with news of the
   update again.
INTEGER - app.update.nagTimer.restart     Default: 1800
   the number of seconds after the user chooses to Restart the browser
   Later after an update has been downloaded to annoy them with a prompt
   to restart.

//升级过程中方法  向用户提供错误详细信息
Functionality [edit]

When the Firefox starts, it detects the update condition that you created by editing the files as described above. It collects a list of addons that are incompatible with the new running instance, and then:

    * checks for VersionInfo updates to each of the items in the list... a VersionInfo update is a remove compatibility update provided by the author of the addon through AMO or their custom update.rdf file that says that the existing installed version of the addon is in fact compatible with the new version of Firefox, and requires no new XPI download/install

    * after the VersionInfo check reduces the incompatibility list somewhat, displays a list of addons that are still incompatible and will need to be updated to still be functional.

    * checks for newer versions of the said addons.

    * when it discovers the updates that are available, shows them to the user and gives them the ability to download and install them now.

    * downloads and installs the selected updates

    * shows information to the user about any errors encountered in this process, also, shows information about items that are still incompatible (no updates found), and gives the user the ability to opt into auto update checking if the user has previously disabled extension auto update checking.

//update.xml 文件内容的意思

//简单事例
<?xml version="1.0"?>

<updates>
  <update type="minor" version="1.0.4" extensionVersion="1.0"
          detailsURL="http://www.foo.com/1.0.4/whatsnew.html">
    <patch type="partial" URL="http://www.foo.com/1.0.4-partial.mar"
           hashFunction="" hashValue="" size=""/>
    <patch type="complete" URL="http://www.foo.com/1.0.4-complete.mar"
           hashFunction="" hashValue="" size=""/>
  </update>
  ..
  <update type="major" version="1.1.2" extensionVersion="1.1"
          detailsURL="http://www.foo.com/1.1.2/whatsnew.html">
    <patch type="complete" URL="http://www.foo.com/1.1.2-complete.mar"
           hashFunction="" hashValue="" size=""/>
  </update>
</updates>

type    major or minor. Major updates are for major application number revs, minor for security releases or incremental updates. (Note: client side support for major updates is new to the MOZILLA_1_8_BRANCH.)
version    A string in FVF format advertising the version of this application update.
extensionVersion    A string in FVF format advertising the version of the extension API that this application update supplies
detailsURL    A URL string to a web page with more information about the specified update. For minor releases, this URL appears as a link (with text like "View more information about this update") in the UI shown to the user when they are presented with the option to upgrade. New for MOZILLA_1_8_BRANCH: For major releases, this URL is loaded "in line" in the UI shown to the user when they are presented with the option to upgrade. See Software_Update:HowToTestMajorUpdateUI for how to test this.
licenseURL    New for MOZILLA_1_8_BRANCH: A URL string to a web page with additional license terms that need to be accepted before the update can be installed (optional, do NOT provide it if this is going to be empty). Note: this attribute is only heeded for major releases. For minor releases, this attribute is ignored by the client. For major releases, this URL is loaded "in line" in the UI shown to the user when they are presented with the option to upgrade. See Software_Update:HowToTestMajorUpdateUI for how to test this.
isSecurityUpdate    true for security updates, to present a scarier warning to users, false if the update is not a security update. Note: The client is not and has not heeded this boolean value, and AUS has never set it. See bug #329729 for details.
buildID    The BuildID of the build being offered

/************************************************************************/

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值