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