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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/component_updater/component_updater_service.cc
diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc
index fa04986f6829511953201f2f4fcabcf416b4cc2b..fcda0ca48e1dfcd689451e0d6d6c84b57a294e45 100644
--- a/chrome/browser/component_updater/component_updater_service.cc
+++ b/chrome/browser/component_updater/component_updater_service.cc
@@ -16,6 +16,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "base/rand_util.h"
#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/sequenced_worker_pool.h"
@@ -574,23 +575,26 @@ void CrxUpdateService::ProcessPendingItems() {
}
CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
- class Helper {
- public:
- static bool IsReadyOnDemand(CrxUpdateItem* item) {
- return item->on_demand && IsReady(item);
- }
- static bool IsReady(CrxUpdateItem* item) {
- return item->status == CrxUpdateItem::kCanUpdate;
+ std::vector<CrxUpdateItem*> ready;
+ std::vector<CrxUpdateItem*> ready_on_demand;
+ for (std::vector<CrxUpdateItem*>::const_iterator it = work_items_.begin();
+ it != work_items_.end();
+ ++it) {
+ CrxUpdateItem* item = *it;
+ if (item->status == CrxUpdateItem::kCanUpdate) {
+ if (item->on_demand)
+ ready_on_demand.push_back(item);
+ else
+ ready.push_back(item);
}
- };
+ }
- std::vector<CrxUpdateItem*>::const_iterator it = std::find_if(
- work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand);
- if (it != work_items_.end())
- return *it;
- it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady);
- if (it != work_items_.end())
- return *it;
+ if (ready_on_demand.size() > 0) {
+ return ready_on_demand[base::RandInt(0, ready_on_demand.size() - 1)];
+ }
+ if (ready.size() > 0) {
+ return ready[base::RandInt(0, ready.size() - 1)];
+ }
return NULL;
}
« 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