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

Side by Side Diff: components/component_updater/component_updater_service.cc

Issue 879993005: Add support for uninstalling components and use it in SupervisedUserWhitelistInstaller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/component_updater/component_updater_service.h" 5 #include "components/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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 public: 93 public:
94 explicit CrxUpdateService(Configurator* config); 94 explicit CrxUpdateService(Configurator* config);
95 ~CrxUpdateService() override; 95 ~CrxUpdateService() override;
96 96
97 // Overrides for ComponentUpdateService. 97 // Overrides for ComponentUpdateService.
98 void AddObserver(Observer* observer) override; 98 void AddObserver(Observer* observer) override;
99 void RemoveObserver(Observer* observer) override; 99 void RemoveObserver(Observer* observer) override;
100 Status Start() override; 100 Status Start() override;
101 Status Stop() override; 101 Status Stop() override;
102 Status RegisterComponent(const CrxComponent& component) override; 102 Status RegisterComponent(const CrxComponent& component) override;
103 Status UnregisterComponent(const std::string& crx_id) override;
103 std::vector<std::string> GetComponentIDs() const override; 104 std::vector<std::string> GetComponentIDs() const override;
104 OnDemandUpdater& GetOnDemandUpdater() override; 105 OnDemandUpdater& GetOnDemandUpdater() override;
105 void MaybeThrottle(const std::string& crx_id, 106 void MaybeThrottle(const std::string& crx_id,
106 const base::Closure& callback) override; 107 const base::Closure& callback) override;
107 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override; 108 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override;
108 109
109 // Context for a crx download url request. 110 // Context for a crx download url request.
110 struct CRXContext { 111 struct CRXContext {
111 scoped_refptr<ComponentInstaller> installer; 112 scoped_refptr<ComponentInstaller> installer;
112 std::vector<uint8_t> pk_hash; 113 std::vector<uint8_t> pk_hash;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const CrxDownloader::Result& download_result); 148 const CrxDownloader::Result& download_result);
148 149
149 void DownloadComplete(scoped_ptr<CRXContext> crx_context, 150 void DownloadComplete(scoped_ptr<CRXContext> crx_context,
150 const CrxDownloader::Result& download_result); 151 const CrxDownloader::Result& download_result);
151 152
152 Status OnDemandUpdateInternal(CrxUpdateItem* item); 153 Status OnDemandUpdateInternal(CrxUpdateItem* item);
153 Status OnDemandUpdateWithCooldown(CrxUpdateItem* item); 154 Status OnDemandUpdateWithCooldown(CrxUpdateItem* item);
154 155
155 void ProcessPendingItems(); 156 void ProcessPendingItems();
156 157
158 // Uninstall and remove all unregistered work items.
159 void UninstallUnregisteredItems();
160
157 // Find a component that is ready to update. 161 // Find a component that is ready to update.
158 CrxUpdateItem* FindReadyComponent() const; 162 CrxUpdateItem* FindReadyComponent() const;
159 163
160 // Prepares the components for an update check and initiates the request. 164 // Prepares the components for an update check and initiates the request.
161 // Returns true if an update check request has been made. Returns false if 165 // Returns true if an update check request has been made. Returns false if
162 // no update check was needed or an error occured. 166 // no update check was needed or an error occured.
163 bool CheckForUpdates(); 167 bool CheckForUpdates();
164 168
165 void UpdateComponent(CrxUpdateItem* workitem); 169 void UpdateComponent(CrxUpdateItem* workitem);
166 170
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 const CrxComponent& component) { 429 const CrxComponent& component) {
426 DCHECK(thread_checker_.CalledOnValidThread()); 430 DCHECK(thread_checker_.CalledOnValidThread());
427 if (component.pk_hash.empty() || !component.version.IsValid() || 431 if (component.pk_hash.empty() || !component.version.IsValid() ||
428 !component.installer) 432 !component.installer)
429 return kError; 433 return kError;
430 434
431 std::string id(GetCrxComponentID(component)); 435 std::string id(GetCrxComponentID(component));
432 CrxUpdateItem* uit = FindUpdateItemById(id); 436 CrxUpdateItem* uit = FindUpdateItemById(id);
433 if (uit) { 437 if (uit) {
434 uit->component = component; 438 uit->component = component;
439 uit->unregistered = false;
435 return kReplaced; 440 return kReplaced;
436 } 441 }
437 442
438 uit = new CrxUpdateItem; 443 uit = new CrxUpdateItem;
439 uit->id.swap(id); 444 uit->id.swap(id);
440 uit->component = component; 445 uit->component = component;
441 446
442 work_items_.push_back(uit); 447 work_items_.push_back(uit);
443 448
444 // If this is the first component registered we call Start to 449 // If this is the first component registered we call Start to
445 // schedule the first timer. Otherwise, reset the timer to trigger another 450 // schedule the first timer. Otherwise, reset the timer to trigger another
446 // pass over the work items, if the component updater is sleeping, fact 451 // pass over the work items, if the component updater is sleeping, fact
447 // indicated by a running timer. If the timer is not running, it means that 452 // indicated by a running timer. If the timer is not running, it means that
448 // the service is busy updating something, and in that case, this component 453 // the service is busy updating something, and in that case, this component
449 // will be picked up at the next pass. 454 // will be picked up at the next pass.
450 if (running_) { 455 if (running_) {
451 if (work_items_.size() == 1) { 456 if (work_items_.size() == 1) {
452 Start(); 457 Start();
453 } else if (timer_.IsRunning()) { 458 } else if (timer_.IsRunning()) {
454 timer_.Start(FROM_HERE, 459 timer_.Start(FROM_HERE,
455 base::TimeDelta::FromSeconds(config_->InitialDelay()), 460 base::TimeDelta::FromSeconds(config_->InitialDelay()),
456 this, 461 this,
457 &CrxUpdateService::ProcessPendingItems); 462 &CrxUpdateService::ProcessPendingItems);
458 } 463 }
459 } 464 }
460 465
461 return kOk; 466 return kOk;
462 } 467 }
463 468
469 ComponentUpdateService::Status CrxUpdateService::UnregisterComponent(
470 const std::string& crx_id) {
471 auto it = std::find_if(work_items_.begin(), work_items_.end(),
472 CrxUpdateItem::FindById(crx_id));
473 if (it == work_items_.end())
474 return kError;
475
476 (*it)->unregistered = true;
477
478 ScheduleNextRun(kStepDelayShort);
479 return kOk;
480 }
481
464 std::vector<std::string> CrxUpdateService::GetComponentIDs() const { 482 std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
465 DCHECK(thread_checker_.CalledOnValidThread()); 483 DCHECK(thread_checker_.CalledOnValidThread());
466 std::vector<std::string> component_ids; 484 std::vector<std::string> component_ids;
467 for (UpdateItems::const_iterator it = work_items_.begin(); 485 for (UpdateItems::const_iterator it = work_items_.begin();
468 it != work_items_.end(); 486 it != work_items_.end();
469 ++it) { 487 ++it) {
470 const CrxUpdateItem* item = *it; 488 const CrxUpdateItem* item = *it;
471 component_ids.push_back(item->id); 489 component_ids.push_back(item->id);
472 } 490 }
473 return component_ids; 491 return component_ids;
(...skipping 11 matching lines...) Expand all
485 Status status = OnDemandUpdateWithCooldown(item); 503 Status status = OnDemandUpdateWithCooldown(item);
486 if (status == kOk || status == kInProgress) { 504 if (status == kOk || status == kInProgress) {
487 item->ready_callbacks.push_back(callback); 505 item->ready_callbacks.push_back(callback);
488 return; 506 return;
489 } 507 }
490 callback.Run(); 508 callback.Run();
491 } 509 }
492 510
493 scoped_refptr<base::SequencedTaskRunner> 511 scoped_refptr<base::SequencedTaskRunner>
494 CrxUpdateService::GetSequencedTaskRunner() { 512 CrxUpdateService::GetSequencedTaskRunner() {
495 return config_->GetSequencedTaskRunner(); 513 return blocking_task_runner_;
Bernhard Bauer 2015/02/08 23:20:40 I had to make this change because of failing tests
496 } 514 }
497 515
498 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, 516 bool CrxUpdateService::GetComponentDetails(const std::string& component_id,
499 CrxUpdateItem* item) const { 517 CrxUpdateItem* item) const {
500 DCHECK(thread_checker_.CalledOnValidThread()); 518 DCHECK(thread_checker_.CalledOnValidThread());
501 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); 519 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id));
502 if (crx_update_item) 520 if (crx_update_item)
503 *item = *crx_update_item; 521 *item = *crx_update_item;
504 return crx_update_item != NULL; 522 return crx_update_item != NULL;
505 } 523 }
(...skipping 11 matching lines...) Expand all
517 // takes a long sleep until the loop runs again. 535 // takes a long sleep until the loop runs again.
518 void CrxUpdateService::ProcessPendingItems() { 536 void CrxUpdateService::ProcessPendingItems() {
519 DCHECK(thread_checker_.CalledOnValidThread()); 537 DCHECK(thread_checker_.CalledOnValidThread());
520 538
521 CrxUpdateItem* ready_upgrade = FindReadyComponent(); 539 CrxUpdateItem* ready_upgrade = FindReadyComponent();
522 if (ready_upgrade) { 540 if (ready_upgrade) {
523 UpdateComponent(ready_upgrade); 541 UpdateComponent(ready_upgrade);
524 return; 542 return;
525 } 543 }
526 544
545 UninstallUnregisteredItems();
546
527 if (!CheckForUpdates()) 547 if (!CheckForUpdates())
528 ScheduleNextRun(kStepDelayLong); 548 ScheduleNextRun(kStepDelayLong);
529 } 549 }
530 550
551 void CrxUpdateService::UninstallUnregisteredItems() {
552 std::vector<CrxUpdateItem*> new_work_items;
553 for (CrxUpdateItem* item : work_items_) {
554 scoped_ptr<CrxUpdateItem> owned_item(item);
555 if (owned_item->unregistered) {
556 const bool success = owned_item->component.installer->Uninstall();
557 DCHECK(success);
558 } else {
559 new_work_items.push_back(owned_item.release());
560 }
561 }
562 new_work_items.swap(work_items_);
563 }
564
531 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { 565 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
532 class Helper { 566 class Helper {
533 public: 567 public:
534 static bool IsReadyOnDemand(CrxUpdateItem* item) { 568 static bool IsReadyOnDemand(CrxUpdateItem* item) {
535 return item->on_demand && IsReady(item); 569 return item->on_demand && IsReady(item);
536 } 570 }
537 static bool IsReady(CrxUpdateItem* item) { 571 static bool IsReady(CrxUpdateItem* item) {
538 return item->status == CrxUpdateItem::kCanUpdate; 572 return item->status == CrxUpdateItem::kCanUpdate;
539 } 573 }
540 }; 574 };
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 808
775 // Called when the CRX package has been downloaded to a temporary location. 809 // Called when the CRX package has been downloaded to a temporary location.
776 // Here we fire the notifications and schedule the component-specific installer 810 // Here we fire the notifications and schedule the component-specific installer
777 // to be called in the file thread. 811 // to be called in the file thread.
778 void CrxUpdateService::DownloadComplete( 812 void CrxUpdateService::DownloadComplete(
779 scoped_ptr<CRXContext> crx_context, 813 scoped_ptr<CRXContext> crx_context,
780 const CrxDownloader::Result& download_result) { 814 const CrxDownloader::Result& download_result) {
781 DCHECK(thread_checker_.CalledOnValidThread()); 815 DCHECK(thread_checker_.CalledOnValidThread());
782 816
783 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id); 817 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id);
818
784 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || 819 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff ||
785 crx->status == CrxUpdateItem::kDownloading); 820 crx->status == CrxUpdateItem::kDownloading);
786 821
787 AppendDownloadMetrics(crx_downloader_->download_metrics(), 822 AppendDownloadMetrics(crx_downloader_->download_metrics(),
788 &crx->download_metrics); 823 &crx->download_metrics);
789 824
790 crx_downloader_.reset(); 825 crx_downloader_.reset();
791 826
792 if (download_result.error) { 827 if (download_result.error) {
793 if (crx->status == CrxUpdateItem::kDownloadingDiff) { 828 if (crx->status == CrxUpdateItem::kDownloadingDiff) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 error_category = kInstallError; 923 error_category = kInstallError;
889 break; 924 break;
890 default: 925 default:
891 error_category = kUnpackError; 926 error_category = kUnpackError;
892 break; 927 break;
893 } 928 }
894 929
895 const bool is_success = error == ComponentUnpacker::kNone; 930 const bool is_success = error == ComponentUnpacker::kNone;
896 931
897 CrxUpdateItem* item = FindUpdateItemById(component_id); 932 CrxUpdateItem* item = FindUpdateItemById(component_id);
933
898 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { 934 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) {
899 item->diff_error_category = error_category; 935 item->diff_error_category = error_category;
900 item->diff_error_code = error; 936 item->diff_error_code = error;
901 item->diff_extra_code1 = extra_code; 937 item->diff_extra_code1 = extra_code;
902 item->diff_update_failed = true; 938 item->diff_update_failed = true;
903 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, 939 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff,
904 CrxUpdateItem::kCanUpdate); 940 CrxUpdateItem::kCanUpdate);
905 DCHECK_EQ(count, 1ul); 941 DCHECK_EQ(count, 1ul);
906 ScheduleNextRun(kStepDelayShort); 942 ScheduleNextRun(kStepDelayShort);
907 return; 943 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 /////////////////////////////////////////////////////////////////////////////// 1038 ///////////////////////////////////////////////////////////////////////////////
1003 1039
1004 // The component update factory. Using the component updater as a singleton 1040 // The component update factory. Using the component updater as a singleton
1005 // is the job of the browser process. 1041 // is the job of the browser process.
1006 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { 1042 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) {
1007 DCHECK(config); 1043 DCHECK(config);
1008 return new CrxUpdateService(config); 1044 return new CrxUpdateService(config);
1009 } 1045 }
1010 1046
1011 } // namespace component_updater 1047 } // namespace component_updater
OLDNEW
« no previous file with comments | « components/component_updater/component_updater_service.h ('k') | components/component_updater/default_component_installer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698