| 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 "content/browser/push_messaging/push_messaging_message_filter.h" | 8 #include "content/browser/push_messaging/push_messaging_message_filter.h" |
| 8 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 9 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 9 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/storage_partition.h" | 12 #include "content/public/browser/storage_partition.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 | 31 |
| 31 void CallResultCallbackFromIO( | 32 void CallResultCallbackFromIO( |
| 32 const ServiceWorkerContext::ResultCallback& callback, | 33 const ServiceWorkerContext::ResultCallback& callback, |
| 33 ServiceWorkerStatusCode service_worker_status) { | 34 ServiceWorkerStatusCode service_worker_status) { |
| 34 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 35 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 35 bool success = service_worker_status == SERVICE_WORKER_OK; | 36 bool success = service_worker_status == SERVICE_WORKER_OK; |
| 36 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 37 base::Bind(callback, success)); | 38 base::Bind(callback, success)); |
| 38 } | 39 } |
| 39 | 40 |
| 41 void CallClosureFromIO(const base::Closure& callback, |
| 42 ServiceWorkerStatusCode status) { |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 44 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| 45 } |
| 46 |
| 40 void GetUserDataOnIO( | 47 void GetUserDataOnIO( |
| 41 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 48 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
| 42 int64 service_worker_registration_id, | 49 int64 service_worker_registration_id, |
| 43 const std::string& key, | 50 const std::string& key, |
| 44 const PushMessagingService::StringCallback& callback) { | 51 const PushMessagingService::StringCallback& callback) { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 46 service_worker_context_wrapper->context()->storage()->GetUserData( | 53 service_worker_context_wrapper->context()->storage()->GetUserData( |
| 47 service_worker_registration_id, key, | 54 service_worker_registration_id, key, |
| 48 base::Bind(&CallStringCallbackFromIO, callback)); | 55 base::Bind(&CallStringCallbackFromIO, callback)); |
| 49 } | 56 } |
| 50 | 57 |
| 51 void SetNotificationsShownOnIO( | 58 void SetNotificationsShownOnIO( |
| 52 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, | 59 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_wrapper, |
| 53 int64 service_worker_registration_id, const GURL& origin, | 60 int64 service_worker_registration_id, const GURL& origin, |
| 54 const std::string& data, | 61 const std::string& data, |
| 55 const PushMessagingService::ResultCallback& callback) { | 62 const PushMessagingService::ResultCallback& callback) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 service_worker_context_wrapper->context()->storage()->StoreUserData( | 64 service_worker_context_wrapper->context()->storage()->StoreUserData( |
| 58 service_worker_registration_id, origin, | 65 service_worker_registration_id, origin, |
| 59 kNotificationsShownServiceWorkerKey, data, | 66 kNotificationsShownServiceWorkerKey, data, |
| 60 base::Bind(&CallResultCallbackFromIO, callback)); | 67 base::Bind(&CallResultCallbackFromIO, callback)); |
| 61 } | 68 } |
| 62 | 69 |
| 63 void OnClearPushRegistrationServiceWorkerKey(ServiceWorkerStatusCode status) { | |
| 64 } | |
| 65 | |
| 66 void ClearPushRegistrationIDOnIO( | 70 void ClearPushRegistrationIDOnIO( |
| 67 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 71 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 68 int64 service_worker_registration_id) { | 72 int64 service_worker_registration_id, |
| 73 const base::Closure& callback) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 70 | 75 |
| 71 service_worker_context->context()->storage()->ClearUserData( | 76 service_worker_context->context()->storage()->ClearUserData( |
| 72 service_worker_registration_id, | 77 service_worker_registration_id, |
| 73 kPushRegistrationIdServiceWorkerKey, | 78 kPushRegistrationIdServiceWorkerKey, |
| 74 base::Bind(&OnClearPushRegistrationServiceWorkerKey)); | 79 base::Bind(&CallClosureFromIO, callback)); |
| 75 } | 80 } |
| 76 | 81 |
| 77 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( | 82 scoped_refptr<ServiceWorkerContextWrapper> GetServiceWorkerContext( |
| 78 BrowserContext* browser_context, const GURL& origin) { | 83 BrowserContext* browser_context, const GURL& origin) { |
| 79 StoragePartition* partition = | 84 StoragePartition* partition = |
| 80 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 85 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
| 81 return make_scoped_refptr( | 86 return make_scoped_refptr( |
| 82 static_cast<ServiceWorkerContextWrapper*>( | 87 static_cast<ServiceWorkerContextWrapper*>( |
| 83 partition->GetServiceWorkerContext())); | 88 partition->GetServiceWorkerContext())); |
| 84 } | 89 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 GetServiceWorkerContext(browser_context, origin), | 138 GetServiceWorkerContext(browser_context, origin), |
| 134 service_worker_registration_id, | 139 service_worker_registration_id, |
| 135 kPushSenderIdServiceWorkerKey, | 140 kPushSenderIdServiceWorkerKey, |
| 136 callback)); | 141 callback)); |
| 137 } | 142 } |
| 138 | 143 |
| 139 // static | 144 // static |
| 140 void PushMessagingService::ClearPushRegistrationID( | 145 void PushMessagingService::ClearPushRegistrationID( |
| 141 BrowserContext* browser_context, | 146 BrowserContext* browser_context, |
| 142 const GURL& origin, | 147 const GURL& origin, |
| 143 int64 service_worker_registration_id) { | 148 int64 service_worker_registration_id, |
| 149 const base::Closure& callback) { |
| 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 145 BrowserThread::PostTask( | 151 BrowserThread::PostTask( |
| 146 BrowserThread::IO, | 152 BrowserThread::IO, |
| 147 FROM_HERE, | 153 FROM_HERE, |
| 148 base::Bind(&ClearPushRegistrationIDOnIO, | 154 base::Bind(&ClearPushRegistrationIDOnIO, |
| 149 GetServiceWorkerContext(browser_context, origin), | 155 GetServiceWorkerContext(browser_context, origin), |
| 150 service_worker_registration_id)); | 156 service_worker_registration_id, |
| 157 callback)); |
| 151 } | 158 } |
| 152 | 159 |
| 153 } // namespace content | 160 } // namespace content |
| OLD | NEW |