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

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: Switched the key to origin and added tests. 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"
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 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.
16
17 namespace {
18
19 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.
20 const GURL& origin) {
21 const base::DictionaryValue* map =
22 profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap);
23
24 std::string map_value;
25 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.
26 return map_value;
27 }
28 } // namespace
Peter Beverloo 2016/04/08 10:41:10 micro nit: blank line above this one
harkness 2016/04/08 14:11:43 Done.
29
30 // static
31 void BackgroundBudgetService::RegisterProfilePrefs(
32 user_prefs::PrefRegistrySyncable* registry) {
33 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap);
34 }
35
36 // static
37 void BackgroundBudgetService::GetBudget(Profile* profile,
38 const GURL& origin,
39 const StringCallback& callback) {
40 // Temporarily, this is just moving the old grace period code into the new
41 // 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.
42 const std::string map_value =
43 GetBudgetStringForServiceWorker(profile, origin);
44
45 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
46 }
47
48 // static
49 void BackgroundBudgetService::StoreBudget(
50 Profile* profile,
51 const GURL& origin,
52 const std::string& notifications_shown,
53 const BudgetCallback& callback) {
54 DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap);
55 base::DictionaryValue* map = update.Get();
56 map->SetStringWithoutPathExpansion(origin.spec(), notifications_shown);
57 }
58
59 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698