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

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: cleanup 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 const CrxComponent& component) { 426 const CrxComponent& component) {
426 DCHECK(thread_checker_.CalledOnValidThread()); 427 DCHECK(thread_checker_.CalledOnValidThread());
427 if (component.pk_hash.empty() || !component.version.IsValid() || 428 if (component.pk_hash.empty() || !component.version.IsValid() ||
428 !component.installer) 429 !component.installer)
429 return kError; 430 return kError;
430 431
431 std::string id(GetCrxComponentID(component)); 432 std::string id(GetCrxComponentID(component));
432 CrxUpdateItem* uit = FindUpdateItemById(id); 433 CrxUpdateItem* uit = FindUpdateItemById(id);
433 if (uit) { 434 if (uit) {
434 uit->component = component; 435 uit->component = component;
436 uit->unregistered = false;
435 return kReplaced; 437 return kReplaced;
436 } 438 }
437 439
438 uit = new CrxUpdateItem; 440 uit = new CrxUpdateItem;
439 uit->id.swap(id); 441 uit->id.swap(id);
440 uit->component = component; 442 uit->component = component;
441 443
442 work_items_.push_back(uit); 444 work_items_.push_back(uit);
443 445
444 // If this is the first component registered we call Start to 446 // If this is the first component registered we call Start to
445 // schedule the first timer. Otherwise, reset the timer to trigger another 447 // schedule the first timer. Otherwise, reset the timer to trigger another
446 // pass over the work items, if the component updater is sleeping, fact 448 // 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 449 // 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 450 // the service is busy updating something, and in that case, this component
449 // will be picked up at the next pass. 451 // will be picked up at the next pass.
450 if (running_) { 452 if (running_) {
451 if (work_items_.size() == 1) { 453 if (work_items_.size() == 1) {
452 Start(); 454 Start();
453 } else if (timer_.IsRunning()) { 455 } else if (timer_.IsRunning()) {
454 timer_.Start(FROM_HERE, 456 timer_.Start(FROM_HERE,
455 base::TimeDelta::FromSeconds(config_->InitialDelay()), 457 base::TimeDelta::FromSeconds(config_->InitialDelay()),
456 this, 458 this,
457 &CrxUpdateService::ProcessPendingItems); 459 &CrxUpdateService::ProcessPendingItems);
458 } 460 }
459 } 461 }
460 462
461 return kOk; 463 return kOk;
462 } 464 }
463 465
466 ComponentUpdateService::Status CrxUpdateService::UnregisterComponent(
467 const std::string& crx_id) {
468 UpdateItems::iterator it = std::find_if(
Sorin Jianu 2015/02/06 19:11:58 maybe use auto?
Bernhard Bauer 2015/02/06 22:49:03 Done.
469 work_items_.begin(), work_items_.end(), CrxUpdateItem::FindById(crx_id));
470 if (it == work_items_.end())
471 return kError;
472
473 (*it)->unregistered = true;
474
475 ScheduleNextRun(kStepDelayShort);
476 return kOk;
477 }
478
464 std::vector<std::string> CrxUpdateService::GetComponentIDs() const { 479 std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
465 DCHECK(thread_checker_.CalledOnValidThread()); 480 DCHECK(thread_checker_.CalledOnValidThread());
466 std::vector<std::string> component_ids; 481 std::vector<std::string> component_ids;
467 for (UpdateItems::const_iterator it = work_items_.begin(); 482 for (UpdateItems::const_iterator it = work_items_.begin();
468 it != work_items_.end(); 483 it != work_items_.end();
469 ++it) { 484 ++it) {
470 const CrxUpdateItem* item = *it; 485 const CrxUpdateItem* item = *it;
471 component_ids.push_back(item->id); 486 component_ids.push_back(item->id);
472 } 487 }
473 return component_ids; 488 return component_ids;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 // takes a long sleep until the loop runs again. 532 // takes a long sleep until the loop runs again.
518 void CrxUpdateService::ProcessPendingItems() { 533 void CrxUpdateService::ProcessPendingItems() {
519 DCHECK(thread_checker_.CalledOnValidThread()); 534 DCHECK(thread_checker_.CalledOnValidThread());
520 535
521 CrxUpdateItem* ready_upgrade = FindReadyComponent(); 536 CrxUpdateItem* ready_upgrade = FindReadyComponent();
522 if (ready_upgrade) { 537 if (ready_upgrade) {
523 UpdateComponent(ready_upgrade); 538 UpdateComponent(ready_upgrade);
524 return; 539 return;
525 } 540 }
526 541
542 // Uninstall and remove all unregistered work items.
Sorin Jianu 2015/02/06 19:11:58 Can we factor out this code as a member function?
Bernhard Bauer 2015/02/06 22:49:03 Done.
543 std::vector<CrxUpdateItem*> new_work_items;
544 for (CrxUpdateItem* item : work_items_) {
545 scoped_ptr<CrxUpdateItem> owned_item(item);
546 if (owned_item->unregistered) {
547 bool success = owned_item->component.installer->Uninstall();
Sorin Jianu 2015/02/06 19:11:58 could be const
Bernhard Bauer 2015/02/06 22:49:03 Done.
548 DCHECK(success);
549 } else {
550 new_work_items.push_back(owned_item.release());
551 }
552 }
553 new_work_items.swap(work_items_);
554
527 if (!CheckForUpdates()) 555 if (!CheckForUpdates())
528 ScheduleNextRun(kStepDelayLong); 556 ScheduleNextRun(kStepDelayLong);
529 } 557 }
530 558
531 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { 559 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
532 class Helper { 560 class Helper {
533 public: 561 public:
534 static bool IsReadyOnDemand(CrxUpdateItem* item) { 562 static bool IsReadyOnDemand(CrxUpdateItem* item) {
535 return item->on_demand && IsReady(item); 563 return item->on_demand && IsReady(item);
536 } 564 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 802
775 // Called when the CRX package has been downloaded to a temporary location. 803 // Called when the CRX package has been downloaded to a temporary location.
776 // Here we fire the notifications and schedule the component-specific installer 804 // Here we fire the notifications and schedule the component-specific installer
777 // to be called in the file thread. 805 // to be called in the file thread.
778 void CrxUpdateService::DownloadComplete( 806 void CrxUpdateService::DownloadComplete(
779 scoped_ptr<CRXContext> crx_context, 807 scoped_ptr<CRXContext> crx_context,
780 const CrxDownloader::Result& download_result) { 808 const CrxDownloader::Result& download_result) {
781 DCHECK(thread_checker_.CalledOnValidThread()); 809 DCHECK(thread_checker_.CalledOnValidThread());
782 810
783 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id); 811 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id);
812
784 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || 813 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff ||
785 crx->status == CrxUpdateItem::kDownloading); 814 crx->status == CrxUpdateItem::kDownloading);
786 815
787 AppendDownloadMetrics(crx_downloader_->download_metrics(), 816 AppendDownloadMetrics(crx_downloader_->download_metrics(),
788 &crx->download_metrics); 817 &crx->download_metrics);
789 818
790 crx_downloader_.reset(); 819 crx_downloader_.reset();
791 820
792 if (download_result.error) { 821 if (download_result.error) {
793 if (crx->status == CrxUpdateItem::kDownloadingDiff) { 822 if (crx->status == CrxUpdateItem::kDownloadingDiff) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 error_category = kInstallError; 917 error_category = kInstallError;
889 break; 918 break;
890 default: 919 default:
891 error_category = kUnpackError; 920 error_category = kUnpackError;
892 break; 921 break;
893 } 922 }
894 923
895 const bool is_success = error == ComponentUnpacker::kNone; 924 const bool is_success = error == ComponentUnpacker::kNone;
896 925
897 CrxUpdateItem* item = FindUpdateItemById(component_id); 926 CrxUpdateItem* item = FindUpdateItemById(component_id);
927
898 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { 928 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) {
899 item->diff_error_category = error_category; 929 item->diff_error_category = error_category;
900 item->diff_error_code = error; 930 item->diff_error_code = error;
901 item->diff_extra_code1 = extra_code; 931 item->diff_extra_code1 = extra_code;
902 item->diff_update_failed = true; 932 item->diff_update_failed = true;
903 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, 933 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff,
904 CrxUpdateItem::kCanUpdate); 934 CrxUpdateItem::kCanUpdate);
905 DCHECK_EQ(count, 1ul); 935 DCHECK_EQ(count, 1ul);
906 ScheduleNextRun(kStepDelayShort); 936 ScheduleNextRun(kStepDelayShort);
907 return; 937 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 /////////////////////////////////////////////////////////////////////////////// 1032 ///////////////////////////////////////////////////////////////////////////////
1003 1033
1004 // The component update factory. Using the component updater as a singleton 1034 // The component update factory. Using the component updater as a singleton
1005 // is the job of the browser process. 1035 // is the job of the browser process.
1006 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { 1036 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) {
1007 DCHECK(config); 1037 DCHECK(config);
1008 return new CrxUpdateService(config); 1038 return new CrxUpdateService(config);
1009 } 1039 }
1010 1040
1011 } // namespace component_updater 1041 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698