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

Unified Diff: content/public/browser/push_messaging_service.cc

Issue 883743002: Push API: Grace - allow one in ten pushes to show no notification. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@userdata
Patch Set: Use static methods on PushMessagingService to save state Created 5 years, 10 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: content/public/browser/push_messaging_service.cc
diff --git a/content/public/browser/push_messaging_service.cc b/content/public/browser/push_messaging_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e89b9a98c19c0c1608a858ffff1571b4707c1e00
--- /dev/null
+++ b/content/public/browser/push_messaging_service.cc
@@ -0,0 +1,91 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
Michael van Ouwerkerk 2015/02/04 15:51:33 Doing this much work in static methods seems permi
johnme 2015/02/04 17:57:41 Acknowledged. I'm doing this based on jochen/micha
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/browser/push_messaging_service.h"
+
+#include "content/browser/service_worker/service_worker_context_wrapper.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace content {
+
+static const char kNotificationsShownServiceWorkerKey[] =
+ "notifications_shown_by_last_few_pushes";
+
+static void CallGetNotificationsShownCallbackFromIO(
+ const PushMessagingService::GetNotificationsShownCallback& callback,
+ const std::string& data,
+ ServiceWorkerStatusCode service_worker_status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ bool success = service_worker_status == SERVICE_WORKER_OK;
+ bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND;
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, data, success, not_found));
+}
+
+static void CallResultCallbackFromIO(
+ const ServiceWorkerContext::ResultCallback& callback,
+ ServiceWorkerStatusCode service_worker_status) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ bool success = service_worker_status == SERVICE_WORKER_OK;
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(callback, success));
+}
+
+static void GetNotificationsShownOnIO(
+ ServiceWorkerContextWrapper* service_worker_context_wrapper,
Michael van Ouwerkerk 2015/02/04 15:51:33 Shouldn't this be a scoped_refptr? Otherwise this
johnme 2015/02/04 17:57:41 Done (yeah, I deliberately used scoped_refptr<Serv
+ int64 service_worker_registration_id,
+ const PushMessagingService::GetNotificationsShownCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ service_worker_context_wrapper->context()->storage()->GetUserData(
+ service_worker_registration_id, kNotificationsShownServiceWorkerKey,
+ base::Bind(&CallGetNotificationsShownCallbackFromIO, callback));
+}
+
+static void SetNotificationsShownOnIO(
+ ServiceWorkerContextWrapper* service_worker_context_wrapper,
Michael van Ouwerkerk 2015/02/04 15:51:33 Ditto.
johnme 2015/02/04 17:57:41 Done.
+ int64 service_worker_registration_id, const GURL& origin,
+ const std::string& data,
+ const PushMessagingService::ResultCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ service_worker_context_wrapper->context()->storage()->StoreUserData(
+ service_worker_registration_id, origin,
+ kNotificationsShownServiceWorkerKey, data,
+ base::Bind(&CallResultCallbackFromIO, callback));
+}
+
+// static
+void PushMessagingService::GetNotificationsShownByLastFewPushes(
+ ServiceWorkerContext* service_worker_context,
+ int64 service_worker_registration_id,
+ const GetNotificationsShownCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ scoped_refptr<ServiceWorkerContextWrapper> wrapper =
+ static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&GetNotificationsShownOnIO,
+ wrapper,
+ service_worker_registration_id,
+ callback));
+}
+
+// static
+void PushMessagingService::SetNotificationsShownByLastFewPushes(
+ ServiceWorkerContext* service_worker_context,
+ int64 service_worker_registration_id,
+ const GURL& origin,
+ const std::string& notifications_shown,
+ const ResultCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ scoped_refptr<ServiceWorkerContextWrapper> wrapper =
+ static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&SetNotificationsShownOnIO,
+ wrapper,
+ service_worker_registration_id,
+ origin,
+ notifications_shown,
+ callback));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698