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

Unified Diff: chrome/browser/push_messaging/background_budget_service.cc

Issue 2020263002: Added code to make sure that the budget service does sane things if the clock rolls backwards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
Index: chrome/browser/push_messaging/background_budget_service.cc
diff --git a/chrome/browser/push_messaging/background_budget_service.cc b/chrome/browser/push_messaging/background_budget_service.cc
index cbcb169f211be16066eabddf007ed853b0cfcae3..8589cd510c1f9a9bd0ff4be1689425c23922c1c1 100644
--- a/chrome/browser/push_messaging/background_budget_service.cc
+++ b/chrome/browser/push_messaging/background_budget_service.cc
@@ -129,6 +129,12 @@ double BackgroundBudgetService::GetBudget(const GURL& origin) {
base::Time now = clock_->Now();
base::TimeDelta elapsed = now - base::Time::FromDoubleT(last_updated_msec);
+ // The user can set their clock backwards, so if the last updated time is in
+ // the future, don't update the budget based on elapsed time. Eventually the
+ // clock will reach the future, and the budget calculations will catch up.
+ if (elapsed.InMicroseconds() < 0)
johnme 2016/06/01 18:24:38 Conversely, the clock may jump forwards a lot, e.g
harkness 2016/06/02 10:06:34 Done.
+ return old_budget;
+
// For each time period that elapses, calculate the carryover ratio as the
// ratio of time remaining in our max period to the total period.
// The carryover component is then the old budget multiplied by the ratio.

Powered by Google App Engine
This is Rietveld 408576698