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 "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 void CallStringCallbackFromIO( | 18 void CallStringCallbackFromIO( |
19 const PushMessagingService::StringCallback& callback, | 19 const PushMessagingService::StringCallback& callback, |
20 const std::string& data, | 20 const std::vector<std::string>& data, |
21 ServiceWorkerStatusCode service_worker_status) { | 21 ServiceWorkerStatusCode service_worker_status) { |
22 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 22 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
23 bool success = service_worker_status == SERVICE_WORKER_OK; | 23 bool success = service_worker_status == SERVICE_WORKER_OK; |
24 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; | 24 bool not_found = service_worker_status == SERVICE_WORKER_ERROR_NOT_FOUND; |
| 25 std::string result; |
| 26 if (success) { |
| 27 DCHECK_EQ(1u, data.size()); |
| 28 result = data[0]; |
| 29 } |
25 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 30 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
26 base::Bind(callback, data, success, not_found)); | 31 base::Bind(callback, result, success, not_found)); |
27 } | 32 } |
28 | 33 |
29 void CallClosureFromIO(const base::Closure& callback, | 34 void CallClosureFromIO(const base::Closure& callback, |
30 ServiceWorkerStatusCode status) { | 35 ServiceWorkerStatusCode status) { |
31 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
32 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
33 } | 38 } |
34 | 39 |
35 void GetUserDataOnIO( | 40 void GetUserDataOnIO( |
36 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 41 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
37 int64_t service_worker_registration_id, | 42 int64_t service_worker_registration_id, |
38 const std::string& key, | 43 const std::string& key, |
39 const PushMessagingService::StringCallback& callback) { | 44 const PushMessagingService::StringCallback& callback) { |
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
41 service_worker_context_wrapper->GetRegistrationUserData( | 46 service_worker_context_wrapper->GetRegistrationUserData( |
42 service_worker_registration_id, key, | 47 service_worker_registration_id, {key}, |
43 base::Bind(&CallStringCallbackFromIO, callback)); | 48 base::Bind(&CallStringCallbackFromIO, callback)); |
44 } | 49 } |
45 | 50 |
46 void ClearPushSubscriptionIDOnIO( | 51 void ClearPushSubscriptionIDOnIO( |
47 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 52 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
48 int64_t service_worker_registration_id, | 53 int64_t service_worker_registration_id, |
49 const base::Closure& callback) { | 54 const base::Closure& callback) { |
50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
51 | 56 |
52 service_worker_context->ClearRegistrationUserData( | 57 service_worker_context->ClearRegistrationUserData( |
53 service_worker_registration_id, | 58 service_worker_registration_id, {kPushRegistrationIdServiceWorkerKey}, |
54 kPushRegistrationIdServiceWorkerKey, | |
55 base::Bind(&CallClosureFromIO, callback)); | 59 base::Bind(&CallClosureFromIO, callback)); |
56 } | 60 } |
57 | 61 |
58 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( | 62 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( |
59 BrowserContext* browser_context, const GURL& origin) { | 63 BrowserContext* browser_context, const GURL& origin) { |
60 StoragePartition* partition = | 64 StoragePartition* partition = |
61 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 65 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
62 return make_scoped_refptr( | 66 return make_scoped_refptr( |
63 static_cast<ServiceWorkerContextWrapper*>( | 67 static_cast<ServiceWorkerContextWrapper*>( |
64 partition->GetServiceWorkerContext())); | 68 partition->GetServiceWorkerContext())); |
(...skipping 27 matching lines...) Expand all Loading... |
92 BrowserThread::PostTask( | 96 BrowserThread::PostTask( |
93 BrowserThread::IO, | 97 BrowserThread::IO, |
94 FROM_HERE, | 98 FROM_HERE, |
95 base::Bind(&ClearPushSubscriptionIDOnIO, | 99 base::Bind(&ClearPushSubscriptionIDOnIO, |
96 GetServiceWorkerContext(browser_context, origin), | 100 GetServiceWorkerContext(browser_context, origin), |
97 service_worker_registration_id, | 101 service_worker_registration_id, |
98 callback)); | 102 callback)); |
99 } | 103 } |
100 | 104 |
101 } // namespace content | 105 } // namespace content |
OLD | NEW |