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