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

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: Code review comments integrated 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
« no previous file with comments | « no previous file | chrome/browser/push_messaging/background_budget_service_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8afa9d26f24af12961c521d5559a435460a70d1b 100644
--- a/chrome/browser/push_messaging/background_budget_service.cc
+++ b/chrome/browser/push_messaging/background_budget_service.cc
@@ -129,6 +129,14 @@ 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.
+ // TODO(harkness): Consider what to do if the clock jumps forward by a
+ // significant amount.
+ if (elapsed.InMicroseconds() < 0)
+ 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.
« no previous file with comments | « no previous file | chrome/browser/push_messaging/background_budget_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698