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

Side by Side Diff: chrome/browser/budget_service/budget_database.cc

Issue 2922203002: Always use milliseconds in the Budget API implementation (Closed)
Patch Set: missing file? Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/budget_service/budget_database_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/budget_service/budget_database.h" 5 #include "chrome/browser/budget_service/budget_database.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/task_scheduler/post_task.h" 9 #include "base/task_scheduler/post_task.h"
10 #include "base/time/clock.h" 10 #include "base/time/clock.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 // Now, build up the BudgetExpection. This is different from the format 150 // Now, build up the BudgetExpection. This is different from the format
151 // in which the cache stores the data. The cache stores chunks of budget and 151 // in which the cache stores the data. The cache stores chunks of budget and
152 // when that budget expires. The mojo array describes a set of times 152 // when that budget expires. The mojo array describes a set of times
153 // and the budget at those times. 153 // and the budget at those times.
154 double total = GetBudget(origin); 154 double total = GetBudget(origin);
155 155
156 // Always add one entry at the front of the list for the total budget now. 156 // Always add one entry at the front of the list for the total budget now.
157 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New()); 157 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New());
158 prediction->budget_at = total; 158 prediction->budget_at = total;
159 prediction->time = clock_->Now().ToDoubleT(); 159 prediction->time =
160 clock_->Now().ToDoubleT() * base::Time::kMillisecondsPerSecond;
Miguel Garcia 2017/06/05 18:47:10 Why not simply clock_->Now().InMilliseconds() (or
Peter Beverloo 2017/06/05 19:01:24 Used ToJsTime() so that we get the epoch - thanks!
160 predictions.push_back(std::move(prediction)); 161 predictions.push_back(std::move(prediction));
161 162
162 // Starting with the soonest expiring chunks, add entries for the 163 // Starting with the soonest expiring chunks, add entries for the
163 // expiration times going forward. 164 // expiration times going forward.
164 const BudgetChunks& chunks = budget_map_[origin].chunks; 165 const BudgetChunks& chunks = budget_map_[origin].chunks;
165 for (const auto& chunk : chunks) { 166 for (const auto& chunk : chunks) {
166 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New()); 167 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New());
167 total -= chunk.amount; 168 total -= chunk.amount;
168 prediction->budget_at = total; 169 prediction->budget_at = total;
169 prediction->time = chunk.expiration.ToDoubleT(); 170 prediction->time =
171 chunk.expiration.ToDoubleT() * base::Time::kMillisecondsPerSecond;
170 predictions.push_back(std::move(prediction)); 172 predictions.push_back(std::move(prediction));
171 } 173 }
172 174
173 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, 175 callback.Run(blink::mojom::BudgetServiceErrorType::NONE,
174 std::move(predictions)); 176 std::move(predictions));
175 } 177 }
176 178
177 void BudgetDatabase::SpendBudgetAfterSync(const url::Origin& origin, 179 void BudgetDatabase::SpendBudgetAfterSync(const url::Origin& origin,
178 double amount, 180 double amount,
179 const SpendBudgetCallback& callback, 181 const SpendBudgetCallback& callback,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return false; 374 return false;
373 } 375 }
374 376
375 double BudgetDatabase::GetSiteEngagementScoreForOrigin( 377 double BudgetDatabase::GetSiteEngagementScoreForOrigin(
376 const url::Origin& origin) const { 378 const url::Origin& origin) const {
377 if (profile_->IsOffTheRecord()) 379 if (profile_->IsOffTheRecord())
378 return 0; 380 return 0;
379 381
380 return SiteEngagementService::Get(profile_)->GetScore(origin.GetURL()); 382 return SiteEngagementService::Get(profile_)->GetScore(origin.GetURL());
381 } 383 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/budget_service/budget_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698