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

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: Address review comments (e.g. use bitset) 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 content {
11
12 static const char kNotificationsShownServiceWorkerKey[] =
Avi (use Gerrit) 2015/02/04 21:24:22 Don't use static in this way; use an anonymous nam
johnme 2015/02/05 11:34:26 Done.
13 "notifications_shown_by_last_few_pushes";
14
15 static void CallGetNotificationsShownCallbackFromIO(
16 const PushMessagingService::GetNotificationsShownCallback& callback,
17 const std::string& data,
18 ServiceWorkerStatusCode service_worker_status) {
19 DCHECK_CURRENTLY_ON(BrowserThread::IO);
20 bool success = service_worker_status == SERVICE_WORKER_OK;
21 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND;
22 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
23 base::Bind(callback, data, success, not_found));
24 }
25
26 static void CallResultCallbackFromIO(
27 const ServiceWorkerContext::ResultCallback& callback,
28 ServiceWorkerStatusCode service_worker_status) {
29 DCHECK_CURRENTLY_ON(BrowserThread::IO);
30 bool success = service_worker_status == SERVICE_WORKER_OK;
31 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
32 base::Bind(callback, success));
33 }
34
35 static void GetNotificationsShownOnIO(
36 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
37 int64 service_worker_registration_id,
38 const PushMessagingService::GetNotificationsShownCallback& callback) {
39 DCHECK_CURRENTLY_ON(BrowserThread::IO);
40 service_worker_context_wrapper->context()->storage()->GetUserData(
41 service_worker_registration_id, kNotificationsShownServiceWorkerKey,
42 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback));
43 }
44
45 static void SetNotificationsShownOnIO(
46 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
47 int64 service_worker_registration_id, const GURL& origin,
48 const std::string& data,
49 const PushMessagingService::ResultCallback& callback) {
50 DCHECK_CURRENTLY_ON(BrowserThread::IO);
51 service_worker_context_wrapper->context()->storage()->StoreUserData(
52 service_worker_registration_id, origin,
53 kNotificationsShownServiceWorkerKey, data,
54 base::Bind(&CallResultCallbackFromIO, callback));
55 }
56
57 // static
58 void PushMessagingService::GetNotificationsShownByLastFewPushes(
59 ServiceWorkerContext* service_worker_context,
60 int64 service_worker_registration_id,
61 const GetNotificationsShownCallback& callback) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
64 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
65 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
66 base::Bind(&GetNotificationsShownOnIO,
67 wrapper,
68 service_worker_registration_id,
69 callback));
70 }
71
72 // static
73 void PushMessagingService::SetNotificationsShownByLastFewPushes(
74 ServiceWorkerContext* service_worker_context,
75 int64 service_worker_registration_id,
76 const GURL& origin,
77 const std::string& notifications_shown,
78 const ResultCallback& callback) {
79 DCHECK_CURRENTLY_ON(BrowserThread::UI);
80 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
81 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
82 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
83 base::Bind(&SetNotificationsShownOnIO,
84 wrapper,
85 service_worker_registration_id,
86 origin,
87 notifications_shown,
88 callback));
89 }
90
91 } // 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