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

Side by Side Diff: content/public/browser/push_messaging_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 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/public/browser/push_messaging_service.h" 5 #include "content/public/browser/push_messaging_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "content/browser/push_messaging/push_messaging_message_filter.h" 8 #include "content/browser/push_messaging/push_messaging_message_filter.h"
9 #include "content/browser/service_worker/service_worker_context_wrapper.h" 9 #include "content/browser/service_worker/service_worker_context_wrapper.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 namespace { 16 namespace {
17 17
18 const char kNotificationsShownServiceWorkerKey[] =
19 "notifications_shown_by_last_few_pushes";
20
21 void CallStringCallbackFromIO( 18 void CallStringCallbackFromIO(
22 const PushMessagingService::StringCallback& callback, 19 const PushMessagingService::StringCallback& callback,
23 const std::string& data, 20 const std::string& data,
24 ServiceWorkerStatusCode service_worker_status) { 21 ServiceWorkerStatusCode service_worker_status) {
25 DCHECK_CURRENTLY_ON(BrowserThread::IO); 22 DCHECK_CURRENTLY_ON(BrowserThread::IO);
26 bool success = service_worker_status == SERVICE_WORKER_OK; 23 bool success = service_worker_status == SERVICE_WORKER_OK;
27 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; 24 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND;
28 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 25 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
29 base::Bind(callback, data, success, not_found)); 26 base::Bind(callback, data, success, not_found));
30 } 27 }
31 28
32 void CallResultCallbackFromIO(
33 const ServiceWorkerContext::ResultCallback& callback,
34 ServiceWorkerStatusCode service_worker_status) {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36 bool success = service_worker_status == SERVICE_WORKER_OK;
37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
38 base::Bind(callback, success));
39 }
40
41 void CallClosureFromIO(const base::Closure& callback, 29 void CallClosureFromIO(const base::Closure& callback,
42 ServiceWorkerStatusCode status) { 30 ServiceWorkerStatusCode status) {
43 DCHECK_CURRENTLY_ON(BrowserThread::IO); 31 DCHECK_CURRENTLY_ON(BrowserThread::IO);
44 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); 32 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
45 } 33 }
46 34
47 void GetUserDataOnIO( 35 void GetUserDataOnIO(
48 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, 36 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
49 int64_t service_worker_registration_id, 37 int64_t service_worker_registration_id,
50 const std::string& key, 38 const std::string& key,
51 const PushMessagingService::StringCallback& callback) { 39 const PushMessagingService::StringCallback& callback) {
52 DCHECK_CURRENTLY_ON(BrowserThread::IO); 40 DCHECK_CURRENTLY_ON(BrowserThread::IO);
53 service_worker_context_wrapper->GetRegistrationUserData( 41 service_worker_context_wrapper->GetRegistrationUserData(
54 service_worker_registration_id, key, 42 service_worker_registration_id, key,
55 base::Bind(&CallStringCallbackFromIO, callback)); 43 base::Bind(&CallStringCallbackFromIO, callback));
56 } 44 }
57 45
58 void SetNotificationsShownOnIO(
59 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper,
60 int64_t service_worker_registration_id,
61 const GURL& origin,
62 const std::string& data,
63 const PushMessagingService::ResultCallback& callback) {
64 DCHECK_CURRENTLY_ON(BrowserThread::IO);
65 service_worker_context_wrapper->StoreRegistrationUserData(
66 service_worker_registration_id, origin,
67 kNotificationsShownServiceWorkerKey, data,
68 base::Bind(&CallResultCallbackFromIO, callback));
69 }
70
71 void ClearPushSubscriptionIDOnIO( 46 void ClearPushSubscriptionIDOnIO(
72 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, 47 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
73 int64_t service_worker_registration_id, 48 int64_t service_worker_registration_id,
74 const base::Closure& callback) { 49 const base::Closure& callback) {
75 DCHECK_CURRENTLY_ON(BrowserThread::IO); 50 DCHECK_CURRENTLY_ON(BrowserThread::IO);
76 51
77 service_worker_context->ClearRegistrationUserData( 52 service_worker_context->ClearRegistrationUserData(
78 service_worker_registration_id, 53 service_worker_registration_id,
79 kPushRegistrationIdServiceWorkerKey, 54 kPushRegistrationIdServiceWorkerKey,
80 base::Bind(&CallClosureFromIO, callback)); 55 base::Bind(&CallClosureFromIO, callback));
81 } 56 }
82 57
83 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( 58 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext(
84 BrowserContext* browser_context, const GURL& origin) { 59 BrowserContext* browser_context, const GURL& origin) {
85 StoragePartition* partition = 60 StoragePartition* partition =
86 BrowserContext::GetStoragePartitionForSite(browser_context, origin); 61 BrowserContext::GetStoragePartitionForSite(browser_context, origin);
87 return make_scoped_refptr( 62 return make_scoped_refptr(
88 static_cast<ServiceWorkerContextWrapper*>( 63 static_cast<ServiceWorkerContextWrapper*>(
89 partition->GetServiceWorkerContext())); 64 partition->GetServiceWorkerContext()));
90 } 65 }
91 66
92 } // anonymous namespace 67 } // anonymous namespace
93 68
94 // static 69 // static
95 void PushMessagingService::GetNotificationsShownByLastFewPushes(
96 ServiceWorkerContext* service_worker_context,
97 int64_t service_worker_registration_id,
98 const StringCallback& callback) {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
101 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
102 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
103 base::Bind(&GetUserDataOnIO,
104 wrapper,
105 service_worker_registration_id,
106 kNotificationsShownServiceWorkerKey,
107 callback));
108 }
109
110 // static
111 void PushMessagingService::SetNotificationsShownByLastFewPushes(
112 ServiceWorkerContext* service_worker_context,
113 int64_t service_worker_registration_id,
114 const GURL& origin,
115 const std::string& notifications_shown,
116 const ResultCallback& callback) {
117 DCHECK_CURRENTLY_ON(BrowserThread::UI);
118 scoped_refptr<ServiceWorkerContextWrapper> wrapper =
119 static_cast<ServiceWorkerContextWrapper*>(service_worker_context);
120 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
121 base::Bind(&SetNotificationsShownOnIO,
122 wrapper,
123 service_worker_registration_id,
124 origin,
125 notifications_shown,
126 callback));
127 }
128
129 // static
130 void PushMessagingService::GetSenderId(BrowserContext* browser_context, 70 void PushMessagingService::GetSenderId(BrowserContext* browser_context,
131 const GURL& origin, 71 const GURL& origin,
132 int64_t service_worker_registration_id, 72 int64_t service_worker_registration_id,
133 const StringCallback& callback) { 73 const StringCallback& callback) {
134 DCHECK_CURRENTLY_ON(BrowserThread::UI); 74 DCHECK_CURRENTLY_ON(BrowserThread::UI);
135 BrowserThread::PostTask( 75 BrowserThread::PostTask(
136 BrowserThread::IO, 76 BrowserThread::IO,
137 FROM_HERE, 77 FROM_HERE,
138 base::Bind(&GetUserDataOnIO, 78 base::Bind(&GetUserDataOnIO,
139 GetServiceWorkerContext(browser_context, origin), 79 GetServiceWorkerContext(browser_context, origin),
(...skipping 12 matching lines...) Expand all
152 BrowserThread::PostTask( 92 BrowserThread::PostTask(
153 BrowserThread::IO, 93 BrowserThread::IO,
154 FROM_HERE, 94 FROM_HERE,
155 base::Bind(&ClearPushSubscriptionIDOnIO, 95 base::Bind(&ClearPushSubscriptionIDOnIO,
156 GetServiceWorkerContext(browser_context, origin), 96 GetServiceWorkerContext(browser_context, origin),
157 service_worker_registration_id, 97 service_worker_registration_id,
158 callback)); 98 callback));
159 } 99 }
160 100
161 } // namespace content 101 } // 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