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

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

Issue 1344843003: [BackgroundSync] Add browser side support for SyncRegistration.done (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ncn_max
Patch Set: Rebase Created 5 years, 3 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
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 142 void BackgroundSyncProvider::releaseRegistration(int64_t handle_id) {
143 GetBackgroundSyncServicePtr()->ReleaseRegistration(handle_id); 143 GetBackgroundSyncServicePtr()->ReleaseRegistration(handle_id);
144 } 144 }
145 145
146 void BackgroundSyncProvider::notifyWhenDone(
147 int64_t handle_id,
148 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) {
149 DCHECK(callbacks);
150
151 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacksPtr(callbacks);
michaeln 2015/09/17 21:44:12 nit: callbacks_ptr
jkarlin 2015/09/18 12:03:20 Done.
152
153 // base::Unretained is safe here, as the mojo channel will be deleted (and
154 // will wipe its callbacks) before 'this' is deleted.
155 GetBackgroundSyncServicePtr()->NotifyWhenDone(
156 handle_id,
157 base::Bind(&BackgroundSyncProvider::NotifyWhenDoneCallback,
158 base::Unretained(this), base::Passed(callbacksPtr.Pass())));
159 }
160
146 void BackgroundSyncProvider::DuplicateRegistrationHandle( 161 void BackgroundSyncProvider::DuplicateRegistrationHandle(
147 int handle_id, 162 int handle_id,
148 const BackgroundSyncService::DuplicateRegistrationHandleCallback& 163 const BackgroundSyncService::DuplicateRegistrationHandleCallback&
149 callback) { 164 callback) {
150 GetBackgroundSyncServicePtr()->DuplicateRegistrationHandle(handle_id, 165 GetBackgroundSyncServicePtr()->DuplicateRegistrationHandle(handle_id,
151 callback); 166 callback);
152 } 167 }
153 168
154 void BackgroundSyncProvider::RegisterCallback( 169 void BackgroundSyncProvider::RegisterCallback(
155 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, 170 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 "Background Sync is disabled.")); 330 "Background Sync is disabled."));
316 break; 331 break;
317 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER: 332 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
318 callbacks->onError( 333 callbacks->onError(
319 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, 334 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
320 "No service worker is active.")); 335 "No service worker is active."));
321 break; 336 break;
322 } 337 }
323 } 338 }
324 339
340 void BackgroundSyncProvider::NotifyWhenDoneCallback(
341 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks,
342 BackgroundSyncError error,
343 BackgroundSyncState state) {
344 switch (error) {
345 case BACKGROUND_SYNC_ERROR_NONE:
346 switch (state) {
347 case BACKGROUND_SYNC_STATE_PENDING:
348 case BACKGROUND_SYNC_STATE_FIRING:
349 case BACKGROUND_SYNC_STATE_UNREGISTERED_WHILE_FIRING:
350 NOTREACHED();
351 break;
352 case BACKGROUND_SYNC_STATE_SUCCESS:
353 callbacks->onSuccess(true);
354 break;
355 case BACKGROUND_SYNC_STATE_FAILED:
356 case BACKGROUND_SYNC_STATE_UNREGISTERED:
357 callbacks->onSuccess(false);
358 break;
359 }
360 break;
361 case BACKGROUND_SYNC_ERROR_NOT_FOUND:
362 case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
363 NOTREACHED();
364 break;
365 case BACKGROUND_SYNC_ERROR_STORAGE:
366 callbacks->onError(
367 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
368 "Background Sync is disabled."));
369 break;
370 case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
371 callbacks->onError(
372 blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
373 "No service worker is active."));
374 break;
375 }
376 }
377
325 BackgroundSyncServicePtr& 378 BackgroundSyncServicePtr&
326 BackgroundSyncProvider::GetBackgroundSyncServicePtr() { 379 BackgroundSyncProvider::GetBackgroundSyncServicePtr() {
327 if (!background_sync_service_.get()) { 380 if (!background_sync_service_.get()) {
328 service_registry_->ConnectToRemoteService( 381 service_registry_->ConnectToRemoteService(
329 mojo::GetProxy(&background_sync_service_)); 382 mojo::GetProxy(&background_sync_service_));
330 } 383 }
331 return background_sync_service_; 384 return background_sync_service_;
332 } 385 }
333 386
334 } // namespace content 387 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698