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..4ede1c980e57c86e95b22eec0002163ec27ce05d |
| --- /dev/null |
| +++ b/chrome/browser/push_messaging/background_budget_service.cc |
| @@ -0,0 +1,59 @@ |
| +// 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" |
| +#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 chrome { |
|
Peter Beverloo
2016/04/08 10:41:10
Please don't put things in the chrome namespace.
harkness
2016/04/08 14:11:43
Done.
|
| + |
| +namespace { |
| + |
| +std::string GetBudgetStringForServiceWorker(Profile* profile, |
|
Peter Beverloo
2016/04/08 10:41:10
nit (1): s/ForServiceWorker/ForOrigin/
nit (2): Al
harkness
2016/04/08 14:11:43
Done.
|
| + const GURL& origin) { |
| + const base::DictionaryValue* map = |
| + profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap); |
| + |
| + std::string map_value; |
| + map->GetStringWithoutPathExpansion(origin.spec(), &map_value); |
|
Peter Beverloo
2016/04/08 10:41:10
What happens when |origin| is not an origin, but a
harkness
2016/04/08 14:11:43
Done.
|
| + return map_value; |
| +} |
| +} // namespace |
|
Peter Beverloo
2016/04/08 10:41:10
micro nit: blank line above this one
harkness
2016/04/08 14:11:43
Done.
|
| + |
| +// static |
| +void BackgroundBudgetService::RegisterProfilePrefs( |
| + user_prefs::PrefRegistrySyncable* registry) { |
| + registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap); |
| +} |
| + |
| +// static |
| +void BackgroundBudgetService::GetBudget(Profile* profile, |
| + const GURL& origin, |
| + const StringCallback& callback) { |
| + // Temporarily, this is just moving the old grace period code into the new |
| + // service. |
|
Peter Beverloo
2016/04/08 10:41:11
micro nit: This comment doesn't add much value. Wo
harkness
2016/04/08 14:11:43
I just removed it.
|
| + const std::string map_value = |
| + GetBudgetStringForServiceWorker(profile, origin); |
| + |
| + callback.Run(map_value); |
|
Peter Beverloo
2016/04/08 10:41:10
Do you expect this to be asynchronous in the futur
harkness
2016/04/08 14:11:43
I did a bit of investigation into the prefs storag
Peter Beverloo
2016/04/08 14:29:38
It's not about whether you're on the same thread o
|
| +} |
| + |
| +// static |
| +void BackgroundBudgetService::StoreBudget( |
| + Profile* profile, |
| + const GURL& origin, |
| + const std::string& notifications_shown, |
| + const BudgetCallback& callback) { |
| + DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap); |
| + base::DictionaryValue* map = update.Get(); |
| + map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown); |
| +} |
| + |
| +} // namespace chrome |