| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "components/pref_registry/pref_registry_syncable.h" | 10 #include "components/pref_registry/pref_registry_syncable.h" |
| 11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
| 12 #include "components/prefs/scoped_user_pref_update.h" | 12 #include "components/prefs/scoped_user_pref_update.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 std::string GetBudgetStringForOrigin(Profile* profile, const GURL& origin) { | 16 std::string GetBudgetStringForOrigin(Profile* profile, const GURL& origin) { |
| 17 DCHECK_EQ(origin.GetOrigin(), origin); | 17 DCHECK_EQ(origin.GetOrigin(), origin); |
| 18 const base::DictionaryValue* map = | 18 const base::DictionaryValue* map = |
| 19 profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap); | 19 profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap); |
| 20 | 20 |
| 21 std::string map_string; | 21 std::string map_string; |
| 22 map->GetStringWithoutPathExpansion(origin.spec(), &map_string); | 22 map->GetStringWithoutPathExpansion(origin.spec(), &map_string); |
| 23 return map_string; | 23 return map_string; |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 BackgroundBudgetService::BackgroundBudgetService(Profile* profile) |
| 29 : profile_(profile) { |
| 30 DCHECK(profile); |
| 31 } |
| 32 |
| 28 // static | 33 // static |
| 29 void BackgroundBudgetService::RegisterProfilePrefs( | 34 void BackgroundBudgetService::RegisterProfilePrefs( |
| 30 user_prefs::PrefRegistrySyncable* registry) { | 35 user_prefs::PrefRegistrySyncable* registry) { |
| 31 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); | 36 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); |
| 32 } | 37 } |
| 33 | 38 |
| 34 // static | 39 std::string BackgroundBudgetService::GetBudget(const GURL& origin) { |
| 35 std::string BackgroundBudgetService::GetBudget(Profile* profile, | 40 return GetBudgetStringForOrigin(profile_, origin); |
| 36 const GURL& origin) { | |
| 37 return GetBudgetStringForOrigin(profile, origin); | |
| 38 } | 41 } |
| 39 | 42 |
| 40 // static | |
| 41 void BackgroundBudgetService::StoreBudget( | 43 void BackgroundBudgetService::StoreBudget( |
| 42 Profile* profile, | |
| 43 const GURL& origin, | 44 const GURL& origin, |
| 44 const std::string& notifications_shown) { | 45 const std::string& notifications_shown) { |
| 45 DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap); | 46 DictionaryPrefUpdate update(profile_->GetPrefs(), |
| 47 prefs::kBackgroundBudgetMap); |
| 46 base::DictionaryValue* map = update.Get(); | 48 base::DictionaryValue* map = update.Get(); |
| 47 map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown); | 49 map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown); |
| 48 } | 50 } |
| OLD | NEW |