Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(851)

Side by Side Diff: chrome/browser/component_updater/component_updater_service.cc

Issue 209313002: Modified components ui to address concern of all the time disabled check update button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified according to code review comments. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 std::vector<std::string> GetComponentIDs() const OVERRIDE;
173 std::vector<CrxComponentInfo>* components) OVERRIDE; 167 virtual CrxUpdateItem* GetComponentDetails(
168 const std::string& component_id) const OVERRIDE;
169
174 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( 170 virtual content::ResourceThrottle* GetOnDemandResourceThrottle(
175 net::URLRequest* request, const std::string& crx_id) OVERRIDE; 171 net::URLRequest* request, const std::string& crx_id) OVERRIDE;
176 172
177 // Context for a crx download url request. 173 // Context for a crx download url request.
178 struct CRXContext { 174 struct CRXContext {
179 ComponentInstaller* installer; 175 ComponentInstaller* installer;
180 std::vector<uint8> pk_hash; 176 std::vector<uint8> pk_hash;
181 std::string id; 177 std::string id;
182 std::string fingerprint; 178 std::string fingerprint;
183 CRXContext() : installer(NULL) {} 179 CRXContext() : installer(NULL) {}
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 232
237 void DoneInstalling(const std::string& component_id, 233 void DoneInstalling(const std::string& component_id,
238 ComponentUnpacker::Error error, 234 ComponentUnpacker::Error error,
239 int extended_error); 235 int extended_error);
240 236
241 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); 237 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to);
242 238
243 size_t ChangeItemStatus(CrxUpdateItem::Status from, 239 size_t ChangeItemStatus(CrxUpdateItem::Status from,
244 CrxUpdateItem::Status to); 240 CrxUpdateItem::Status to);
245 241
246 CrxUpdateItem* FindUpdateItemById(const std::string& id); 242 CrxUpdateItem* FindUpdateItemById(const std::string& id) const;
247 243
248 void NotifyObservers(Observer::Events event, const std::string& id); 244 void NotifyObservers(Observer::Events event, const std::string& id);
249 245
250 bool HasOnDemandItems() const; 246 bool HasOnDemandItems() const;
251 247
252 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, 248 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt,
253 const std::string& crx_id); 249 const std::string& crx_id);
254 250
251 Status GetServiceStatus(const CrxUpdateItem::Status status);
252
255 scoped_ptr<ComponentUpdateService::Configurator> config_; 253 scoped_ptr<ComponentUpdateService::Configurator> config_;
256 254
257 scoped_ptr<UpdateChecker> update_checker_; 255 scoped_ptr<UpdateChecker> update_checker_;
258 256
259 scoped_ptr<PingManager> ping_manager_; 257 scoped_ptr<PingManager> ping_manager_;
260 258
261 scoped_refptr<ComponentUnpacker> unpacker_; 259 scoped_refptr<ComponentUnpacker> unpacker_;
262 260
263 scoped_ptr<CrxDownloader> crx_downloader_; 261 scoped_ptr<CrxDownloader> crx_downloader_;
264 262
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (0 == delay_seconds) 392 if (0 == delay_seconds)
395 return; 393 return;
396 } 394 }
397 395
398 VLOG(1) << "Scheduling next run to occur in " << delay_seconds << " seconds"; 396 VLOG(1) << "Scheduling next run to occur in " << delay_seconds << " seconds";
399 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_seconds), 397 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_seconds),
400 this, &CrxUpdateService::ProcessPendingItems); 398 this, &CrxUpdateService::ProcessPendingItems);
401 } 399 }
402 400
403 // Given a extension-like component id, find the associated component. 401 // Given a extension-like component id, find the associated component.
404 CrxUpdateItem* CrxUpdateService::FindUpdateItemById(const std::string& id) { 402 CrxUpdateItem* CrxUpdateService::FindUpdateItemById(
403 const std::string& id) const {
405 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
406 CrxUpdateItem::FindById finder(id); 405 CrxUpdateItem::FindById finder(id);
407 UpdateItems::iterator it = std::find_if(work_items_.begin(), 406 UpdateItems::const_iterator it = std::find_if(work_items_.begin(),
408 work_items_.end(), 407 work_items_.end(),
409 finder); 408 finder);
410 return it != work_items_.end() ? *it : NULL; 409 return it != work_items_.end() ? *it : NULL;
411 } 410 }
412 411
413 // Changes a component's status, clearing on_demand and firing notifications as 412 // Changes a component's status, clearing on_demand and firing notifications as
414 // necessary. By convention, this is the only function that can change a 413 // necessary. By convention, this is the only function that can change a
415 // CrxUpdateItem's |status|. 414 // CrxUpdateItem's |status|.
416 // TODO(waffles): Do we want to add DCHECKS for valid state transitions here? 415 // TODO(waffles): Do we want to add DCHECKS for valid state transitions here?
417 void CrxUpdateService::ChangeItemState(CrxUpdateItem* item, 416 void CrxUpdateService::ChangeItemState(CrxUpdateItem* item,
418 CrxUpdateItem::Status to) { 417 CrxUpdateItem::Status to) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
560 std::vector<CrxComponentInfo>* components) {
561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
548 std::vector<std::string> component_ids;
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(item->id);
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 }
554 return component_ids;
571 } 555 }
572 556
557 CrxUpdateItem* CrxUpdateService::GetComponentDetails(
558 const std::string& component_id) const {
559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
560 CrxUpdateItem* item = FindUpdateItemById(component_id);
Sorin Jianu 2014/05/08 22:07:24 we could just return FindUpdateItemById(component_
Shrikant Kelkar 2014/05/15 23:12:43 Done.
561 return item;
562 }
563
564
Sorin Jianu 2014/05/08 22:07:24 One extra empty line could be removed.
Shrikant Kelkar 2014/05/15 23:12:43 Done.
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698