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

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, 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
« 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/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/stringprintf.h"
Sorin Jianu 2014/02/11 22:10:23 What is the reason for including this header?
bartekn 2014/02/13 22:51:30 Whoops, sorry, I used it for printing some debug m
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"
29 #include "chrome/browser/component_updater/crx_update_item.h" 30 #include "chrome/browser/component_updater/crx_update_item.h"
30 #include "chrome/browser/component_updater/update_checker.h" 31 #include "chrome/browser/component_updater/update_checker.h"
(...skipping 536 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;
Sorin Jianu 2014/02/11 22:10:23 One idea to filter the work_items_ is by using std
bartekn 2014/02/13 22:51:30 I tried it, but for some reason copy_if doesn't se
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) {
Sorin Jianu 2014/02/11 22:10:23 the chrome style guide prefers not fully bracing s
bartekn 2014/02/13 22:51:30 Done.
586 ready_on_demand.push_back(item);
587 } else {
588 ready.push_back(item);
589 }
581 } 590 }
582 static bool IsReady(CrxUpdateItem* item) { 591 }
583 return item->status == CrxUpdateItem::kCanUpdate;
584 }
585 };
586 592
587 std::vector<CrxUpdateItem*>::const_iterator it = std::find_if( 593 if (ready_on_demand.size() > 0) {
588 work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand); 594 int r = rand();
Sorin Jianu 2014/02/11 22:10:23 I suggest using a function from base/rand_util.h a
bartekn 2014/02/13 22:51:30 Done.
589 if (it != work_items_.end()) 595 return ready_on_demand[r % ready_on_demand.size()];
590 return *it; 596 }
591 it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady); 597 if (ready.size() > 0) {
592 if (it != work_items_.end()) 598 int r = rand();
593 return *it; 599 return ready[r % ready.size()];
600 }
594 return NULL; 601 return NULL;
595 } 602 }
596 603
597 // Prepares the components for an update check and initiates the request. 604 // Prepares the components for an update check and initiates the request.
598 bool CrxUpdateService::CheckForUpdates() { 605 bool CrxUpdateService::CheckForUpdates() {
599 // All components are selected for the update check, regardless of when they 606 // All components are selected for the update check, regardless of when they
600 // were last checked. More selective algorithms could be implemented in the 607 // were last checked. More selective algorithms could be implemented in the
601 // future. 608 // future.
602 std::vector<CrxUpdateItem*> items_to_check; 609 std::vector<CrxUpdateItem*> items_to_check;
603 for (size_t i = 0; i != work_items_.size(); ++i) { 610 for (size_t i = 0; i != work_items_.size(); ++i) {
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 // The component update factory. Using the component updater as a singleton 1008 // The component update factory. Using the component updater as a singleton
1002 // is the job of the browser process. 1009 // is the job of the browser process.
1003 ComponentUpdateService* ComponentUpdateServiceFactory( 1010 ComponentUpdateService* ComponentUpdateServiceFactory(
1004 ComponentUpdateService::Configurator* config) { 1011 ComponentUpdateService::Configurator* config) {
1005 DCHECK(config); 1012 DCHECK(config);
1006 return new CrxUpdateService(config); 1013 return new CrxUpdateService(config);
1007 } 1014 }
1008 1015
1009 } // namespace component_updater 1016 } // namespace component_updater
1010 1017
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