| 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/child/background_sync/background_sync_provider.h" | 5 #include "content/child/background_sync/background_sync_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 11 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
| 12 #include "content/child/background_sync/background_sync_type_converters.h" | 14 #include "content/child/background_sync/background_sync_type_converters.h" |
| 13 #include "content/child/child_thread_impl.h" | 15 #include "content/child/child_thread_impl.h" |
| 14 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 16 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 15 #include "content/public/common/background_sync.mojom.h" | 17 #include "content/public/common/background_sync.mojom.h" |
| 16 #include "content/public/common/permission_status.mojom.h" | 18 #include "content/public/common/permission_status.mojom.h" |
| 17 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncErro
r.h" | 19 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncErro
r.h" |
| 18 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" | 20 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.h" |
| 19 | 21 |
| 20 using base::LazyInstance; | 22 using base::LazyInstance; |
| 21 using base::ThreadLocalPointer; | 23 using base::ThreadLocalPointer; |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 // Returns the id of the given |service_worker_registration|, which | 28 // Returns the id of the given |service_worker_registration|, which |
| 27 // is only available on the implementation of the interface. | 29 // is only available on the implementation of the interface. |
| 28 int64 GetServiceWorkerRegistrationId( | 30 int64_t GetServiceWorkerRegistrationId( |
| 29 blink::WebServiceWorkerRegistration* service_worker_registration) { | 31 blink::WebServiceWorkerRegistration* service_worker_registration) { |
| 30 return static_cast<WebServiceWorkerRegistrationImpl*>( | 32 return static_cast<WebServiceWorkerRegistrationImpl*>( |
| 31 service_worker_registration)->registration_id(); | 33 service_worker_registration)->registration_id(); |
| 32 } | 34 } |
| 33 | 35 |
| 34 void ConnectToServiceOnMainThread( | 36 void ConnectToServiceOnMainThread( |
| 35 mojo::InterfaceRequest<BackgroundSyncService> request) { | 37 mojo::InterfaceRequest<BackgroundSyncService> request) { |
| 36 DCHECK(ChildThreadImpl::current()); | 38 DCHECK(ChildThreadImpl::current()); |
| 37 ChildThreadImpl::current()->service_registry()->ConnectToRemoteService( | 39 ChildThreadImpl::current()->service_registry()->ConnectToRemoteService( |
| 38 request.Pass()); | 40 request.Pass()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 } | 84 } |
| 83 | 85 |
| 84 void BackgroundSyncProvider::registerBackgroundSync( | 86 void BackgroundSyncProvider::registerBackgroundSync( |
| 85 const blink::WebSyncRegistration* options, | 87 const blink::WebSyncRegistration* options, |
| 86 blink::WebServiceWorkerRegistration* service_worker_registration, | 88 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 87 bool requested_from_service_worker, | 89 bool requested_from_service_worker, |
| 88 blink::WebSyncRegistrationCallbacks* callbacks) { | 90 blink::WebSyncRegistrationCallbacks* callbacks) { |
| 89 DCHECK(options); | 91 DCHECK(options); |
| 90 DCHECK(service_worker_registration); | 92 DCHECK(service_worker_registration); |
| 91 DCHECK(callbacks); | 93 DCHECK(callbacks); |
| 92 int64 service_worker_registration_id = | 94 int64_t service_worker_registration_id = |
| 93 GetServiceWorkerRegistrationId(service_worker_registration); | 95 GetServiceWorkerRegistrationId(service_worker_registration); |
| 94 scoped_ptr<const blink::WebSyncRegistration> optionsPtr(options); | 96 scoped_ptr<const blink::WebSyncRegistration> optionsPtr(options); |
| 95 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacksPtr(callbacks); | 97 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacksPtr(callbacks); |
| 96 | 98 |
| 97 // base::Unretained is safe here, as the mojo channel will be deleted (and | 99 // base::Unretained is safe here, as the mojo channel will be deleted (and |
| 98 // will wipe its callbacks) before 'this' is deleted. | 100 // will wipe its callbacks) before 'this' is deleted. |
| 99 GetBackgroundSyncServicePtr()->Register( | 101 GetBackgroundSyncServicePtr()->Register( |
| 100 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())), | 102 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())), |
| 101 service_worker_registration_id, requested_from_service_worker, | 103 service_worker_registration_id, requested_from_service_worker, |
| 102 base::Bind(&BackgroundSyncProvider::RegisterCallback, | 104 base::Bind(&BackgroundSyncProvider::RegisterCallback, |
| 103 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 105 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
| 104 } | 106 } |
| 105 | 107 |
| 106 void BackgroundSyncProvider::unregisterBackgroundSync( | 108 void BackgroundSyncProvider::unregisterBackgroundSync( |
| 107 int64_t handle_id, | 109 int64_t handle_id, |
| 108 blink::WebServiceWorkerRegistration* service_worker_registration, | 110 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 109 blink::WebSyncUnregistrationCallbacks* callbacks) { | 111 blink::WebSyncUnregistrationCallbacks* callbacks) { |
| 110 DCHECK(service_worker_registration); | 112 DCHECK(service_worker_registration); |
| 111 DCHECK(callbacks); | 113 DCHECK(callbacks); |
| 112 int64 service_worker_registration_id = | 114 int64_t service_worker_registration_id = |
| 113 GetServiceWorkerRegistrationId(service_worker_registration); | 115 GetServiceWorkerRegistrationId(service_worker_registration); |
| 114 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks); | 116 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks); |
| 115 | 117 |
| 116 // base::Unretained is safe here, as the mojo channel will be deleted (and | 118 // base::Unretained is safe here, as the mojo channel will be deleted (and |
| 117 // will wipe its callbacks) before 'this' is deleted. | 119 // will wipe its callbacks) before 'this' is deleted. |
| 118 GetBackgroundSyncServicePtr()->Unregister( | 120 GetBackgroundSyncServicePtr()->Unregister( |
| 119 handle_id, service_worker_registration_id, | 121 handle_id, service_worker_registration_id, |
| 120 base::Bind(&BackgroundSyncProvider::UnregisterCallback, | 122 base::Bind(&BackgroundSyncProvider::UnregisterCallback, |
| 121 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 123 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void BackgroundSyncProvider::getRegistration( | 126 void BackgroundSyncProvider::getRegistration( |
| 125 blink::WebSyncRegistration::Periodicity periodicity, | 127 blink::WebSyncRegistration::Periodicity periodicity, |
| 126 const blink::WebString& tag, | 128 const blink::WebString& tag, |
| 127 blink::WebServiceWorkerRegistration* service_worker_registration, | 129 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 128 blink::WebSyncRegistrationCallbacks* callbacks) { | 130 blink::WebSyncRegistrationCallbacks* callbacks) { |
| 129 DCHECK(service_worker_registration); | 131 DCHECK(service_worker_registration); |
| 130 DCHECK(callbacks); | 132 DCHECK(callbacks); |
| 131 int64 service_worker_registration_id = | 133 int64_t service_worker_registration_id = |
| 132 GetServiceWorkerRegistrationId(service_worker_registration); | 134 GetServiceWorkerRegistrationId(service_worker_registration); |
| 133 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacksPtr(callbacks); | 135 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacksPtr(callbacks); |
| 134 | 136 |
| 135 // base::Unretained is safe here, as the mojo channel will be deleted (and | 137 // base::Unretained is safe here, as the mojo channel will be deleted (and |
| 136 // will wipe its callbacks) before 'this' is deleted. | 138 // will wipe its callbacks) before 'this' is deleted. |
| 137 GetBackgroundSyncServicePtr()->GetRegistration( | 139 GetBackgroundSyncServicePtr()->GetRegistration( |
| 138 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), tag.utf8(), | 140 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), tag.utf8(), |
| 139 service_worker_registration_id, | 141 service_worker_registration_id, |
| 140 base::Bind(&BackgroundSyncProvider::GetRegistrationCallback, | 142 base::Bind(&BackgroundSyncProvider::GetRegistrationCallback, |
| 141 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 143 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void BackgroundSyncProvider::getRegistrations( | 146 void BackgroundSyncProvider::getRegistrations( |
| 145 blink::WebSyncRegistration::Periodicity periodicity, | 147 blink::WebSyncRegistration::Periodicity periodicity, |
| 146 blink::WebServiceWorkerRegistration* service_worker_registration, | 148 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 147 blink::WebSyncGetRegistrationsCallbacks* callbacks) { | 149 blink::WebSyncGetRegistrationsCallbacks* callbacks) { |
| 148 DCHECK(service_worker_registration); | 150 DCHECK(service_worker_registration); |
| 149 DCHECK(callbacks); | 151 DCHECK(callbacks); |
| 150 int64 service_worker_registration_id = | 152 int64_t service_worker_registration_id = |
| 151 GetServiceWorkerRegistrationId(service_worker_registration); | 153 GetServiceWorkerRegistrationId(service_worker_registration); |
| 152 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacksPtr(callbacks); | 154 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacksPtr(callbacks); |
| 153 | 155 |
| 154 // base::Unretained is safe here, as the mojo channel will be deleted (and | 156 // base::Unretained is safe here, as the mojo channel will be deleted (and |
| 155 // will wipe its callbacks) before 'this' is deleted. | 157 // will wipe its callbacks) before 'this' is deleted. |
| 156 GetBackgroundSyncServicePtr()->GetRegistrations( | 158 GetBackgroundSyncServicePtr()->GetRegistrations( |
| 157 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), | 159 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), |
| 158 service_worker_registration_id, | 160 service_worker_registration_id, |
| 159 base::Bind(&BackgroundSyncProvider::GetRegistrationsCallback, | 161 base::Bind(&BackgroundSyncProvider::GetRegistrationsCallback, |
| 160 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 162 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void BackgroundSyncProvider::getPermissionStatus( | 165 void BackgroundSyncProvider::getPermissionStatus( |
| 164 blink::WebSyncRegistration::Periodicity periodicity, | 166 blink::WebSyncRegistration::Periodicity periodicity, |
| 165 blink::WebServiceWorkerRegistration* service_worker_registration, | 167 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 166 blink::WebSyncGetPermissionStatusCallbacks* callbacks) { | 168 blink::WebSyncGetPermissionStatusCallbacks* callbacks) { |
| 167 DCHECK(service_worker_registration); | 169 DCHECK(service_worker_registration); |
| 168 DCHECK(callbacks); | 170 DCHECK(callbacks); |
| 169 int64 service_worker_registration_id = | 171 int64_t service_worker_registration_id = |
| 170 GetServiceWorkerRegistrationId(service_worker_registration); | 172 GetServiceWorkerRegistrationId(service_worker_registration); |
| 171 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacksPtr( | 173 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacksPtr( |
| 172 callbacks); | 174 callbacks); |
| 173 | 175 |
| 174 // base::Unretained is safe here, as the mojo channel will be deleted (and | 176 // base::Unretained is safe here, as the mojo channel will be deleted (and |
| 175 // will wipe its callbacks) before 'this' is deleted. | 177 // will wipe its callbacks) before 'this' is deleted. |
| 176 GetBackgroundSyncServicePtr()->GetPermissionStatus( | 178 GetBackgroundSyncServicePtr()->GetPermissionStatus( |
| 177 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), | 179 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), |
| 178 service_worker_registration_id, | 180 service_worker_registration_id, |
| 179 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback, | 181 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 mojo::InterfaceRequest<BackgroundSyncService> request = | 433 mojo::InterfaceRequest<BackgroundSyncService> request = |
| 432 mojo::GetProxy(&background_sync_service_); | 434 mojo::GetProxy(&background_sync_service_); |
| 433 main_thread_task_runner_->PostTask( | 435 main_thread_task_runner_->PostTask( |
| 434 FROM_HERE, | 436 FROM_HERE, |
| 435 base::Bind(&ConnectToServiceOnMainThread, base::Passed(&request))); | 437 base::Bind(&ConnectToServiceOnMainThread, base::Passed(&request))); |
| 436 } | 438 } |
| 437 return background_sync_service_; | 439 return background_sync_service_; |
| 438 } | 440 } |
| 439 | 441 |
| 440 } // namespace content | 442 } // namespace content |
| OLD | NEW |