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

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: 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..b4ae9f3138d889c8a0be8fa4f0dcd274043d216e
--- /dev/null
+++ b/chrome/browser/push_messaging/background_budget_service.cc
@@ -0,0 +1,65 @@
+// 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 {
+
+namespace {
+
+std::string GetBudgetStringForServiceWorker(
+ Profile* profile,
+ const int64_t service_worker_registration_id) {
+ const base::DictionaryValue* map =
+ profile->GetPrefs()->GetDictionary(prefs::kBackgroundBudgetMap);
+ const std::string worker_id_string =
+ base::Int64ToString(service_worker_registration_id);
+
+ std::string map_value;
+ map->GetStringWithoutPathExpansion(worker_id_string, &map_value);
+ return map_value;
+}
+} // namespace
+
+// static
+void BackgroundBudgetService::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterDictionaryPref(prefs::kBackgroundBudgetMap);
+}
+
+// static
+void BackgroundBudgetService::GetBudget(Profile* profile,
+ int64_t service_worker_registration_id,
+ const StringCallback& callback) {
+ // Temporarily, this is just moving the old grace period code into the new
+ // service.
+ const std::string map_value =
+ GetBudgetStringForServiceWorker(profile, service_worker_registration_id);
+
+ callback.Run(map_value);
+}
+
+// static
+void BackgroundBudgetService::StoreBudget(
+ Profile* profile,
+ int64_t service_worker_registration_id,
+ const GURL& origin,
+ const std::string& notifications_shown,
+ const BudgetCallback& callback) {
+ DictionaryPrefUpdate update(profile->GetPrefs(), prefs::kBackgroundBudgetMap);
+ base::DictionaryValue* map = update.Get();
+ const std::string worker_id_string =
+ base::Int64ToString(service_worker_registration_id);
+ map->SetStringWithoutPathExpansion(worker_id_string, notifications_shown);
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698