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