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

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: 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 {
16
17 namespace {
18
19 std::string GetBudgetStringForServiceWorker(
20 Profile* profile,
21 const int64_t service_worker_registration_id) {
22 const base::DictionaryValue* map =
23 profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap);
24 const std::string worker_id_string =
25 base::Int64ToString(service_worker_registration_id);
26
27 std::string map_value;
28 map->GetStringWithoutPathExpansion(worker_id_string, &map_value);
29 return map_value;
30 }
31 } // namespace
32
33 // static
34 void BackgroundBudgetService::RegisterProfilePrefs(
35 user_prefs::PrefRegistrySyncable* registry) {
36 registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap);
37 }
38
39 // static
40 void BackgroundBudgetService::GetBudget(Profile* profile,
41 int64_t service_worker_registration_id,
42 const StringCallback& callback) {
43 // Temporarily, this is just moving the old grace period code into the new
44 // service.
45 const std::string map_value =
46 GetBudgetStringForServiceWorker(profile, service_worker_registration_id);
47
48 callback.Run(map_value);
49 }
50
51 // static
52 void BackgroundBudgetService::StoreBudget(
53 Profile* profile,
54 int64_t service_worker_registration_id,
55 const GURL& origin,
56 const std::string& notifications_shown,
57 const BudgetCallback& callback) {
58 DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap);
59 base::DictionaryValue* map = update.Get();
60 const std::string worker_id_string =
61 base::Int64ToString(service_worker_registration_id);
62 map->SetStringWithoutPathExpansion(worker_id_string, notifications_shown);
63 }
64
65 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698