| 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" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
| 16 #include "base/time/default_clock.h" | 16 #include "base/time/default_clock.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "chrome/browser/engagement/site_engagement_score.h" | 18 #include "chrome/browser/engagement/site_engagement_score.h" |
| 19 #include "chrome/browser/engagement/site_engagement_service.h" | 19 #include "chrome/browser/engagement/site_engagement_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 22 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
| 23 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 24 #include "components/prefs/scoped_user_pref_update.h" | 24 #include "components/prefs/scoped_user_pref_update.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "third_party/WebKit/public/platform/modules/budget_service/budget_servi
ce.mojom.h" |
| 26 | 27 |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 constexpr char kSeparator = '#'; | 32 constexpr char kSeparator = '#'; |
| 32 | 33 |
| 33 // Calculate the ratio of the different components of a budget with respect | 34 // Calculate the ratio of the different components of a budget with respect |
| 34 // to a maximum time period of 10 days = 864000.0 seconds. | 35 // to a maximum time period of 10 days = 864000.0 seconds. |
| 35 constexpr double kSecondsToAccumulate = 864000.0; | 36 constexpr double kSecondsToAccumulate = 864000.0; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 96 |
| 96 BudgetManager::~BudgetManager() {} | 97 BudgetManager::~BudgetManager() {} |
| 97 | 98 |
| 98 // static | 99 // static |
| 99 void BudgetManager::RegisterProfilePrefs( | 100 void BudgetManager::RegisterProfilePrefs( |
| 100 user_prefs::PrefRegistrySyncable* registry) { | 101 user_prefs::PrefRegistrySyncable* registry) { |
| 101 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); | 102 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); |
| 102 } | 103 } |
| 103 | 104 |
| 104 // static | 105 // static |
| 105 double BudgetManager::GetCost(CostType type) { | 106 double BudgetManager::GetCost(blink::mojom::BudgetOperationType type) { |
| 106 switch (type) { | 107 switch (type) { |
| 107 case CostType::SILENT_PUSH: | 108 case blink::mojom::BudgetOperationType::SILENT_PUSH: |
| 108 return 2.0; | 109 return 2.0; |
| 109 // No default case. | 110 // No default case. |
| 110 } | 111 } |
| 111 NOTREACHED(); | 112 NOTREACHED(); |
| 112 return SiteEngagementScore::kMaxPoints + 1.0; | 113 return SiteEngagementScore::kMaxPoints + 1.0; |
| 113 } | 114 } |
| 114 | 115 |
| 115 void BudgetManager::GetBudget(const GURL& origin, | 116 void BudgetManager::GetBudget(const GURL& origin, |
| 116 const GetBudgetCallback& callback) { | 117 const GetBudgetCallback& callback) { |
| 117 DCHECK_EQ(origin, origin.GetOrigin()); | 118 DCHECK_EQ(origin, origin.GetOrigin()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 base::Time time = clock_->Now(); | 187 base::Time time = clock_->Now(); |
| 187 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); | 188 SetBudgetDataInPrefs(profile_, origin, time.ToDoubleT(), budget, ses_score); |
| 188 | 189 |
| 189 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(closure)); | 190 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(closure)); |
| 190 } | 191 } |
| 191 | 192 |
| 192 // Override the default clock with the specified clock. Only used for testing. | 193 // Override the default clock with the specified clock. Only used for testing. |
| 193 void BudgetManager::SetClockForTesting(std::unique_ptr<base::Clock> clock) { | 194 void BudgetManager::SetClockForTesting(std::unique_ptr<base::Clock> clock) { |
| 194 clock_ = std::move(clock); | 195 clock_ = std::move(clock); |
| 195 } | 196 } |
| OLD | NEW |