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

Side by Side 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: Fix typo (invesed needed but not shown logic) 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 unified diff | Download patch
« no previous file with comments | « content/public/browser/push_messaging_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "content/public/browser/push_messaging_service.h"
6
7 #include "content/browser/service_worker/service_worker_context_wrapper.h"
8 #include "content/public/browser/browser_thread.h"
9
10 namespace {
11
12 const char kNotificationsShownServiceWorkerKey[] =
13 "notifications_shown_by_last_few_pushes";
14
15 } // namespace
16
17 namespace content {
18
19 static void CallGetNotificationsShownCallbackFromIO(
20 const PushMessagingService::GetNotificationsShownCallback& callback,
21 const std::string& data,
22 ServiceWorkerStatusCode service_worker_status) {
23 DCHECK_CURRENTLY_ON(BrowserThread::IO);
24 bool success = service_worker_status == SERVICE_WORKER_OK;
25 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND;
26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
27 base::Bind(callback, data, success, not_found));
28 }
29
30 static void CallResultCallbackFromIO(
31 const ServiceWorkerContext::ResultCallback& callback,
32 ServiceWorkerStatusCode service_worker_status) {
33 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34 bool success = service_worker_status == SERVICE_WORKER_OK;
35 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
36 base::Bind(callback, success));
37 }
38
39 static void GetNotificationsShownOnIO(
40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
41 int64 service_worker_registration_id,
42 const PushMessagingService::GetNotificationsShownCallback& callback) {
43 DCHECK_CURRENTLY_ON(BrowserThread::IO);
44 service_worker_context_wrapper->context()->storage()->GetUserData(
45 service_worker_registration_id, kNotificationsShownServiceWorkerKey,
46 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback));
47 }
48
49 static void SetNotificationsShownOnIO(
50 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
51 int64 service_worker_registration_id, const GURL& origin,
52 const std::string& data,
53 const PushMessagingService::ResultCallback& callback) {
54 DCHECK_CURRENTLY_ON(BrowserThread::IO);
55 service_worker_context_wrapper->context()->storage()->StoreUserData(
56 service_worker_registration_id, origin,
57 kNotificationsShownServiceWorkerKey, data,
58 base::Bind(&CallResultCallbackFromIO, callback));
59 }
60
61 // static
62 void PushMessagingService::GetNotificationsShownByLastFewPushes(
63 ServiceWorkerContext* service_worker_context,
64 int64 service_worker_registration_id,
65 const GetNotificationsShownCallback& callback) {
66 DCHECK_CURRENTLY_ON(BrowserThread::UI);
67 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
68 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
69 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
70 base::Bind(&GetNotificationsShownOnIO,
71 wrapper,
72 service_worker_registration_id,
73 callback));
74 }
75
76 // static
77 void PushMessagingService::SetNotificationsShownByLastFewPushes(
78 ServiceWorkerContext* service_worker_context,
79 int64 service_worker_registration_id,
80 const GURL& origin,
81 const std::string& notifications_shown,
82 const ResultCallback& callback) {
83 DCHECK_CURRENTLY_ON(BrowserThread::UI);
84 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
85 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
86 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
87 base::Bind(&SetNotificationsShownOnIO,
88 wrapper,
89 service_worker_registration_id,
90 origin,
91 notifications_shown,
92 callback));
93 }
94
95 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/push_messaging_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698