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

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: rebase 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 timer_.Start(FROM_HERE, 455 timer_.Start(FROM_HERE,
455 base::TimeDelta::FromSeconds(config_->InitialDelay()), 456 base::TimeDelta::FromSeconds(config_->InitialDelay()),
456 this, 457 this,
457 &CrxUpdateService::ProcessPendingItems); 458 &CrxUpdateService::ProcessPendingItems);
458 } 459 }
459 } 460 }
460 461
461 return kOk; 462 return kOk;
462 } 463 }
463 464
465 ComponentUpdateService::Status CrxUpdateService::UnregisterComponent(
466 const std::string& crx_id) {
467 UpdateItems::iterator it = std::find_if(
468 work_items_.begin(), work_items_.end(), CrxUpdateItem::FindById(crx_id));
469 if (it == work_items_.end())
470 return kError;
471
472 CrxUpdateItem* item = *it;
473 CrxUpdateItem::Status status = item->status;
474 if (status == CrxUpdateItem::kDownloading ||
475 status == CrxUpdateItem::kDownloadingDiff ||
476 status == CrxUpdateItem::kUpdating ||
477 status == CrxUpdateItem::kUpdatingDiff) {
478 ChangeItemState(item, CrxUpdateItem::kNoUpdate);
479 ping_manager_->OnUpdateComplete(item);
480 }
481
482 work_items_.erase(it);
Sorin Jianu 2015/02/05 22:55:35 We wonder if we could do this in a different way.
Bernhard Bauer 2015/02/05 23:57:35 Okay, that makes sense. I'll try to work on that t
483 return kOk;
484 }
485
464 std::vector<std::string> CrxUpdateService::GetComponentIDs() const { 486 std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
465 DCHECK(thread_checker_.CalledOnValidThread()); 487 DCHECK(thread_checker_.CalledOnValidThread());
466 std::vector<std::string> component_ids; 488 std::vector<std::string> component_ids;
467 for (UpdateItems::const_iterator it = work_items_.begin(); 489 for (UpdateItems::const_iterator it = work_items_.begin();
468 it != work_items_.end(); 490 it != work_items_.end();
469 ++it) { 491 ++it) {
470 const CrxUpdateItem* item = *it; 492 const CrxUpdateItem* item = *it;
471 component_ids.push_back(item->id); 493 component_ids.push_back(item->id);
472 } 494 }
473 return component_ids; 495 return component_ids;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // at a time if updates are available. Otherwise, it does an update check or 538 // at a time if updates are available. Otherwise, it does an update check or
517 // takes a long sleep until the loop runs again. 539 // takes a long sleep until the loop runs again.
518 void CrxUpdateService::ProcessPendingItems() { 540 void CrxUpdateService::ProcessPendingItems() {
519 DCHECK(thread_checker_.CalledOnValidThread()); 541 DCHECK(thread_checker_.CalledOnValidThread());
520 542
521 CrxUpdateItem* ready_upgrade = FindReadyComponent(); 543 CrxUpdateItem* ready_upgrade = FindReadyComponent();
522 if (ready_upgrade) { 544 if (ready_upgrade) {
523 UpdateComponent(ready_upgrade); 545 UpdateComponent(ready_upgrade);
524 return; 546 return;
525 } 547 }
526 548
Sorin Jianu 2015/02/05 22:55:35 This is where we could inspect the state of the it
Bernhard Bauer 2015/02/06 16:05:05 Done.
527 if (!CheckForUpdates()) 549 if (!CheckForUpdates())
528 ScheduleNextRun(kStepDelayLong); 550 ScheduleNextRun(kStepDelayLong);
529 } 551 }
530 552
531 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { 553 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
532 class Helper { 554 class Helper {
533 public: 555 public:
534 static bool IsReadyOnDemand(CrxUpdateItem* item) { 556 static bool IsReadyOnDemand(CrxUpdateItem* item) {
535 return item->on_demand && IsReady(item); 557 return item->on_demand && IsReady(item);
536 } 558 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 796
775 // Called when the CRX package has been downloaded to a temporary location. 797 // Called when the CRX package has been downloaded to a temporary location.
776 // Here we fire the notifications and schedule the component-specific installer 798 // Here we fire the notifications and schedule the component-specific installer
777 // to be called in the file thread. 799 // to be called in the file thread.
778 void CrxUpdateService::DownloadComplete( 800 void CrxUpdateService::DownloadComplete(
779 scoped_ptr<CRXContext> crx_context, 801 scoped_ptr<CRXContext> crx_context,
780 const CrxDownloader::Result& download_result) { 802 const CrxDownloader::Result& download_result) {
781 DCHECK(thread_checker_.CalledOnValidThread()); 803 DCHECK(thread_checker_.CalledOnValidThread());
782 804
783 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id); 805 CrxUpdateItem* crx = FindUpdateItemById(crx_context->id);
806
807 // If the item has been removed in the mean time, clean up and return.
Sorin Jianu 2015/02/05 22:55:35 The code to clean up an item can be hooked up in t
Bernhard Bauer 2015/02/06 16:05:05 Done.
808 if (!crx) {
809 crx_downloader_.reset();
810 base::FilePath crx_path = download_result.response;
811 if (!crx_path.empty()) {
812 blocking_task_runner_->PostTask(
813 FROM_HERE,
814 base::Bind(base::IgnoreResult(
815 &update_client::DeleteFileAndEmptyParentDirectory),
816 crx_path));
817 }
818 // Move on to the next update, if there is one available.
819 ScheduleNextRun(kStepDelayMedium);
820 return;
821 }
822
784 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff || 823 DCHECK(crx->status == CrxUpdateItem::kDownloadingDiff ||
785 crx->status == CrxUpdateItem::kDownloading); 824 crx->status == CrxUpdateItem::kDownloading);
786 825
787 AppendDownloadMetrics(crx_downloader_->download_metrics(), 826 AppendDownloadMetrics(crx_downloader_->download_metrics(),
788 &crx->download_metrics); 827 &crx->download_metrics);
789 828
790 crx_downloader_.reset(); 829 crx_downloader_.reset();
791 830
792 if (download_result.error) { 831 if (download_result.error) {
793 if (crx->status == CrxUpdateItem::kDownloadingDiff) { 832 if (crx->status == CrxUpdateItem::kDownloadingDiff) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 error_category = kInstallError; 927 error_category = kInstallError;
889 break; 928 break;
890 default: 929 default:
891 error_category = kUnpackError; 930 error_category = kUnpackError;
892 break; 931 break;
893 } 932 }
894 933
895 const bool is_success = error == ComponentUnpacker::kNone; 934 const bool is_success = error == ComponentUnpacker::kNone;
896 935
897 CrxUpdateItem* item = FindUpdateItemById(component_id); 936 CrxUpdateItem* item = FindUpdateItemById(component_id);
937
938 // If the item has been removed in the mean time, return.
Sorin Jianu 2015/02/05 22:55:35 Same. The suggest is to centralize the unregistrat
Bernhard Bauer 2015/02/06 16:05:05 Done.
939 if (!item) {
940 ScheduleNextRun(kStepDelayMedium);
941 return;
942 }
943
898 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) { 944 if (item->status == CrxUpdateItem::kUpdatingDiff && !is_success) {
899 item->diff_error_category = error_category; 945 item->diff_error_category = error_category;
900 item->diff_error_code = error; 946 item->diff_error_code = error;
901 item->diff_extra_code1 = extra_code; 947 item->diff_extra_code1 = extra_code;
902 item->diff_update_failed = true; 948 item->diff_update_failed = true;
903 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff, 949 size_t count = ChangeItemStatus(CrxUpdateItem::kUpdatingDiff,
904 CrxUpdateItem::kCanUpdate); 950 CrxUpdateItem::kCanUpdate);
905 DCHECK_EQ(count, 1ul); 951 DCHECK_EQ(count, 1ul);
906 ScheduleNextRun(kStepDelayShort); 952 ScheduleNextRun(kStepDelayShort);
907 return; 953 return;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 /////////////////////////////////////////////////////////////////////////////// 1048 ///////////////////////////////////////////////////////////////////////////////
1003 1049
1004 // The component update factory. Using the component updater as a singleton 1050 // The component update factory. Using the component updater as a singleton
1005 // is the job of the browser process. 1051 // is the job of the browser process.
1006 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { 1052 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) {
1007 DCHECK(config); 1053 DCHECK(config);
1008 return new CrxUpdateService(config); 1054 return new CrxUpdateService(config);
1009 } 1055 }
1010 1056
1011 } // namespace component_updater 1057 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698