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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 83 } |
| 84 | 84 |
| 85 CrxComponent::CrxComponent() | 85 CrxComponent::CrxComponent() |
| 86 : installer(NULL), | 86 : installer(NULL), |
| 87 allow_background_download(true) { | 87 allow_background_download(true) { |
| 88 } | 88 } |
| 89 | 89 |
| 90 CrxComponent::~CrxComponent() { | 90 CrxComponent::~CrxComponent() { |
| 91 } | 91 } |
| 92 | 92 |
| 93 CrxComponentInfo::CrxComponentInfo() { | |
| 94 } | |
| 95 | |
| 96 CrxComponentInfo::~CrxComponentInfo() { | |
| 97 } | |
| 98 | |
| 99 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
| 100 // In charge of blocking url requests until the |crx_id| component has been | 94 // In charge of blocking url requests until the |crx_id| component has been |
| 101 // updated. This class is touched solely from the IO thread. The UI thread | 95 // updated. This class is touched solely from the IO thread. The UI thread |
| 102 // can post tasks to it via weak pointers. By default the request is blocked | 96 // can post tasks to it via weak pointers. By default the request is blocked |
| 103 // unless the CrxUpdateService calls Unblock(). | 97 // unless the CrxUpdateService calls Unblock(). |
| 104 // The lifetime is controlled by Chrome's resource loader so the component | 98 // The lifetime is controlled by Chrome's resource loader so the component |
| 105 // updater cannot touch objects from this class except via weak pointers. | 99 // updater cannot touch objects from this class except via weak pointers. |
| 106 class CUResourceThrottle | 100 class CUResourceThrottle |
| 107 : public content::ResourceThrottle, | 101 : public content::ResourceThrottle, |
| 108 public base::SupportsWeakPtr<CUResourceThrottle> { | 102 public base::SupportsWeakPtr<CUResourceThrottle> { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 156 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); |
| 163 virtual ~CrxUpdateService(); | 157 virtual ~CrxUpdateService(); |
| 164 | 158 |
| 165 // Overrides for ComponentUpdateService. | 159 // Overrides for ComponentUpdateService. |
| 166 virtual void AddObserver(Observer* observer) OVERRIDE; | 160 virtual void AddObserver(Observer* observer) OVERRIDE; |
| 167 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 161 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
| 168 virtual Status Start() OVERRIDE; | 162 virtual Status Start() OVERRIDE; |
| 169 virtual Status Stop() OVERRIDE; | 163 virtual Status Stop() OVERRIDE; |
| 170 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 164 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
| 171 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; | 165 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; |
| 172 virtual void GetComponents( | 166 virtual void GetComponentIDs( |
| 173 std::vector<CrxComponentInfo>* components) OVERRIDE; | 167 std::vector<std::string>* component_ids) OVERRIDE; |
| 168 virtual void GetComponentDetails(const std::string& component_id, | |
| 169 CrxUpdateItem** item) OVERRIDE; | |
| 170 | |
| 174 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( | 171 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( |
| 175 net::URLRequest* request, const std::string& crx_id) OVERRIDE; | 172 net::URLRequest* request, const std::string& crx_id) OVERRIDE; |
| 176 | 173 |
| 177 // Context for a crx download url request. | 174 // Context for a crx download url request. |
| 178 struct CRXContext { | 175 struct CRXContext { |
| 179 ComponentInstaller* installer; | 176 ComponentInstaller* installer; |
| 180 std::vector<uint8> pk_hash; | 177 std::vector<uint8> pk_hash; |
| 181 std::string id; | 178 std::string id; |
| 182 std::string fingerprint; | 179 std::string fingerprint; |
| 183 CRXContext() : installer(NULL) {} | 180 CRXContext() : installer(NULL) {} |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 242 |
| 246 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 243 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 247 | 244 |
| 248 void NotifyObservers(Observer::Events event, const std::string& id); | 245 void NotifyObservers(Observer::Events event, const std::string& id); |
| 249 | 246 |
| 250 bool HasOnDemandItems() const; | 247 bool HasOnDemandItems() const; |
| 251 | 248 |
| 252 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | 249 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
| 253 const std::string& crx_id); | 250 const std::string& crx_id); |
| 254 | 251 |
| 252 Status GetServiceStatus(const CrxUpdateItem::Status status); | |
| 253 | |
| 255 scoped_ptr<ComponentUpdateService::Configurator> config_; | 254 scoped_ptr<ComponentUpdateService::Configurator> config_; |
| 256 | 255 |
| 257 scoped_ptr<UpdateChecker> update_checker_; | 256 scoped_ptr<UpdateChecker> update_checker_; |
| 258 | 257 |
| 259 scoped_ptr<PingManager> ping_manager_; | 258 scoped_ptr<PingManager> ping_manager_; |
| 260 | 259 |
| 261 scoped_refptr<ComponentUnpacker> unpacker_; | 260 scoped_refptr<ComponentUnpacker> unpacker_; |
| 262 | 261 |
| 263 scoped_ptr<CrxDownloader> crx_downloader_; | 262 scoped_ptr<CrxDownloader> crx_downloader_; |
| 264 | 263 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( | 514 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( |
| 516 CrxUpdateItem* uit) { | 515 CrxUpdateItem* uit) { |
| 517 if (!uit) | 516 if (!uit) |
| 518 return kError; | 517 return kError; |
| 519 | 518 |
| 520 // Check if the request is too soon. | 519 // Check if the request is too soon. |
| 521 base::TimeDelta delta = base::Time::Now() - uit->last_check; | 520 base::TimeDelta delta = base::Time::Now() - uit->last_check; |
| 522 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 521 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| 523 return kError; | 522 return kError; |
| 524 | 523 |
| 525 switch (uit->status) { | 524 Status service_status = GetServiceStatus(uit->status); |
| 526 // If the item is already in the process of being updated, there is | 525 // If the item is already in the process of being updated, there is |
| 527 // no point in this call, so return kInProgress. | 526 // no point in this call, so return kInProgress. |
| 528 case CrxUpdateItem::kChecking: | 527 if (service_status == kInProgress) |
| 529 case CrxUpdateItem::kCanUpdate: | 528 return service_status; |
| 530 case CrxUpdateItem::kDownloadingDiff: | 529 |
| 531 case CrxUpdateItem::kDownloading: | 530 // Otherwise the item was already checked a while back (or it is new), |
| 532 case CrxUpdateItem::kUpdatingDiff: | 531 // set its status to kNew to give it a slightly higher priority. |
| 533 case CrxUpdateItem::kUpdating: | 532 ChangeItemState(uit, CrxUpdateItem::kNew); |
| 534 return kInProgress; | 533 uit->on_demand = true; |
| 535 // Otherwise the item was already checked a while back (or it is new), | |
| 536 // set its status to kNew to give it a slightly higher priority. | |
| 537 case CrxUpdateItem::kNew: | |
| 538 case CrxUpdateItem::kUpdated: | |
| 539 case CrxUpdateItem::kUpToDate: | |
| 540 case CrxUpdateItem::kNoUpdate: | |
| 541 ChangeItemState(uit, CrxUpdateItem::kNew); | |
| 542 uit->on_demand = true; | |
| 543 break; | |
| 544 case CrxUpdateItem::kLastStatus: | |
| 545 NOTREACHED() << uit->status; | |
| 546 } | |
| 547 | 534 |
| 548 // In case the current delay is long, set the timer to a shorter value | 535 // In case the current delay is long, set the timer to a shorter value |
| 549 // to get the ball rolling. | 536 // to get the ball rolling. |
| 550 if (timer_.IsRunning()) { | 537 if (timer_.IsRunning()) { |
| 551 timer_.Stop(); | 538 timer_.Stop(); |
| 552 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->StepDelay()), | 539 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->StepDelay()), |
| 553 this, &CrxUpdateService::ProcessPendingItems); | 540 this, &CrxUpdateService::ProcessPendingItems); |
| 554 } | 541 } |
| 555 | 542 |
| 556 return kOk; | 543 return kOk; |
| 557 } | 544 } |
| 558 | 545 |
| 559 void CrxUpdateService::GetComponents( | 546 void CrxUpdateService::GetComponentIDs( |
| 560 std::vector<CrxComponentInfo>* components) { | 547 std::vector<std::string>* component_ids) { |
| 561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 562 for (UpdateItems::const_iterator it = work_items_.begin(); | 549 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 563 it != work_items_.end(); ++it) { | 550 it != work_items_.end(); ++it) { |
| 564 const CrxUpdateItem* item = *it; | 551 const CrxUpdateItem* item = *it; |
| 565 CrxComponentInfo info; | 552 component_ids->push_back(GetCrxComponentID(item->component)); |
|
Sorin Jianu
2014/05/03 01:09:06
there is already an CrxUpdateItem::id member, we c
Shrikant Kelkar
2014/05/05 23:05:18
Done.
| |
| 566 info.id = GetCrxComponentID(item->component); | |
| 567 info.version = item->component.version.GetString(); | |
| 568 info.name = item->component.name; | |
| 569 components->push_back(info); | |
| 570 } | 553 } |
| 571 } | 554 } |
| 572 | 555 |
| 556 void CrxUpdateService::GetComponentDetails( | |
| 557 const std::string& component_id, CrxUpdateItem** item) { | |
| 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 559 | |
| 560 CrxUpdateItem* crx = FindUpdateItemById(component_id); | |
| 561 *item = crx; | |
| 562 } | |
| 563 | |
| 564 | |
| 573 // This is the main loop of the component updater. It updates one component | 565 // This is the main loop of the component updater. It updates one component |
| 574 // at a time if updates are available. Otherwise, it does an update check or | 566 // at a time if updates are available. Otherwise, it does an update check or |
| 575 // takes a long sleep until the loop runs again. | 567 // takes a long sleep until the loop runs again. |
| 576 void CrxUpdateService::ProcessPendingItems() { | 568 void CrxUpdateService::ProcessPendingItems() { |
| 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 578 | 570 |
| 579 CrxUpdateItem* ready_upgrade = FindReadyComponent(); | 571 CrxUpdateItem* ready_upgrade = FindReadyComponent(); |
| 580 if (ready_upgrade) { | 572 if (ready_upgrade) { |
| 581 UpdateComponent(ready_upgrade); | 573 UpdateComponent(ready_upgrade); |
| 582 return; | 574 return; |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1006 // Check if we can on-demand update, else unblock the request anyway. | 998 // Check if we can on-demand update, else unblock the request anyway. |
| 1007 CrxUpdateItem* item = FindUpdateItemById(crx_id); | 999 CrxUpdateItem* item = FindUpdateItemById(crx_id); |
| 1008 Status status = OnDemandUpdateInternal(item); | 1000 Status status = OnDemandUpdateInternal(item); |
| 1009 if (status == kOk || status == kInProgress) { | 1001 if (status == kOk || status == kInProgress) { |
| 1010 item->throttles.push_back(rt); | 1002 item->throttles.push_back(rt); |
| 1011 return; | 1003 return; |
| 1012 } | 1004 } |
| 1013 UnblockResourceThrottle(rt); | 1005 UnblockResourceThrottle(rt); |
| 1014 } | 1006 } |
| 1015 | 1007 |
| 1008 ComponentUpdateService::Status CrxUpdateService::GetServiceStatus( | |
| 1009 CrxUpdateItem::Status status) { | |
| 1010 switch (status) { | |
| 1011 case CrxUpdateItem::kChecking: | |
| 1012 case CrxUpdateItem::kCanUpdate: | |
| 1013 case CrxUpdateItem::kDownloadingDiff: | |
| 1014 case CrxUpdateItem::kDownloading: | |
| 1015 case CrxUpdateItem::kUpdatingDiff: | |
| 1016 case CrxUpdateItem::kUpdating: | |
| 1017 return kInProgress; | |
| 1018 case CrxUpdateItem::kNew: | |
| 1019 case CrxUpdateItem::kUpdated: | |
| 1020 case CrxUpdateItem::kUpToDate: | |
| 1021 case CrxUpdateItem::kNoUpdate: | |
| 1022 return kOk; | |
| 1023 break; | |
| 1024 case CrxUpdateItem::kLastStatus: | |
| 1025 NOTREACHED() << status; | |
| 1026 } | |
| 1027 return kError; | |
| 1028 } | |
| 1029 | |
| 1016 /////////////////////////////////////////////////////////////////////////////// | 1030 /////////////////////////////////////////////////////////////////////////////// |
| 1017 | 1031 |
| 1018 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) | 1032 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) |
| 1019 : state_(NEW) { | 1033 : state_(NEW) { |
| 1020 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1021 } | 1035 } |
| 1022 | 1036 |
| 1023 CUResourceThrottle::~CUResourceThrottle() { | 1037 CUResourceThrottle::~CUResourceThrottle() { |
| 1024 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1038 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1025 } | 1039 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1050 | 1064 |
| 1051 // The component update factory. Using the component updater as a singleton | 1065 // The component update factory. Using the component updater as a singleton |
| 1052 // is the job of the browser process. | 1066 // is the job of the browser process. |
| 1053 ComponentUpdateService* ComponentUpdateServiceFactory( | 1067 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 1054 ComponentUpdateService::Configurator* config) { | 1068 ComponentUpdateService::Configurator* config) { |
| 1055 DCHECK(config); | 1069 DCHECK(config); |
| 1056 return new CrxUpdateService(config); | 1070 return new CrxUpdateService(config); |
| 1057 } | 1071 } |
| 1058 | 1072 |
| 1059 } // namespace component_updater | 1073 } // namespace component_updater |
| OLD | NEW |