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

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 as per code review comments. Created 6 years, 8 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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 // If the item is already in the process of being updated, there is
Sorin Jianu 2014/03/26 21:41:08 The comments in this function don't make sense any
Shrikant Kelkar 2014/03/26 21:44:43 Done.
982 // no point in this call, so return kInProgress.
983 case CrxUpdateItem::kChecking:
984 case CrxUpdateItem::kCanUpdate:
985 case CrxUpdateItem::kDownloadingDiff:
986 case CrxUpdateItem::kDownloading:
987 case CrxUpdateItem::kUpdatingDiff:
988 case CrxUpdateItem::kUpdating:
989 return kInProgress;
990 // Otherwise the item was already checked a while back (or it is new),
991 // set its status to kNew to give it a slightly higher priority.
992 case CrxUpdateItem::kNew:
993 case CrxUpdateItem::kUpdated:
994 case CrxUpdateItem::kUpToDate:
995 case CrxUpdateItem::kNoUpdate:
996 return kOk;
997 break;
998 case CrxUpdateItem::kLastStatus:
999 NOTREACHED() << status;
1000 }
1001 return kError;
1002 }
1003
976 /////////////////////////////////////////////////////////////////////////////// 1004 ///////////////////////////////////////////////////////////////////////////////
977 1005
978 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) 1006 CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request)
979 : state_(NEW) { 1007 : state_(NEW) {
980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1008 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
981 } 1009 }
982 1010
983 CUResourceThrottle::~CUResourceThrottle() { 1011 CUResourceThrottle::~CUResourceThrottle() {
984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
985 } 1013 }
(...skipping 25 matching lines...) Expand all
1011 // The component update factory. Using the component updater as a singleton 1039 // The component update factory. Using the component updater as a singleton
1012 // is the job of the browser process. 1040 // is the job of the browser process.
1013 ComponentUpdateService* ComponentUpdateServiceFactory( 1041 ComponentUpdateService* ComponentUpdateServiceFactory(
1014 ComponentUpdateService::Configurator* config) { 1042 ComponentUpdateService::Configurator* config) {
1015 DCHECK(config); 1043 DCHECK(config);
1016 return new CrxUpdateService(config); 1044 return new CrxUpdateService(config);
1017 } 1045 }
1018 1046
1019 } // namespace component_updater 1047 } // namespace component_updater
1020 1048
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/component_updater_service.h ('k') | chrome/browser/resources/components.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698