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

Unified Diff: components/update_client/action.cc

Issue 2149283003: Adaptive delay between successive component updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use TimeTicks Created 4 years, 5 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 | components/update_client/crx_update_item.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/update_client/action.cc
diff --git a/components/update_client/action.cc b/components/update_client/action.cc
index c550b2f1c60a08529fcfad72b9bf4c17e37bd491..aa75f66cb4436bb99a6f52d827f6016271db3a73 100644
--- a/components/update_client/action.cc
+++ b/components/update_client/action.cc
@@ -5,6 +5,8 @@
#include "components/update_client/action.h"
#include <algorithm>
+#include <memory>
+
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
@@ -123,6 +125,8 @@ void ActionImpl::UpdateCrx() {
CrxUpdateItem* item = FindUpdateItemById(id);
DCHECK(item);
+ item->update_begin = base::TimeTicks::Now();
+
std::unique_ptr<Action> update_action(
CanTryDiffUpdate(item, update_context_->config)
? ActionUpdateDiff::Create()
@@ -136,6 +140,9 @@ void ActionImpl::UpdateCrx() {
}
void ActionImpl::UpdateCrxComplete(CrxUpdateItem* item) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(item);
+
update_context_->ping_manager->SendPing(item);
update_context_->queue.pop();
@@ -143,12 +150,19 @@ void ActionImpl::UpdateCrxComplete(CrxUpdateItem* item) {
if (update_context_->queue.empty()) {
UpdateComplete(0);
} else {
- // TODO(sorin): the value of timing interval between CRX updates might have
- // to be injected at the call site of update_client::UpdateClient::Update.
- const int wait_sec = update_context_->config->UpdateDelay();
+ DCHECK(!item->update_begin.is_null());
+
+ // Assume that the cost of applying the update is proportional with how
+ // long it took to apply it. Then delay the next update by the same time
+ // interval or the value provided by the configurator, whichever is less.
+ const base::TimeDelta max_update_delay =
+ base::TimeDelta::FromSeconds(update_context_->config->UpdateDelay());
+ const base::TimeDelta update_cost(base::TimeTicks::Now() -
+ item->update_begin);
+ DCHECK(update_cost >= base::TimeDelta());
std::unique_ptr<ActionWait> action_wait(
- new ActionWait(base::TimeDelta::FromSeconds(wait_sec)));
+ new ActionWait(std::min(update_cost, max_update_delay)));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&Action::Run, base::Unretained(action_wait.get()),
« no previous file with comments | « no previous file | components/update_client/crx_update_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698