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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 163 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); |
| 164 virtual ~CrxUpdateService(); | 164 virtual ~CrxUpdateService(); |
| 165 | 165 |
| 166 // Overrides for ComponentUpdateService. | 166 // Overrides for ComponentUpdateService. |
| 167 virtual Status Start() OVERRIDE; | 167 virtual Status Start() OVERRIDE; |
| 168 virtual Status Stop() OVERRIDE; | 168 virtual Status Stop() OVERRIDE; |
| 169 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 169 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
| 170 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; | 170 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; |
| 171 virtual void GetComponents( | 171 virtual void GetComponents( |
| 172 std::vector<CrxComponentInfo>* components) OVERRIDE; | 172 std::vector<CrxComponentInfo>* components) OVERRIDE; |
| 173 virtual ComponentUpdateService::Status GetComponentStatus( | |
| 174 const std::string& component_id) OVERRIDE; | |
| 175 | |
| 173 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( | 176 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( |
| 174 net::URLRequest* request, const std::string& crx_id) OVERRIDE; | 177 net::URLRequest* request, const std::string& crx_id) OVERRIDE; |
| 175 | 178 |
| 176 // Context for a crx download url request. | 179 // Context for a crx download url request. |
| 177 struct CRXContext { | 180 struct CRXContext { |
| 178 ComponentInstaller* installer; | 181 ComponentInstaller* installer; |
| 179 std::vector<uint8> pk_hash; | 182 std::vector<uint8> pk_hash; |
| 180 std::string id; | 183 std::string id; |
| 181 std::string fingerprint; | 184 std::string fingerprint; |
| 182 CRXContext() : installer(NULL) {} | 185 CRXContext() : installer(NULL) {} |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 246 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 244 | 247 |
| 245 void NotifyComponentObservers(ComponentObserver::Events event, | 248 void NotifyComponentObservers(ComponentObserver::Events event, |
| 246 int extra) const; | 249 int extra) const; |
| 247 | 250 |
| 248 bool HasOnDemandItems() const; | 251 bool HasOnDemandItems() const; |
| 249 | 252 |
| 250 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | 253 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
| 251 const std::string& crx_id); | 254 const std::string& crx_id); |
| 252 | 255 |
| 256 ComponentUpdateService::Status GetConciseStatus( | |
| 257 const CrxUpdateItem::Status status); | |
| 258 | |
| 253 scoped_ptr<ComponentUpdateService::Configurator> config_; | 259 scoped_ptr<ComponentUpdateService::Configurator> config_; |
| 254 | 260 |
| 255 scoped_ptr<ComponentPatcher> component_patcher_; | 261 scoped_ptr<ComponentPatcher> component_patcher_; |
| 256 | 262 |
| 257 scoped_ptr<UpdateChecker> update_checker_; | 263 scoped_ptr<UpdateChecker> update_checker_; |
| 258 | 264 |
| 259 scoped_ptr<PingManager> ping_manager_; | 265 scoped_ptr<PingManager> ping_manager_; |
| 260 | 266 |
| 261 scoped_ptr<ComponentUnpacker> unpacker_; | 267 scoped_ptr<ComponentUnpacker> unpacker_; |
| 262 | 268 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( | 508 ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( |
| 503 CrxUpdateItem* uit) { | 509 CrxUpdateItem* uit) { |
| 504 if (!uit) | 510 if (!uit) |
| 505 return kError; | 511 return kError; |
| 506 | 512 |
| 507 // Check if the request is too soon. | 513 // Check if the request is too soon. |
| 508 base::TimeDelta delta = base::Time::Now() - uit->last_check; | 514 base::TimeDelta delta = base::Time::Now() - uit->last_check; |
| 509 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) | 515 if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| 510 return kError; | 516 return kError; |
| 511 | 517 |
| 512 switch (uit->status) { | 518 Status service_status = GetConciseStatus(uit->status); |
|
Sorin Jianu
2014/03/26 20:22:36
Consider renaming GetConciseStatus to GetServiceSt
Shrikant Kelkar
2014/03/26 21:35:51
Done.
| |
| 513 // If the item is already in the process of being updated, there is | 519 // If the item is already in the process of being updated, there is |
| 514 // no point in this call, so return kInProgress. | 520 // no point in this call, so return kInProgress. |
| 515 case CrxUpdateItem::kChecking: | 521 if (service_status == kInProgress) |
| 516 case CrxUpdateItem::kCanUpdate: | 522 return service_status; |
| 517 case CrxUpdateItem::kDownloadingDiff: | 523 |
| 518 case CrxUpdateItem::kDownloading: | 524 // Otherwise the item was already checked a while back (or it is new), |
| 519 case CrxUpdateItem::kUpdatingDiff: | 525 // set its status to kNew to give it a slightly higher priority. |
| 520 case CrxUpdateItem::kUpdating: | 526 ChangeItemState(uit, CrxUpdateItem::kNew); |
|
Sorin Jianu
2014/03/26 20:22:36
are we still setting uit->on_demand = true anywher
Shrikant Kelkar
2014/03/26 21:35:51
good catch, copy~paste error. Thanks.
| |
| 521 return kInProgress; | |
| 522 // Otherwise the item was already checked a while back (or it is new), | |
| 523 // set its status to kNew to give it a slightly higher priority. | |
| 524 case CrxUpdateItem::kNew: | |
| 525 case CrxUpdateItem::kUpdated: | |
| 526 case CrxUpdateItem::kUpToDate: | |
| 527 case CrxUpdateItem::kNoUpdate: | |
| 528 ChangeItemState(uit, CrxUpdateItem::kNew); | |
| 529 uit->on_demand = true; | |
| 530 break; | |
| 531 case CrxUpdateItem::kLastStatus: | |
| 532 NOTREACHED() << uit->status; | |
| 533 } | |
| 534 | 527 |
| 535 // In case the current delay is long, set the timer to a shorter value | 528 // In case the current delay is long, set the timer to a shorter value |
| 536 // to get the ball rolling. | 529 // to get the ball rolling. |
| 537 if (timer_.IsRunning()) { | 530 if (timer_.IsRunning()) { |
| 538 timer_.Stop(); | 531 timer_.Stop(); |
| 539 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->StepDelay()), | 532 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->StepDelay()), |
| 540 this, &CrxUpdateService::ProcessPendingItems); | 533 this, &CrxUpdateService::ProcessPendingItems); |
| 541 } | 534 } |
| 542 | 535 |
| 543 return kOk; | 536 return kOk; |
| 544 } | 537 } |
| 545 | 538 |
| 546 void CrxUpdateService::GetComponents( | 539 void CrxUpdateService::GetComponents( |
| 547 std::vector<CrxComponentInfo>* components) { | 540 std::vector<CrxComponentInfo>* components) { |
| 548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 549 for (UpdateItems::const_iterator it = work_items_.begin(); | 542 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 550 it != work_items_.end(); ++it) { | 543 it != work_items_.end(); ++it) { |
| 551 const CrxUpdateItem* item = *it; | 544 const CrxUpdateItem* item = *it; |
| 552 CrxComponentInfo info; | 545 CrxComponentInfo info; |
| 553 info.id = GetCrxComponentID(item->component); | 546 info.id = GetCrxComponentID(item->component); |
| 554 info.version = item->component.version.GetString(); | 547 info.version = item->component.version.GetString(); |
| 555 info.name = item->component.name; | 548 info.name = item->component.name; |
| 549 info.status = GetConciseStatus(item->status); | |
| 556 components->push_back(info); | 550 components->push_back(info); |
| 557 } | 551 } |
| 558 } | 552 } |
| 559 | 553 |
| 554 ComponentUpdateService::Status CrxUpdateService::GetComponentStatus( | |
| 555 const std::string& component_id) { | |
| 556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 557 | |
| 558 CrxUpdateItem* crx = FindUpdateItemById(component_id); | |
| 559 DCHECK(crx != NULL); | |
|
Sorin Jianu
2014/03/26 20:22:36
no need to dcheck and handle the error, see the DC
Shrikant Kelkar
2014/03/26 21:35:51
Done.
| |
| 560 if (crx == NULL) | |
| 561 return kError; | |
| 562 | |
| 563 Status service_status = GetConciseStatus(crx->status); | |
| 564 return service_status; | |
|
Sorin Jianu
2014/03/26 20:22:36
return GetConciseStatus(crx->status);
Shrikant Kelkar
2014/03/26 21:35:51
Done.
| |
| 565 } | |
| 566 | |
| 567 | |
| 560 // This is the main loop of the component updater. It updates one component | 568 // This is the main loop of the component updater. It updates one component |
| 561 // at a time if updates are available. Otherwise, it does an update check or | 569 // at a time if updates are available. Otherwise, it does an update check or |
| 562 // takes a long sleep until the loop runs again. | 570 // takes a long sleep until the loop runs again. |
| 563 void CrxUpdateService::ProcessPendingItems() { | 571 void CrxUpdateService::ProcessPendingItems() { |
| 564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 565 | 573 |
| 566 CrxUpdateItem* ready_upgrade = FindReadyComponent(); | 574 CrxUpdateItem* ready_upgrade = FindReadyComponent(); |
| 567 if (ready_upgrade) { | 575 if (ready_upgrade) { |
| 568 UpdateComponent(ready_upgrade); | 576 UpdateComponent(ready_upgrade); |
| 569 return; | 577 return; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 // Check if we can on-demand update, else unblock the request anyway. | 974 // Check if we can on-demand update, else unblock the request anyway. |
| 967 CrxUpdateItem* item = FindUpdateItemById(crx_id); | 975 CrxUpdateItem* item = FindUpdateItemById(crx_id); |
| 968 Status status = OnDemandUpdateInternal(item); | 976 Status status = OnDemandUpdateInternal(item); |
| 969 if (status == kOk || status == kInProgress) { | 977 if (status == kOk || status == kInProgress) { |
| 970 item->throttles.push_back(rt); | 978 item->throttles.push_back(rt); |
| 971 return; | 979 return; |
| 972 } | 980 } |
| 973 UnblockResourceThrottle(rt); | 981 UnblockResourceThrottle(rt); |
| 974 } | 982 } |
| 975 | 983 |
| 984 ComponentUpdateService::Status CrxUpdateService::GetConciseStatus( | |
|
Sorin Jianu
2014/03/26 20:22:36
If we don't fully qualify then the param might fit
Shrikant Kelkar
2014/03/26 21:35:51
Not qualifying gives compile error + we seem to be
| |
| 985 CrxUpdateItem::Status status) { | |
| 986 switch (status) { | |
| 987 // If the item is already in the process of being updated, there is | |
| 988 // no point in this call, so return kInProgress. | |
| 989 case CrxUpdateItem::kChecking: | |
| 990 case CrxUpdateItem::kCanUpdate: | |
| 991 case CrxUpdateItem::kDownloadingDiff: | |
| 992 case CrxUpdateItem::kDownloading: | |
| 993 case CrxUpdateItem::kUpdatingDiff: | |
| 994 case CrxUpdateItem::kUpdating: | |
| 995 return kInProgress; | |
| 996 // Otherwise the item was already checked a while back (or it is new), | |
| 997 // set its status to kNew to give it a slightly higher priority. | |
| 998 case CrxUpdateItem::kNew: | |
| 999 case CrxUpdateItem::kUpdated: | |
| 1000 case CrxUpdateItem::kUpToDate: | |
| 1001 case CrxUpdateItem::kNoUpdate: | |
| 1002 return kOk; | |
| 1003 break; | |
| 1004 case CrxUpdateItem::kLastStatus: | |
| 1005 NOTREACHED() << status; | |
| 1006 } | |
| 1007 return kError; | |
| 1008 } | |
| 1009 | |
| 976 /////////////////////////////////////////////////////////////////////////////// | 1010 /////////////////////////////////////////////////////////////////////////////// |
| 977 | 1011 |
| 978 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) | 1012 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) |
| 979 : state_(NEW) { | 1013 : state_(NEW) { |
| 980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 981 } | 1015 } |
| 982 | 1016 |
| 983 CUResourceThrottle::~CUResourceThrottle() { | 1017 CUResourceThrottle::~CUResourceThrottle() { |
| 984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 985 } | 1019 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1011 // The component update factory. Using the component updater as a singleton | 1045 // The component update factory. Using the component updater as a singleton |
| 1012 // is the job of the browser process. | 1046 // is the job of the browser process. |
| 1013 ComponentUpdateService* ComponentUpdateServiceFactory( | 1047 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 1014 ComponentUpdateService::Configurator* config) { | 1048 ComponentUpdateService::Configurator* config) { |
| 1015 DCHECK(config); | 1049 DCHECK(config); |
| 1016 return new CrxUpdateService(config); | 1050 return new CrxUpdateService(config); |
| 1017 } | 1051 } |
| 1018 | 1052 |
| 1019 } // namespace component_updater | 1053 } // namespace component_updater |
| 1020 | 1054 |
| OLD | NEW |