| OLD | NEW |
| 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 Loading... |
| 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 = clock_->Now().ToJsTime(); |
| 160 predictions.push_back(std::move(prediction)); | 160 predictions.push_back(std::move(prediction)); |
| 161 | 161 |
| 162 // Starting with the soonest expiring chunks, add entries for the | 162 // Starting with the soonest expiring chunks, add entries for the |
| 163 // expiration times going forward. | 163 // expiration times going forward. |
| 164 const BudgetChunks& chunks = budget_map_[origin].chunks; | 164 const BudgetChunks& chunks = budget_map_[origin].chunks; |
| 165 for (const auto& chunk : chunks) { | 165 for (const auto& chunk : chunks) { |
| 166 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New()); | 166 blink::mojom::BudgetStatePtr prediction(blink::mojom::BudgetState::New()); |
| 167 total -= chunk.amount; | 167 total -= chunk.amount; |
| 168 prediction->budget_at = total; | 168 prediction->budget_at = total; |
| 169 prediction->time = chunk.expiration.ToDoubleT(); | 169 prediction->time = chunk.expiration.ToJsTime(); |
| 170 predictions.push_back(std::move(prediction)); | 170 predictions.push_back(std::move(prediction)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, | 173 callback.Run(blink::mojom::BudgetServiceErrorType::NONE, |
| 174 std::move(predictions)); | 174 std::move(predictions)); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void BudgetDatabase::SpendBudgetAfterSync(const url::Origin& origin, | 177 void BudgetDatabase::SpendBudgetAfterSync(const url::Origin& origin, |
| 178 double amount, | 178 double amount, |
| 179 const SpendBudgetCallback& callback, | 179 const SpendBudgetCallback& callback, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 return false; | 372 return false; |
| 373 } | 373 } |
| 374 | 374 |
| 375 double BudgetDatabase::GetSiteEngagementScoreForOrigin( | 375 double BudgetDatabase::GetSiteEngagementScoreForOrigin( |
| 376 const url::Origin& origin) const { | 376 const url::Origin& origin) const { |
| 377 if (profile_->IsOffTheRecord()) | 377 if (profile_->IsOffTheRecord()) |
| 378 return 0; | 378 return 0; |
| 379 | 379 |
| 380 return SiteEngagementService::Get(profile_)->GetScore(origin.GetURL()); | 380 return SiteEngagementService::Get(profile_)->GetScore(origin.GetURL()); |
| 381 } | 381 } |
| OLD | NEW |