Chromium Code Reviews| Index: chrome/browser/push_messaging/background_budget_service.cc |
| diff --git a/chrome/browser/push_messaging/background_budget_service.cc b/chrome/browser/push_messaging/background_budget_service.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47615ab46b0261223f88abd249658fd4324a488e |
| --- /dev/null |
| +++ b/chrome/browser/push_messaging/background_budget_service.cc |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/push_messaging/background_budget_service.h" |
| + |
| +#include "base/callback.h" |
| +#include "base/strings/string_number_conversions.h" |
|
Peter Beverloo
2016/04/08 14:29:38
nit: unused
harkness
2016/04/11 09:37:37
Done.
|
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/prefs/scoped_user_pref_update.h" |
| + |
| +namespace { |
| + |
| +std::string GetBudgetStringForOrigin(Profile* profile, const GURL& origin) { |
| + DCHECK_EQ(origin.GetOrigin(), origin); |
| + const base::DictionaryValue* map = |
| + profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap); |
| + |
| + std::string map_string; |
| + map->GetStringWithoutPathExpansion(origin.spec(), &map_string); |
| + return map_string; |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +void BackgroundBudgetService::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); |
| +} |
| + |
| +// static |
| +void BackgroundBudgetService::GetBudget(Profile* profile, |
| + const GURL& origin, |
| + const BudgetCallback& callback) { |
| + const std::string map_string = GetBudgetStringForOrigin(profile, origin); |
| + |
| + callback.Run(map_string); |
| +} |
| + |
| +// static |
| +void BackgroundBudgetService::StoreBudget( |
| + Profile* profile, |
| + const GURL& origin, |
| + const std::string& notifications_shown) { |
| + DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap); |
| + base::DictionaryValue* map = update.Get(); |
| + map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown); |
| +} |