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_manager.h" | 5 #include "chrome/browser/budget_service/budget_manager.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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 void BudgetManager::RegisterProfilePrefs( | 100 void BudgetManager::RegisterProfilePrefs( |
101 user_prefs::PrefRegistrySyncable* registry) { | 101 user_prefs::PrefRegistrySyncable* registry) { |
102 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); | 102 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); |
103 } | 103 } |
104 | 104 |
105 // static | 105 // static |
106 double BudgetManager::GetCost(blink::mojom::BudgetOperationType type) { | 106 double BudgetManager::GetCost(blink::mojom::BudgetOperationType type) { |
107 switch (type) { | 107 switch (type) { |
108 case blink::mojom::BudgetOperationType::SILENT_PUSH: | 108 case blink::mojom::BudgetOperationType::SILENT_PUSH: |
109 return 2.0; | 109 return 2.0; |
| 110 case blink::mojom::BudgetOperationType::INVALID_OPERATION: |
| 111 return SiteEngagementScore::kMaxPoints + 1; |
110 // No default case. | 112 // No default case. |
111 } | 113 } |
112 NOTREACHED(); | 114 NOTREACHED(); |
113 return SiteEngagementScore::kMaxPoints + 1.0; | 115 return SiteEngagementScore::kMaxPoints + 1.0; |
114 } | 116 } |
115 | 117 |
116 void BudgetManager::GetBudget(const GURL& origin, | 118 void BudgetManager::GetBudget(const GURL& origin, |
117 const GetBudgetCallback& callback) { | 119 const GetBudgetCallback& callback) { |
118 DCHECK_EQ(origin, origin.GetOrigin()); | 120 DCHECK_EQ(origin, origin.GetOrigin()); |
119 | 121 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 base::Time time = clock_->Now(); | 189 base::Time time = clock_->Now(); |
188 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); | 190 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); |
189 | 191 |
190 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(closure)); | 192 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(closure)); |
191 } | 193 } |
192 | 194 |
193 // Override the default clock with the specified clock. Only used for testing. | 195 // Override the default clock with the specified clock. Only used for testing. |
194 void BudgetManager::SetClockForTesting(std::unique_ptr<base::Clock> clock) { | 196 void BudgetManager::SetClockForTesting(std::unique_ptr<base::Clock> clock) { |
195 clock_ = std::move(clock); | 197 clock_ = std::move(clock); |
196 } | 198 } |
OLD | NEW |