| 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/push_messaging/background_budget_service.h" | 5 #include "chrome/browser/push_messaging/background_budget_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // rewards sites that don't use all their budgets every day, and a ses | 135 // rewards sites that don't use all their budgets every day, and a ses |
| 136 // component, which gives extra budget to sites that have a high ses score. | 136 // component, which gives extra budget to sites that have a high ses score. |
| 137 double budget = budget_carryover + ses_component; | 137 double budget = budget_carryover + ses_component; |
| 138 DCHECK_GE(budget, 0.0); | 138 DCHECK_GE(budget, 0.0); |
| 139 return budget; | 139 return budget; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void BackgroundBudgetService::StoreBudget(const GURL& origin, double budget) { | 142 void BackgroundBudgetService::StoreBudget(const GURL& origin, double budget) { |
| 143 DCHECK_EQ(origin, origin.GetOrigin()); | 143 DCHECK_EQ(origin, origin.GetOrigin()); |
| 144 DCHECK_GE(budget, 0.0); | 144 DCHECK_GE(budget, 0.0); |
| 145 DCHECK_LE(budget, SiteEngagementScore::kMaxPoints); | 145 DCHECK_LE(budget, SiteEngagementService::GetMaxPoints()); |
| 146 | 146 |
| 147 // Get the current SES score to write into the prefs with the new budget. | 147 // Get the current SES score to write into the prefs with the new budget. |
| 148 SiteEngagementService* service = SiteEngagementService::Get(profile_); | 148 SiteEngagementService* service = SiteEngagementService::Get(profile_); |
| 149 double ses_score = service->GetScore(origin); | 149 double ses_score = service->GetScore(origin); |
| 150 | 150 |
| 151 base::Time time = clock_->Now(); | 151 base::Time time = clock_->Now(); |
| 152 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); | 152 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Override the default clock with the specified clock. Only used for testing. | 155 // Override the default clock with the specified clock. Only used for testing. |
| 156 void BackgroundBudgetService::SetClockForTesting( | 156 void BackgroundBudgetService::SetClockForTesting( |
| 157 std::unique_ptr<base::Clock> clock) { | 157 std::unique_ptr<base::Clock> clock) { |
| 158 clock_ = std::move(clock); | 158 clock_ = std::move(clock); |
| 159 } | 159 } |
| OLD | NEW |