Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: content/child/background_sync/background_sync_provider.cc

Issue 1308273002: [BackgroundSync] Use appopriate type parameters for WebCallbacks (3/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, 142 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
143 BackgroundSyncError error, 143 BackgroundSyncError error,
144 const SyncRegistrationPtr& options) { 144 const SyncRegistrationPtr& options) {
145 // TODO(iclelland): Determine the correct error message to return in each case 145 // TODO(iclelland): Determine the correct error message to return in each case
146 scoped_ptr<blink::WebSyncRegistration> result; 146 scoped_ptr<blink::WebSyncRegistration> result;
147 switch (error) { 147 switch (error) {
148 case BACKGROUND_SYNC_ERROR_NONE: 148 case BACKGROUND_SYNC_ERROR_NONE:
149 if (!options.is_null()) 149 if (!options.is_null())
150 result = 150 result =
151 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options); 151 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options);
152 callbacks->onSuccess(result.release()); 152 callbacks->onSuccess(blink::adoptWebPtr(result.release()));
153 break; 153 break;
154 case BACKGROUND_SYNC_ERROR_NOT_FOUND: 154 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
155 NOTREACHED(); 155 NOTREACHED();
156 break; 156 break;
157 case BACKGROUND_SYNC_ERROR_STORAGE: 157 case BACKGROUND_SYNC_ERROR_STORAGE:
158 callbacks->onError( 158 callbacks->onError(
159 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 159 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
160 "Background Sync is disabled.")); 160 "Background Sync is disabled."));
161 break; 161 break;
162 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED: 162 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
163 callbacks->onError(new blink::WebSyncError( 163 callbacks->onError(blink::WebSyncError(
164 blink::WebSyncError::ErrorTypeNoPermission, 164 blink::WebSyncError::ErrorTypeNoPermission,
165 "Cannot register a sync event without a window client.")); 165 "Cannot register a sync event without a window client."));
166 break; 166 break;
167 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 167 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
168 callbacks->onError( 168 callbacks->onError(
169 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 169 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
170 "No service worker is active.")); 170 "No service worker is active."));
171 break; 171 break;
172 } 172 }
173 } 173 }
174 174
175 void BackgroundSyncProvider::UnregisterCallback( 175 void BackgroundSyncProvider::UnregisterCallback(
176 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, 176 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks,
177 BackgroundSyncError error) { 177 BackgroundSyncError error) {
178 // TODO(iclelland): Determine the correct error message to return in each case 178 // TODO(iclelland): Determine the correct error message to return in each case
179 switch (error) { 179 switch (error) {
180 case BACKGROUND_SYNC_ERROR_NONE: 180 case BACKGROUND_SYNC_ERROR_NONE:
181 callbacks->onSuccess(new bool(true)); 181 callbacks->onSuccess(true);
182 break; 182 break;
183 case BACKGROUND_SYNC_ERROR_NOT_FOUND: 183 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
184 callbacks->onSuccess(new bool(false)); 184 callbacks->onSuccess(false);
185 break; 185 break;
186 case BACKGROUND_SYNC_ERROR_STORAGE: 186 case BACKGROUND_SYNC_ERROR_STORAGE:
187 callbacks->onError( 187 callbacks->onError(
188 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 188 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
189 "Background Sync is disabled.")); 189 "Background Sync is disabled."));
190 break; 190 break;
191 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED: 191 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
192 // This error should never be returned from 192 // This error should never be returned from
193 // BackgroundSyncManager::Unregister 193 // BackgroundSyncManager::Unregister
194 NOTREACHED(); 194 NOTREACHED();
195 break; 195 break;
196 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 196 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
197 callbacks->onError( 197 callbacks->onError(
198 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 198 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
199 "No service worker is active.")); 199 "No service worker is active."));
200 break; 200 break;
201 } 201 }
202 } 202 }
203 203
204 void BackgroundSyncProvider::GetRegistrationCallback( 204 void BackgroundSyncProvider::GetRegistrationCallback(
205 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, 205 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
206 BackgroundSyncError error, 206 BackgroundSyncError error,
207 const SyncRegistrationPtr& options) { 207 const SyncRegistrationPtr& options) {
208 // TODO(iclelland): Determine the correct error message to return in each case 208 // TODO(iclelland): Determine the correct error message to return in each case
209 scoped_ptr<blink::WebSyncRegistration> result; 209 scoped_ptr<blink::WebSyncRegistration> result;
210 switch (error) { 210 switch (error) {
211 case BACKGROUND_SYNC_ERROR_NONE: 211 case BACKGROUND_SYNC_ERROR_NONE:
212 if (!options.is_null()) 212 if (!options.is_null())
213 result = 213 result =
214 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options); 214 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options);
215 callbacks->onSuccess(result.release()); 215 callbacks->onSuccess(blink::adoptWebPtr(result.release()));
216 break; 216 break;
217 case BACKGROUND_SYNC_ERROR_NOT_FOUND: 217 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
218 callbacks->onSuccess(nullptr); 218 callbacks->onSuccess(nullptr);
219 break; 219 break;
220 case BACKGROUND_SYNC_ERROR_STORAGE: 220 case BACKGROUND_SYNC_ERROR_STORAGE:
221 callbacks->onError( 221 callbacks->onError(
222 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 222 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
223 "Background Sync is disabled.")); 223 "Background Sync is disabled."));
224 break; 224 break;
225 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED: 225 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
226 // This error should never be returned from 226 // This error should never be returned from
227 // BackgroundSyncManager::GetRegistration 227 // BackgroundSyncManager::GetRegistration
228 NOTREACHED(); 228 NOTREACHED();
229 break; 229 break;
230 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 230 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
231 callbacks->onError( 231 callbacks->onError(
232 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 232 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
233 "No service worker is active.")); 233 "No service worker is active."));
234 break; 234 break;
235 } 235 }
236 } 236 }
237 237
238 void BackgroundSyncProvider::GetRegistrationsCallback( 238 void BackgroundSyncProvider::GetRegistrationsCallback(
239 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, 239 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks,
240 BackgroundSyncError error, 240 BackgroundSyncError error,
241 const mojo::Array<SyncRegistrationPtr>& registrations) { 241 const mojo::Array<SyncRegistrationPtr>& registrations) {
242 // TODO(iclelland): Determine the correct error message to return in each case 242 // TODO(iclelland): Determine the correct error message to return in each case
243 blink::WebVector<blink::WebSyncRegistration*>* results;
244 switch (error) { 243 switch (error) {
245 case BACKGROUND_SYNC_ERROR_NONE: 244 case BACKGROUND_SYNC_ERROR_NONE: {
246 results = new blink::WebVector<blink::WebSyncRegistration*>( 245 blink::WebVector<blink::WebSyncRegistration*> results(
247 registrations.size()); 246 registrations.size());
248 for (size_t i = 0; i < registrations.size(); ++i) { 247 for (size_t i = 0; i < registrations.size(); ++i) {
249 (*results)[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>( 248 results[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(
250 registrations[i]).release(); 249 registrations[i])
250 .release();
251 } 251 }
252 callbacks->onSuccess(results); 252 callbacks->onSuccess(results);
253 break; 253 break;
254 }
254 case BACKGROUND_SYNC_ERROR_NOT_FOUND: 255 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
255 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED: 256 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
256 // These errors should never be returned from 257 // These errors should never be returned from
257 // BackgroundSyncManager::GetRegistrations 258 // BackgroundSyncManager::GetRegistrations
258 NOTREACHED(); 259 NOTREACHED();
259 break; 260 break;
260 case BACKGROUND_SYNC_ERROR_STORAGE: 261 case BACKGROUND_SYNC_ERROR_STORAGE:
261 callbacks->onError( 262 callbacks->onError(
262 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 263 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
263 "Background Sync is disabled.")); 264 "Background Sync is disabled."));
264 break; 265 break;
265 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 266 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
266 callbacks->onError( 267 callbacks->onError(
267 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 268 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
268 "No service worker is active.")); 269 "No service worker is active."));
269 break; 270 break;
270 } 271 }
271 } 272 }
272 273
273 void BackgroundSyncProvider::GetPermissionStatusCallback( 274 void BackgroundSyncProvider::GetPermissionStatusCallback(
274 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks, 275 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks,
275 BackgroundSyncError error, 276 BackgroundSyncError error,
276 PermissionStatus status) { 277 PermissionStatus status) {
277 // TODO(iclelland): Determine the correct error message to return in each case 278 // TODO(iclelland): Determine the correct error message to return in each case
278 switch (error) { 279 switch (error) {
279 case BACKGROUND_SYNC_ERROR_NONE: 280 case BACKGROUND_SYNC_ERROR_NONE:
280 switch (status) { 281 switch (status) {
281 case PERMISSION_STATUS_GRANTED: 282 case PERMISSION_STATUS_GRANTED:
282 callbacks->onSuccess(new blink::WebSyncPermissionStatus( 283 callbacks->onSuccess(blink::WebSyncPermissionStatusGranted);
283 blink::WebSyncPermissionStatusGranted));
284 break; 284 break;
285 case PERMISSION_STATUS_DENIED: 285 case PERMISSION_STATUS_DENIED:
286 callbacks->onSuccess(new blink::WebSyncPermissionStatus( 286 callbacks->onSuccess(blink::WebSyncPermissionStatusDenied);
287 blink::WebSyncPermissionStatusDenied));
288 break; 287 break;
289 case PERMISSION_STATUS_ASK: 288 case PERMISSION_STATUS_ASK:
290 callbacks->onSuccess(new blink::WebSyncPermissionStatus( 289 callbacks->onSuccess(blink::WebSyncPermissionStatusPrompt);
291 blink::WebSyncPermissionStatusPrompt));
292 break; 290 break;
293 } 291 }
294 break; 292 break;
295 case BACKGROUND_SYNC_ERROR_NOT_FOUND: 293 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
296 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED: 294 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
297 // These errors should never be returned from 295 // These errors should never be returned from
298 // BackgroundSyncManager::GetPermissionStatus 296 // BackgroundSyncManager::GetPermissionStatus
299 NOTREACHED(); 297 NOTREACHED();
300 break; 298 break;
301 case BACKGROUND_SYNC_ERROR_STORAGE: 299 case BACKGROUND_SYNC_ERROR_STORAGE:
302 callbacks->onError( 300 callbacks->onError(
303 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 301 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
304 "Background Sync is disabled.")); 302 "Background Sync is disabled."));
305 break; 303 break;
306 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 304 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
307 callbacks->onError( 305 callbacks->onError(
308 new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 306 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
309 "No service worker is active.")); 307 "No service worker is active."));
310 break; 308 break;
311 } 309 }
312 } 310 }
313 311
314 BackgroundSyncServicePtr& 312 BackgroundSyncServicePtr&
315 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { 313 BackgroundSyncProvider::GetBackgroundSyncServicePtr() {
316 if (!background_sync_service_.get()) { 314 if (!background_sync_service_.get()) {
317 service_registry_->ConnectToRemoteService( 315 service_registry_->ConnectToRemoteService(
318 mojo::GetProxy(&background_sync_service_)); 316 mojo::GetProxy(&background_sync_service_));
319 } 317 }
320 return background_sync_service_; 318 return background_sync_service_;
321 } 319 }
322 320
323 } // namespace content 321 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698