| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 23 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/component_updater/component_unpacker.h" | 25 #include "chrome/browser/component_updater/component_unpacker.h" |
| 26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" | 26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
| 27 #include "chrome/browser/component_updater/component_updater_utils.h" | 27 #include "chrome/browser/component_updater/component_updater_utils.h" |
| 28 #include "chrome/browser/component_updater/crx_downloader.h" | 28 #include "chrome/browser/component_updater/crx_downloader.h" |
| 29 #include "chrome/browser/component_updater/crx_update_item.h" | 29 #include "chrome/browser/component_updater/crx_update_item.h" |
| 30 #include "chrome/browser/component_updater/update_checker.h" | 30 #include "chrome/browser/component_updater/update_checker.h" |
| 31 #include "chrome/browser/component_updater/update_response.h" | 31 #include "chrome/browser/component_updater/update_response.h" |
| 32 #include "chrome/common/chrome_version_info.h" | |
| 33 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/resource_controller.h" | 33 #include "content/public/browser/resource_controller.h" |
| 35 #include "content/public/browser/resource_throttle.h" | 34 #include "content/public/browser/resource_throttle.h" |
| 36 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 37 | 36 |
| 38 using content::BrowserThread; | 37 using content::BrowserThread; |
| 39 | 38 |
| 40 namespace component_updater { | 39 namespace component_updater { |
| 41 | 40 |
| 42 // The component updater is designed to live until process shutdown, so | 41 // The component updater is designed to live until process shutdown, so |
| 43 // base::Bind() calls are not refcounted. | 42 // base::Bind() calls are not refcounted. |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 // Returns true if the |proposed| version is newer than |current| version. | 46 // Returns true if the |proposed| version is newer than |current| version. |
| 48 bool IsVersionNewer(const Version& current, const std::string& proposed) { | 47 bool IsVersionNewer(const base::Version& current, const std::string& proposed) { |
| 49 Version proposed_ver(proposed); | 48 base::Version proposed_ver(proposed); |
| 50 return proposed_ver.IsValid() && current.CompareTo(proposed_ver) < 0; | 49 return proposed_ver.IsValid() && current.CompareTo(proposed_ver) < 0; |
| 51 } | 50 } |
| 52 | 51 |
| 53 // Returns true if a differential update is available, it has not failed yet, | 52 // Returns true if a differential update is available, it has not failed yet, |
| 54 // and the configuration allows it. | 53 // and the configuration allows it. |
| 55 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, | 54 bool CanTryDiffUpdate(const CrxUpdateItem* update_item, |
| 56 const ComponentUpdateService::Configurator& config) { | 55 const ComponentUpdateService::Configurator& config) { |
| 57 return HasDiffUpdate(update_item) && !update_item->diff_update_failed && | 56 return HasDiffUpdate(update_item) && !update_item->diff_update_failed && |
| 58 config.DeltasEnabled(); | 57 config.DeltasEnabled(); |
| 59 } | 58 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // rest of the browser, so even if we have many components registered and | 137 // rest of the browser, so even if we have many components registered and |
| 139 // eligible for update, we only do one thing at a time with pauses in between | 138 // eligible for update, we only do one thing at a time with pauses in between |
| 140 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 139 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
| 141 // in flight at a time. | 140 // in flight at a time. |
| 142 // There are no locks in this code, the main structure |work_items_| is mutated | 141 // There are no locks in this code, the main structure |work_items_| is mutated |
| 143 // only from the UI thread. The unpack and installation is done in a blocking | 142 // only from the UI thread. The unpack and installation is done in a blocking |
| 144 // pool thread. The network requests are done in the IO thread or in the file | 143 // pool thread. The network requests are done in the IO thread or in the file |
| 145 // thread. | 144 // thread. |
| 146 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { | 145 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { |
| 147 public: | 146 public: |
| 148 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 147 explicit CrxUpdateService(ComponentUpdateService::Configurator* config, |
| 148 const std::string& chrome_version, |
| 149 const std::string& platform_name); |
| 149 virtual ~CrxUpdateService(); | 150 virtual ~CrxUpdateService(); |
| 150 | 151 |
| 151 // Overrides for ComponentUpdateService. | 152 // Overrides for ComponentUpdateService. |
| 152 virtual void AddObserver(Observer* observer) OVERRIDE; | 153 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 153 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 154 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 154 virtual Status Start() OVERRIDE; | 155 virtual Status Start() OVERRIDE; |
| 155 virtual Status Stop() OVERRIDE; | 156 virtual Status Stop() OVERRIDE; |
| 156 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 157 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
| 157 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; | 158 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; |
| 158 virtual CrxUpdateItem* GetComponentDetails( | 159 virtual CrxUpdateItem* GetComponentDetails( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 scoped_ptr<CrxDownloader> crx_downloader_; | 257 scoped_ptr<CrxDownloader> crx_downloader_; |
| 257 | 258 |
| 258 // A collection of every work item. | 259 // A collection of every work item. |
| 259 typedef std::vector<CrxUpdateItem*> UpdateItems; | 260 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| 260 UpdateItems work_items_; | 261 UpdateItems work_items_; |
| 261 | 262 |
| 262 base::OneShotTimer<CrxUpdateService> timer_; | 263 base::OneShotTimer<CrxUpdateService> timer_; |
| 263 | 264 |
| 264 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 265 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 265 | 266 |
| 266 const Version chrome_version_; | 267 const base::Version chrome_version_; |
| 268 const std::string platform_name_; |
| 267 | 269 |
| 268 bool running_; | 270 bool running_; |
| 269 | 271 |
| 270 ObserverList<Observer> observer_list_; | 272 ObserverList<Observer> observer_list_; |
| 271 | 273 |
| 272 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); | 274 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); |
| 273 }; | 275 }; |
| 274 | 276 |
| 275 ////////////////////////////////////////////////////////////////////////////// | 277 ////////////////////////////////////////////////////////////////////////////// |
| 276 | 278 |
| 277 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config) | 279 CrxUpdateService::CrxUpdateService(ComponentUpdateService::Configurator* config, |
| 280 const std::string& chrome_version, |
| 281 const std::string& platform_name) |
| 278 : config_(config), | 282 : config_(config), |
| 279 ping_manager_( | 283 ping_manager_( |
| 280 new PingManager(config->PingUrl(), config->RequestContext())), | 284 new PingManager(chrome_version, platform_name, config->PingUrl(), |
| 285 config->RequestContext())), |
| 281 blocking_task_runner_( | 286 blocking_task_runner_( |
| 282 BrowserThread::GetBlockingPool()-> | 287 BrowserThread::GetBlockingPool()-> |
| 283 GetSequencedTaskRunnerWithShutdownBehavior( | 288 GetSequencedTaskRunnerWithShutdownBehavior( |
| 284 BrowserThread::GetBlockingPool()->GetSequenceToken(), | 289 BrowserThread::GetBlockingPool()->GetSequenceToken(), |
| 285 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 290 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 286 chrome_version_(chrome::VersionInfo().Version()), | 291 chrome_version_(chrome_version), |
| 292 platform_name_(platform_name), |
| 287 running_(false) { | 293 running_(false) { |
| 288 } | 294 } |
| 289 | 295 |
| 290 CrxUpdateService::~CrxUpdateService() { | 296 CrxUpdateService::~CrxUpdateService() { |
| 291 // Because we are a singleton, at this point only the UI thread should be | 297 // Because we are a singleton, at this point only the UI thread should be |
| 292 // alive, this simplifies the management of the work that could be in | 298 // alive, this simplifies the management of the work that could be in |
| 293 // flight in other threads. | 299 // flight in other threads. |
| 294 Stop(); | 300 Stop(); |
| 295 STLDeleteElements(&work_items_); | 301 STLDeleteElements(&work_items_); |
| 296 } | 302 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 VLOG(1) << "Scheduling update check for component id=" << item->id | 606 VLOG(1) << "Scheduling update check for component id=" << item->id |
| 601 << ", time_since_last_checked=" | 607 << ", time_since_last_checked=" |
| 602 << time_since_last_checked.InSeconds() << " seconds"; | 608 << time_since_last_checked.InSeconds() << " seconds"; |
| 603 | 609 |
| 604 ChangeItemState(item, CrxUpdateItem::kChecking); | 610 ChangeItemState(item, CrxUpdateItem::kChecking); |
| 605 | 611 |
| 606 item->last_check = now; | 612 item->last_check = now; |
| 607 item->crx_urls.clear(); | 613 item->crx_urls.clear(); |
| 608 item->crx_diffurls.clear(); | 614 item->crx_diffurls.clear(); |
| 609 item->previous_version = item->component.version; | 615 item->previous_version = item->component.version; |
| 610 item->next_version = Version(); | 616 item->next_version = base::Version(); |
| 611 item->previous_fp = item->component.fingerprint; | 617 item->previous_fp = item->component.fingerprint; |
| 612 item->next_fp.clear(); | 618 item->next_fp.clear(); |
| 613 item->diff_update_failed = false; | 619 item->diff_update_failed = false; |
| 614 item->error_category = 0; | 620 item->error_category = 0; |
| 615 item->error_code = 0; | 621 item->error_code = 0; |
| 616 item->extra_code1 = 0; | 622 item->extra_code1 = 0; |
| 617 item->diff_error_category = 0; | 623 item->diff_error_category = 0; |
| 618 item->diff_error_code = 0; | 624 item->diff_error_code = 0; |
| 619 item->diff_extra_code1 = 0; | 625 item->diff_extra_code1 = 0; |
| 620 item->download_metrics.clear(); | 626 item->download_metrics.clear(); |
| 621 | 627 |
| 622 items_to_check.push_back(item); | 628 items_to_check.push_back(item); |
| 623 } | 629 } |
| 624 | 630 |
| 625 if (items_to_check.empty()) | 631 if (items_to_check.empty()) |
| 626 return false; | 632 return false; |
| 627 | 633 |
| 628 update_checker_ = | 634 update_checker_ = |
| 629 UpdateChecker::Create(config_->UpdateUrl(), | 635 UpdateChecker::Create(config_->UpdateUrl(), |
| 630 config_->RequestContext(), | 636 config_->RequestContext(), |
| 631 base::Bind(&CrxUpdateService::UpdateCheckComplete, | 637 base::Bind(&CrxUpdateService::UpdateCheckComplete, |
| 632 base::Unretained(this))).Pass(); | 638 base::Unretained(this))).Pass(); |
| 633 return update_checker_->CheckForUpdates(items_to_check, | 639 return update_checker_->CheckForUpdates(chrome_version_.GetString(), |
| 640 platform_name_, items_to_check, |
| 634 config_->ExtraRequestParams()); | 641 config_->ExtraRequestParams()); |
| 635 } | 642 } |
| 636 | 643 |
| 637 void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) { | 644 void CrxUpdateService::UpdateComponent(CrxUpdateItem* workitem) { |
| 638 scoped_ptr<CRXContext> crx_context(new CRXContext); | 645 scoped_ptr<CRXContext> crx_context(new CRXContext); |
| 639 crx_context->pk_hash = workitem->component.pk_hash; | 646 crx_context->pk_hash = workitem->component.pk_hash; |
| 640 crx_context->id = workitem->id; | 647 crx_context->id = workitem->id; |
| 641 crx_context->installer = workitem->component.installer; | 648 crx_context->installer = workitem->component.installer; |
| 642 crx_context->fingerprint = workitem->next_fp; | 649 crx_context->fingerprint = workitem->next_fp; |
| 643 const std::vector<GURL>* urls = NULL; | 650 const std::vector<GURL>* urls = NULL; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 } | 735 } |
| 729 | 736 |
| 730 if (it->manifest.packages.size() != 1) { | 737 if (it->manifest.packages.size() != 1) { |
| 731 // Assume one and only one package per component. | 738 // Assume one and only one package per component. |
| 732 VLOG(1) << "Ignoring multiple packages for component: " << crx->id; | 739 VLOG(1) << "Ignoring multiple packages for component: " << crx->id; |
| 733 ChangeItemState(crx, CrxUpdateItem::kNoUpdate); | 740 ChangeItemState(crx, CrxUpdateItem::kNoUpdate); |
| 734 continue; | 741 continue; |
| 735 } | 742 } |
| 736 | 743 |
| 737 // Parse the members of the result and queue an upgrade for this component. | 744 // Parse the members of the result and queue an upgrade for this component. |
| 738 crx->next_version = Version(it->manifest.version); | 745 crx->next_version = base::Version(it->manifest.version); |
| 739 | 746 |
| 740 VLOG(1) << "Update found for component: " << crx->id; | 747 VLOG(1) << "Update found for component: " << crx->id; |
| 741 | 748 |
| 742 typedef UpdateResponse::Result::Manifest::Package Package; | 749 typedef UpdateResponse::Result::Manifest::Package Package; |
| 743 const Package& package(it->manifest.packages[0]); | 750 const Package& package(it->manifest.packages[0]); |
| 744 crx->next_fp = package.fingerprint; | 751 crx->next_fp = package.fingerprint; |
| 745 | 752 |
| 746 // Resolve the urls by combining the base urls with the package names. | 753 // Resolve the urls by combining the base urls with the package names. |
| 747 for (size_t i = 0; i != it->crx_urls.size(); ++i) { | 754 for (size_t i = 0; i != it->crx_urls.size(); ++i) { |
| 748 const GURL url(it->crx_urls[i].Resolve(package.name)); | 755 const GURL url(it->crx_urls[i].Resolve(package.name)); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 void CUResourceThrottle::Unblock() { | 1087 void CUResourceThrottle::Unblock() { |
| 1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1088 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1082 if (state_ == BLOCKED) | 1089 if (state_ == BLOCKED) |
| 1083 controller()->Resume(); | 1090 controller()->Resume(); |
| 1084 state_ = UNBLOCKED; | 1091 state_ = UNBLOCKED; |
| 1085 } | 1092 } |
| 1086 | 1093 |
| 1087 // The component update factory. Using the component updater as a singleton | 1094 // The component update factory. Using the component updater as a singleton |
| 1088 // is the job of the browser process. | 1095 // is the job of the browser process. |
| 1089 ComponentUpdateService* ComponentUpdateServiceFactory( | 1096 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 1090 ComponentUpdateService::Configurator* config) { | 1097 ComponentUpdateService::Configurator* config, |
| 1098 const std::string& chrome_version, |
| 1099 const std::string& platform_name) { |
| 1091 DCHECK(config); | 1100 DCHECK(config); |
| 1092 return new CrxUpdateService(config); | 1101 return new CrxUpdateService(config, chrome_version, platform_name); |
| 1093 } | 1102 } |
| 1094 | 1103 |
| 1095 } // namespace component_updater | 1104 } // namespace component_updater |
| OLD | NEW |