Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/push_messaging/background_budget_service.cc

Issue 1861683002: Background service worker push message processing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Integrated code review comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/strings/string_number_conversions.h"
Peter Beverloo 2016/04/08 14:29:38 nit: unused
harkness 2016/04/11 09:37:37 Done.
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "components/prefs/pref_service.h"
13 #include "components/prefs/scoped_user_pref_update.h"
14
15 namespace {
16
17 std::string GetBudgetStringForOrigin(Profile* profile, const GURL& origin) {
18 DCHECK_EQ(origin.GetOrigin(), origin);
19 const base::DictionaryValue* map =
20 profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap);
21
22 std::string map_string;
23 map->GetStringWithoutPathExpansion(origin.spec(), &map_string);
24 return map_string;
25 }
26
27 } // namespace
28
29 // static
30 void BackgroundBudgetService::RegisterProfilePrefs(
31 user_prefs::PrefRegistrySyncable* registry) {
32 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap);
33 }
34
35 // static
36 void BackgroundBudgetService::GetBudget(Profile* profile,
37 const GURL& origin,
38 const BudgetCallback& callback) {
39 const std::string map_string = GetBudgetStringForOrigin(profile, origin);
40
41 callback.Run(map_string);
42 }
43
44 // static
45 void BackgroundBudgetService::StoreBudget(
46 Profile* profile,
47 const GURL& origin,
48 const std::string& notifications_shown) {
49 DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap);
50 base::DictionaryValue* map = update.Get();
51 map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown);
52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698