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

Unified 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: dcheck ordering 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 side-by-side diff with in-line comments
Download patch
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..ef24a41a0ab4d659755f7f6ee30b635cff68b2f5
--- /dev/null
+++ b/chrome/browser/push_messaging/background_budget_service.cc
@@ -0,0 +1,48 @@
+// 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 "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
+std::string BackgroundBudgetService::GetBudget(Profile* profile,
+ const GURL& origin) {
+ return GetBudgetStringForOrigin(profile, origin);
+}
+
+// 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);
+}

Powered by Google App Engine
This is Rietveld 408576698