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

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

Issue 192283003: Revert of 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: 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"
20 #include "base/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
21 #include "base/stl_util.h" 20 #include "base/stl_util.h"
22 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
23 #include "base/timer/timer.h" 22 #include "base/timer/timer.h"
24 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/component_updater/component_patcher.h" 24 #include "chrome/browser/component_updater/component_patcher.h"
26 #include "chrome/browser/component_updater/component_unpacker.h" 25 #include "chrome/browser/component_updater/component_unpacker.h"
27 #include "chrome/browser/component_updater/component_updater_ping_manager.h" 26 #include "chrome/browser/component_updater/component_updater_ping_manager.h"
28 #include "chrome/browser/component_updater/component_updater_utils.h" 27 #include "chrome/browser/component_updater/component_updater_utils.h"
29 #include "chrome/browser/component_updater/crx_downloader.h" 28 #include "chrome/browser/component_updater/crx_downloader.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 if (ready_upgrade) { 567 if (ready_upgrade) {
569 UpdateComponent(ready_upgrade); 568 UpdateComponent(ready_upgrade);
570 return; 569 return;
571 } 570 }
572 571
573 if (!CheckForUpdates()) 572 if (!CheckForUpdates())
574 ScheduleNextRun(kStepDelayLong); 573 ScheduleNextRun(kStepDelayLong);
575 } 574 }
576 575
577 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { 576 CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
578 std::vector<CrxUpdateItem*> ready; 577 class Helper {
579 std::vector<CrxUpdateItem*> ready_on_demand; 578 public:
580 for (std::vector<CrxUpdateItem*>::const_iterator it = work_items_.begin(); 579 static bool IsReadyOnDemand(CrxUpdateItem* item) {
581 it != work_items_.end(); 580 return item->on_demand && IsReady(item);
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);
589 } 581 }
590 } 582 static bool IsReady(CrxUpdateItem* item) {
583 return item->status == CrxUpdateItem::kCanUpdate;
584 }
585 };
591 586
592 if (ready_on_demand.size() > 0) { 587 std::vector<CrxUpdateItem*>::const_iterator it = std::find_if(
593 return ready_on_demand[base::RandInt(0, ready_on_demand.size() - 1)]; 588 work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand);
594 } 589 if (it != work_items_.end())
595 if (ready.size() > 0) { 590 return *it;
596 return ready[base::RandInt(0, ready.size() - 1)]; 591 it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady);
597 } 592 if (it != work_items_.end())
593 return *it;
598 return NULL; 594 return NULL;
599 } 595 }
600 596
601 // Prepares the components for an update check and initiates the request. 597 // Prepares the components for an update check and initiates the request.
602 // On demand components are always included in the update check request. 598 // On demand components are always included in the update check request.
603 // Otherwise, only include components that have not been checked recently. 599 // Otherwise, only include components that have not been checked recently.
604 bool CrxUpdateService::CheckForUpdates() { 600 bool CrxUpdateService::CheckForUpdates() {
605 const base::TimeDelta minimum_recheck_wait_time = 601 const base::TimeDelta minimum_recheck_wait_time =
606 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait()); 602 base::TimeDelta::FromSeconds(config_->MinimumReCheckWait());
607 const base::Time now(base::Time::Now()); 603 const base::Time now(base::Time::Now());
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 // The component update factory. Using the component updater as a singleton 1011 // The component update factory. Using the component updater as a singleton
1016 // is the job of the browser process. 1012 // is the job of the browser process.
1017 ComponentUpdateService* ComponentUpdateServiceFactory( 1013 ComponentUpdateService* ComponentUpdateServiceFactory(
1018 ComponentUpdateService::Configurator* config) { 1014 ComponentUpdateService::Configurator* config) {
1019 DCHECK(config); 1015 DCHECK(config);
1020 return new CrxUpdateService(config); 1016 return new CrxUpdateService(config);
1021 } 1017 }
1022 1018
1023 } // namespace component_updater 1019 } // namespace component_updater
1024 1020
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