OLD | NEW |
---|---|
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 "content/browser/service_worker/service_worker_context_wrapper.h" | 7 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
8 #include "content/public/browser/browser_context.h" | |
8 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/storage_partition.h" | |
11 | |
12 namespace content { | |
9 | 13 |
10 namespace { | 14 namespace { |
11 | 15 |
12 const char kNotificationsShownServiceWorkerKey[] = | 16 const char kNotificationsShownServiceWorkerKey[] = |
13 "notifications_shown_by_last_few_pushes"; | 17 "notifications_shown_by_last_few_pushes"; |
18 const char kPushRegistrationIdServiceWorkerKey[] = | |
19 "push_registration_id"; | |
johnme
2015/02/16 20:27:45
Please add an extern declaration for the one in co
mlamouri (slow - plz ping)
2015/02/16 20:46:03
Done.
| |
14 | 20 |
15 } // namespace | 21 void CallGetNotificationsShownCallbackFromIO( |
16 | |
17 namespace content { | |
18 | |
19 static void CallGetNotificationsShownCallbackFromIO( | |
20 const PushMessagingService::GetNotificationsShownCallback& callback, | 22 const PushMessagingService::GetNotificationsShownCallback& callback, |
21 const std::string& data, | 23 const std::string& data, |
22 ServiceWorkerStatusCode service_worker_status) { | 24 ServiceWorkerStatusCode service_worker_status) { |
23 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 25 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
24 bool success = service_worker_status == SERVICE_WORKER_OK; | 26 bool success = service_worker_status == SERVICE_WORKER_OK; |
25 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; | 27 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; |
26 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 28 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
27 base::Bind(callback, data, success, not_found)); | 29 base::Bind(callback, data, success, not_found)); |
28 } | 30 } |
29 | 31 |
30 static void CallResultCallbackFromIO( | 32 void CallResultCallbackFromIO( |
31 const ServiceWorkerContext::ResultCallback& callback, | 33 const ServiceWorkerContext::ResultCallback& callback, |
32 ServiceWorkerStatusCode service_worker_status) { | 34 ServiceWorkerStatusCode service_worker_status) { |
33 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 35 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
34 bool success = service_worker_status == SERVICE_WORKER_OK; | 36 bool success = service_worker_status == SERVICE_WORKER_OK; |
35 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
36 base::Bind(callback, success)); | 38 base::Bind(callback, success)); |
37 } | 39 } |
38 | 40 |
39 static void GetNotificationsShownOnIO( | 41 void GetNotificationsShownOnIO( |
40 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 42 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
41 int64 service_worker_registration_id, | 43 int64 service_worker_registration_id, |
42 const PushMessagingService::GetNotificationsShownCallback& callback) { | 44 const PushMessagingService::GetNotificationsShownCallback& callback) { |
43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
44 service_worker_context_wrapper->context()->storage()->GetUserData( | 46 service_worker_context_wrapper->context()->storage()->GetUserData( |
45 service_worker_registration_id, kNotificationsShownServiceWorkerKey, | 47 service_worker_registration_id, kNotificationsShownServiceWorkerKey, |
46 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback)); | 48 base::Bind(&CallGetNotificationsShownCallbackFromIO, callback)); |
47 } | 49 } |
48 | 50 |
49 static void SetNotificationsShownOnIO( | 51 void SetNotificationsShownOnIO( |
50 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 52 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
51 int64 service_worker_registration_id, const GURL& origin, | 53 int64 service_worker_registration_id, const GURL& origin, |
52 const std::string& data, | 54 const std::string& data, |
53 const PushMessagingService::ResultCallback& callback) { | 55 const PushMessagingService::ResultCallback& callback) { |
54 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
55 service_worker_context_wrapper->context()->storage()->StoreUserData( | 57 service_worker_context_wrapper->context()->storage()->StoreUserData( |
56 service_worker_registration_id, origin, | 58 service_worker_registration_id, origin, |
57 kNotificationsShownServiceWorkerKey, data, | 59 kNotificationsShownServiceWorkerKey, data, |
58 base::Bind(&CallResultCallbackFromIO, callback)); | 60 base::Bind(&CallResultCallbackFromIO, callback)); |
59 } | 61 } |
60 | 62 |
63 void OnClearPushRegistrationServiceWorkerKey(ServiceWorkerStatusCode status) { | |
64 } | |
65 | |
66 void ClearPushRegistrationIDOnIO( | |
67 int64 service_worker_registration_id, | |
68 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) { | |
johnme
2015/02/16 20:27:45
Nit: Please swap the argument order, for consisten
mlamouri (slow - plz ping)
2015/02/16 20:46:03
I guess PushMessagingRouter isn't consistent with
| |
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
70 | |
71 service_worker_context->context()->storage()->ClearUserData( | |
72 service_worker_registration_id, | |
73 kPushRegistrationIdServiceWorkerKey, | |
74 base::Bind(&OnClearPushRegistrationServiceWorkerKey)); | |
75 } | |
76 | |
77 } // anonymous namespace | |
78 | |
61 // static | 79 // static |
62 void PushMessagingService::GetNotificationsShownByLastFewPushes( | 80 void PushMessagingService::GetNotificationsShownByLastFewPushes( |
63 ServiceWorkerContext* service_worker_context, | 81 ServiceWorkerContext* service_worker_context, |
64 int64 service_worker_registration_id, | 82 int64 service_worker_registration_id, |
65 const GetNotificationsShownCallback& callback) { | 83 const GetNotificationsShownCallback& callback) { |
66 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 84 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
67 scoped_refptr<ServiceWorkerContextWrapper> wrapper = | 85 scoped_refptr<ServiceWorkerContextWrapper> wrapper = |
68 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); | 86 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); |
69 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 87 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
70 base::Bind(&GetNotificationsShownOnIO, | 88 base::Bind(&GetNotificationsShownOnIO, |
(...skipping 14 matching lines...) Expand all Loading... | |
85 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); | 103 static_cast<ServiceWorkerContextWrapper*>(service_worker_context); |
86 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 104 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
87 base::Bind(&SetNotificationsShownOnIO, | 105 base::Bind(&SetNotificationsShownOnIO, |
88 wrapper, | 106 wrapper, |
89 service_worker_registration_id, | 107 service_worker_registration_id, |
90 origin, | 108 origin, |
91 notifications_shown, | 109 notifications_shown, |
92 callback)); | 110 callback)); |
93 } | 111 } |
94 | 112 |
113 // static | |
114 void PushMessagingService::ClearPushRegistrationID( | |
115 BrowserContext* browser_context, | |
116 const GURL& origin, | |
117 int64 service_worker_registration_id) { | |
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
119 StoragePartition* partition = | |
120 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | |
121 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = | |
122 static_cast<ServiceWorkerContextWrapper*>( | |
123 partition->GetServiceWorkerContext()); | |
124 | |
125 BrowserThread::PostTask( | |
126 BrowserThread::IO, | |
127 FROM_HERE, | |
128 base::Bind(&ClearPushRegistrationIDOnIO, | |
129 service_worker_registration_id, | |
130 service_worker_context)); | |
131 } | |
132 | |
95 } // namespace content | 133 } // namespace content |
OLD | NEW |