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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "content/child/background_sync/background_sync_type_converters.h" | 9 #include "content/child/background_sync/background_sync_type_converters.h" |
10 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 10 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // will wipe its callbacks) before 'this' is deleted. | 54 // will wipe its callbacks) before 'this' is deleted. |
55 GetBackgroundSyncServicePtr()->Register( | 55 GetBackgroundSyncServicePtr()->Register( |
56 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())), | 56 mojo::ConvertTo<SyncRegistrationPtr>(*(optionsPtr.get())), |
57 service_worker_registration_id, requested_from_service_worker, | 57 service_worker_registration_id, requested_from_service_worker, |
58 base::Bind(&BackgroundSyncProvider::RegisterCallback, | 58 base::Bind(&BackgroundSyncProvider::RegisterCallback, |
59 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 59 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
60 } | 60 } |
61 | 61 |
62 void BackgroundSyncProvider::unregisterBackgroundSync( | 62 void BackgroundSyncProvider::unregisterBackgroundSync( |
63 blink::WebSyncRegistration::Periodicity periodicity, | 63 blink::WebSyncRegistration::Periodicity periodicity, |
64 int64_t id, | 64 int64_t handle_id, |
65 const blink::WebString& tag, | 65 const blink::WebString& tag, |
66 blink::WebServiceWorkerRegistration* service_worker_registration, | 66 blink::WebServiceWorkerRegistration* service_worker_registration, |
67 blink::WebSyncUnregistrationCallbacks* callbacks) { | 67 blink::WebSyncUnregistrationCallbacks* callbacks) { |
68 DCHECK(service_worker_registration); | 68 DCHECK(service_worker_registration); |
69 DCHECK(callbacks); | 69 DCHECK(callbacks); |
70 int64 service_worker_registration_id = | 70 int64 service_worker_registration_id = |
71 GetServiceWorkerRegistrationId(service_worker_registration); | 71 GetServiceWorkerRegistrationId(service_worker_registration); |
72 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks); | 72 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacksPtr(callbacks); |
73 | 73 |
74 // base::Unretained is safe here, as the mojo channel will be deleted (and | 74 // base::Unretained is safe here, as the mojo channel will be deleted (and |
75 // will wipe its callbacks) before 'this' is deleted. | 75 // will wipe its callbacks) before 'this' is deleted. |
76 GetBackgroundSyncServicePtr()->Unregister( | 76 GetBackgroundSyncServicePtr()->Unregister( |
77 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), id, tag.utf8(), | 77 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), handle_id, |
78 service_worker_registration_id, | 78 service_worker_registration_id, |
79 base::Bind(&BackgroundSyncProvider::UnregisterCallback, | 79 base::Bind(&BackgroundSyncProvider::UnregisterCallback, |
80 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 80 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
81 } | 81 } |
82 | 82 |
83 void BackgroundSyncProvider::getRegistration( | 83 void BackgroundSyncProvider::getRegistration( |
84 blink::WebSyncRegistration::Periodicity periodicity, | 84 blink::WebSyncRegistration::Periodicity periodicity, |
85 const blink::WebString& tag, | 85 const blink::WebString& tag, |
86 blink::WebServiceWorkerRegistration* service_worker_registration, | 86 blink::WebServiceWorkerRegistration* service_worker_registration, |
87 blink::WebSyncRegistrationCallbacks* callbacks) { | 87 blink::WebSyncRegistrationCallbacks* callbacks) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 // base::Unretained is safe here, as the mojo channel will be deleted (and | 133 // base::Unretained is safe here, as the mojo channel will be deleted (and |
134 // will wipe its callbacks) before 'this' is deleted. | 134 // will wipe its callbacks) before 'this' is deleted. |
135 GetBackgroundSyncServicePtr()->GetPermissionStatus( | 135 GetBackgroundSyncServicePtr()->GetPermissionStatus( |
136 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), | 136 mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), |
137 service_worker_registration_id, | 137 service_worker_registration_id, |
138 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback, | 138 base::Bind(&BackgroundSyncProvider::GetPermissionStatusCallback, |
139 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); | 139 base::Unretained(this), base::Passed(callbacksPtr.Pass()))); |
140 } | 140 } |
141 | 141 |
| 142 void BackgroundSyncProvider::releaseRegistration(int64_t handle_id) { |
| 143 GetBackgroundSyncServicePtr()->ReleaseRegistration(handle_id); |
| 144 } |
| 145 |
| 146 void BackgroundSyncProvider::DuplicateRegistrationHandle( |
| 147 int handle_id, |
| 148 const BackgroundSyncService::DuplicateRegistrationHandleCallback& |
| 149 callback) { |
| 150 GetBackgroundSyncServicePtr()->DuplicateRegistrationHandle(handle_id, |
| 151 callback); |
| 152 } |
| 153 |
142 void BackgroundSyncProvider::RegisterCallback( | 154 void BackgroundSyncProvider::RegisterCallback( |
143 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 155 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
144 BackgroundSyncError error, | 156 BackgroundSyncError error, |
145 const SyncRegistrationPtr& options) { | 157 const SyncRegistrationPtr& options) { |
146 // TODO(iclelland): Determine the correct error message to return in each case | 158 // TODO(iclelland): Determine the correct error message to return in each case |
147 scoped_ptr<blink::WebSyncRegistration> result; | 159 scoped_ptr<blink::WebSyncRegistration> result; |
148 switch (error) { | 160 switch (error) { |
149 case BACKGROUND_SYNC_ERROR_NONE: | 161 case BACKGROUND_SYNC_ERROR_NONE: |
150 if (!options.is_null()) | 162 if (!options.is_null()) |
151 result = | 163 result = |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 BackgroundSyncServicePtr& | 325 BackgroundSyncServicePtr& |
314 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { | 326 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { |
315 if (!background_sync_service_.get()) { | 327 if (!background_sync_service_.get()) { |
316 service_registry_->ConnectToRemoteService( | 328 service_registry_->ConnectToRemoteService( |
317 mojo::GetProxy(&background_sync_service_)); | 329 mojo::GetProxy(&background_sync_service_)); |
318 } | 330 } |
319 return background_sync_service_; | 331 return background_sync_service_; |
320 } | 332 } |
321 | 333 |
322 } // namespace content | 334 } // namespace content |
OLD | NEW |