Commit 57066f04 authored by bartekn@chromium.org's avatar bartekn@chromium.org

Randomize order in which ready component updates are applied. On demand...

Randomize order in which ready component updates are applied. On demand updates still take precedence.

BUG=343686

Review URL: https://codereview.chromium.org/144523004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255832 0039d316-1c4b-4281-b951-d872f2087c98
parent d10cee16
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/rand_util.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/threading/sequenced_worker_pool.h"
...@@ -574,23 +575,26 @@ void CrxUpdateService::ProcessPendingItems() { ...@@ -574,23 +575,26 @@ void CrxUpdateService::ProcessPendingItems() {
} }
CrxUpdateItem* CrxUpdateService::FindReadyComponent() const { CrxUpdateItem* CrxUpdateService::FindReadyComponent() const {
class Helper { std::vector<CrxUpdateItem*> ready;
public: std::vector<CrxUpdateItem*> ready_on_demand;
static bool IsReadyOnDemand(CrxUpdateItem* item) { for (std::vector<CrxUpdateItem*>::const_iterator it = work_items_.begin();
return item->on_demand && IsReady(item); it != work_items_.end();
} ++it) {
static bool IsReady(CrxUpdateItem* item) { CrxUpdateItem* item = *it;
return item->status == CrxUpdateItem::kCanUpdate; 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( if (ready_on_demand.size() > 0) {
work_items_.begin(), work_items_.end(), Helper::IsReadyOnDemand); return ready_on_demand[base::RandInt(0, ready_on_demand.size() - 1)];
if (it != work_items_.end()) }
return *it; if (ready.size() > 0) {
it = std::find_if(work_items_.begin(), work_items_.end(), Helper::IsReady); return ready[base::RandInt(0, ready.size() - 1)];
if (it != work_items_.end()) }
return *it;
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment