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

Unified 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: Address comments from PS7 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 side-by-side diff with in-line comments
Download patch
Index: content/child/background_sync/background_sync_provider.cc
diff --git a/content/child/background_sync/background_sync_provider.cc b/content/child/background_sync/background_sync_provider.cc
index 28ebdf33293d621e8a0f05625a434ab4771342c2..2742016c33430e298c5d811e3db0d02ed24517b2 100644
--- a/content/child/background_sync/background_sync_provider.cc
+++ b/content/child/background_sync/background_sync_provider.cc
@@ -143,6 +143,21 @@ void BackgroundSyncProvider::releaseRegistration(int64_t handle_id) {
GetBackgroundSyncServicePtr()->ReleaseRegistration(handle_id);
}
+void BackgroundSyncProvider::notifyWhenDone(
+ int64_t handle_id,
+ blink::WebSyncNotifyWhenDoneCallbacks* callbacks) {
+ DCHECK(callbacks);
+
+ scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks_ptr(callbacks);
+
+ // base::Unretained is safe here, as the mojo channel will be deleted (and
+ // will wipe its callbacks) before 'this' is deleted.
+ GetBackgroundSyncServicePtr()->NotifyWhenDone(
+ handle_id,
+ base::Bind(&BackgroundSyncProvider::NotifyWhenDoneCallback,
+ base::Unretained(this), base::Passed(callbacks_ptr.Pass())));
+}
+
void BackgroundSyncProvider::DuplicateRegistrationHandle(
int handle_id,
const BackgroundSyncService::DuplicateRegistrationHandleCallback&
@@ -322,6 +337,44 @@ void BackgroundSyncProvider::GetPermissionStatusCallback(
}
}
+void BackgroundSyncProvider::NotifyWhenDoneCallback(
+ scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks,
+ BackgroundSyncError error,
+ BackgroundSyncState state) {
+ switch (error) {
+ case BACKGROUND_SYNC_ERROR_NONE:
+ switch (state) {
+ case BACKGROUND_SYNC_STATE_PENDING:
+ case BACKGROUND_SYNC_STATE_FIRING:
+ case BACKGROUND_SYNC_STATE_UNREGISTERED_WHILE_FIRING:
+ NOTREACHED();
+ break;
+ case BACKGROUND_SYNC_STATE_SUCCESS:
+ callbacks->onSuccess(true);
+ break;
+ case BACKGROUND_SYNC_STATE_FAILED:
+ case BACKGROUND_SYNC_STATE_UNREGISTERED:
+ callbacks->onSuccess(false);
+ break;
+ }
+ break;
+ case BACKGROUND_SYNC_ERROR_NOT_FOUND:
+ case BACKGROUND_SYNC_ERROR_NOT_ALLOWED:
+ NOTREACHED();
+ break;
+ case BACKGROUND_SYNC_ERROR_STORAGE:
+ callbacks->onError(
+ blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
+ "Background Sync is disabled."));
+ break;
+ case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
+ callbacks->onError(
+ blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
+ "No service worker is active."));
+ break;
+ }
+}
+
BackgroundSyncServicePtr&
BackgroundSyncProvider::GetBackgroundSyncServicePtr() {
if (!background_sync_service_.get()) {

Powered by Google App Engine
This is Rietveld 408576698