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

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

Issue 144523004: Randomize order in which ready component updates are applied. On demand updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: synced Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/rand_util.h"
19 #include "base/sequenced_task_runner.h" 20 #include "base/sequenced_task_runner.h"
20 #include "base/stl_util.h" 21 #include "base/stl_util.h"
21 #include "base/threading/sequenced_worker_pool.h" 22 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/timer/timer.h" 23 #include "base/timer/timer.h"
23 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/component_updater/component_patcher.h" 25 #include "chrome/browser/component_updater/component_patcher.h"
25 #include "chrome/browser/component_updater/component_unpacker.h" 26 #include "chrome/browser/component_updater/component_unpacker.h"
26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" 27 #include "chrome/browser/component_updater/component_updater_ping_manager.h"
27 #include "chrome/browser/component_updater/component_updater_utils.h" 28 #include "chrome/browser/component_updater/component_updater_utils.h"
28 #include "chrome/browser/component_updater/crx_downloader.h" 29 #include "chrome/browser/component_updater/crx_downloader.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 if (ready_upgrade) { 568 if (ready_upgrade) {
568 UpdateComponent(ready_upgrade); 569 UpdateComponent(ready_upgrade);
569 return; 570 return;
570 } 571 }
571 572
572 if (!CheckForUpdates()) 573 if (!CheckForUpdates())
573 ScheduleNextRun(kStepDelayLong); 574 ScheduleNextRun(kStepDelayLong);
574 } 575 }
575 576
576 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { 577 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
577 class Helper { 578 std::vector<CrxUpdateItem*> ready;
578 public: 579 std::vector<CrxUpdateItem*> ready_on_demand;
579 static bool IsReadyOnDemand(CrxUpdateItem* item) { 580 for (std::vector<CrxUpdateItem*>::const_iterator it = work_items_.begin();
580 return item->on_demand && IsReady(item); 581 it != work_items_.end();
582 ++it) {
583 CrxUpdateItem* item = *it;
584 if (item->status == CrxUpdateItem::kCanUpdate) {
585 if (item->on_demand)
586 ready_on_demand.push_back(item);
587 else
588 ready.push_back(item);
581 } 589 }
582 static bool IsReady(CrxUpdateItem* item) { 590 }
583 return item->status == CrxUpdateItem::kCanUpdate;
584 }
585 };
586 591
587 std::vector<CrxUpdateItem*>::const_iterator it = std::find_if( 592 if (ready_on_demand.size() > 0) {
588 work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand); 593 return ready_on_demand[base::RandInt(0, ready_on_demand.size() - 1)];
589 if (it != work_items_.end()) 594 }
590 return *it; 595 if (ready.size() > 0) {
591 it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady); 596 return ready[base::RandInt(0, ready.size() - 1)];
592 if (it != work_items_.end()) 597 }
593 return *it;
594 return NULL; 598 return NULL;
595 } 599 }
596 600
597 // Prepares the components for an update check and initiates the request. 601 // Prepares the components for an update check and initiates the request.
598 // On demand components are always included in the update check request. 602 // On demand components are always included in the update check request.
599 // Otherwise, only include components that have not been checked recently. 603 // Otherwise, only include components that have not been checked recently.
600 bool CrxUpdateService::CheckForUpdates() { 604 bool CrxUpdateService::CheckForUpdates() {
601 const base::TimeDelta minimum_recheck_wait_time = 605 const base::TimeDelta minimum_recheck_wait_time =
602 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait()); 606 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait());
603 const base::Time now(base::Time::Now()); 607 const base::Time now(base::Time::Now());
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 // The component update factory. Using the component updater as a singleton 1015 // The component update factory. Using the component updater as a singleton
1012 // is the job of the browser process. 1016 // is the job of the browser process.
1013 ComponentUpdateService* ComponentUpdateServiceFactory( 1017 ComponentUpdateService* ComponentUpdateServiceFactory(
1014 ComponentUpdateService::Configurator* config) { 1018 ComponentUpdateService::Configurator* config) {
1015 DCHECK(config); 1019 DCHECK(config);
1016 return new CrxUpdateService(config); 1020 return new CrxUpdateService(config);
1017 } 1021 }
1018 1022
1019 } // namespace component_updater 1023 } // namespace component_updater
1020 1024
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698