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 @@
#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;
}
......
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