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