Commit 93178c5d authored by iclelland's avatar iclelland Committed by Commit bot

[Background Sync] Add proper error status to API calls and callbacks

BUG=484306

Review URL: https://codereview.chromium.org/1131943005

Cr-Commit-Position: refs/heads/master@{#329625}
parent 9b3ffc87
...@@ -93,7 +93,7 @@ void BackgroundSyncProvider::getRegistration( ...@@ -93,7 +93,7 @@ void BackgroundSyncProvider::getRegistration(
GetBackgroundSyncServicePtr()->GetRegistration( GetBackgroundSyncServicePtr()->GetRegistration(
mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), tag.utf8(), mojo::ConvertTo<BackgroundSyncPeriodicity>(periodicity), tag.utf8(),
service_worker_registration_id, service_worker_registration_id,
base::Bind(&BackgroundSyncProvider::RegisterCallback, base::Bind(&BackgroundSyncProvider::GetRegistrationCallback,
base::Unretained(this), base::Passed(callbacksPtr.Pass()))); base::Unretained(this), base::Passed(callbacksPtr.Pass())));
} }
...@@ -118,42 +118,117 @@ void BackgroundSyncProvider::getRegistrations( ...@@ -118,42 +118,117 @@ void BackgroundSyncProvider::getRegistrations(
void BackgroundSyncProvider::RegisterCallback( void BackgroundSyncProvider::RegisterCallback(
scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
BackgroundSyncError error,
const SyncRegistrationPtr& options) { const SyncRegistrationPtr& options) {
// TODO(iclelland): Pass through the various errors from the manager to here // TODO(iclelland): Determine the correct error message to return in each case
// and handle them appropriately.
scoped_ptr<blink::WebSyncRegistration> result; scoped_ptr<blink::WebSyncRegistration> result;
if (!options.is_null()) switch (error) {
result = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options); case BACKGROUND_SYNC_ERROR_NONE:
if (!options.is_null())
callbacks->onSuccess(result.release()); result =
mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options);
callbacks->onSuccess(result.release());
break;
case BACKGROUND_SYNC_ERROR_NOT_FOUND:
NOTREACHED();
break;
case BACKGROUND_SYNC_ERROR_STORAGE:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"Background Sync is disabled."));
break;
case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"No service worker is active."));
break;
}
} }
void BackgroundSyncProvider::UnregisterCallback( void BackgroundSyncProvider::UnregisterCallback(
scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks,
bool success) { BackgroundSyncError error) {
// TODO(iclelland): Pass through the various errors from the manager to here // TODO(iclelland): Determine the correct error message to return in each case
// and handle them appropriately. switch (error) {
if (success) { case BACKGROUND_SYNC_ERROR_NONE:
callbacks->onSuccess(new bool(success)); callbacks->onSuccess(new bool(true));
} else { break;
callbacks->onError( case BACKGROUND_SYNC_ERROR_NOT_FOUND:
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown, callbacks->onSuccess(new bool(false));
"Sync registration does not exist")); break;
case BACKGROUND_SYNC_ERROR_STORAGE:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"Background Sync is disabled."));
break;
case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"No service worker is active."));
break;
}
}
void BackgroundSyncProvider::GetRegistrationCallback(
scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
BackgroundSyncError error,
const SyncRegistrationPtr& options) {
// TODO(iclelland): Determine the correct error message to return in each case
scoped_ptr<blink::WebSyncRegistration> result;
switch (error) {
case BACKGROUND_SYNC_ERROR_NONE:
if (!options.is_null())
result =
mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(options);
callbacks->onSuccess(result.release());
break;
case BACKGROUND_SYNC_ERROR_NOT_FOUND:
callbacks->onSuccess(nullptr);
break;
case BACKGROUND_SYNC_ERROR_STORAGE:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"Background Sync is disabled."));
break;
case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"No service worker is active."));
break;
} }
} }
void BackgroundSyncProvider::GetRegistrationsCallback( void BackgroundSyncProvider::GetRegistrationsCallback(
scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks,
BackgroundSyncError error,
const mojo::Array<SyncRegistrationPtr>& registrations) { const mojo::Array<SyncRegistrationPtr>& registrations) {
// TODO(iclelland): Pass through the various errors from the manager to here // TODO(iclelland): Determine the correct error message to return in each case
// and handle them appropriately. blink::WebVector<blink::WebSyncRegistration*>* results;
blink::WebVector<blink::WebSyncRegistration*>* results = switch (error) {
new blink::WebVector<blink::WebSyncRegistration*>(registrations.size()); case BACKGROUND_SYNC_ERROR_NONE:
for (size_t i = 0; i < registrations.size(); ++i) { results = new blink::WebVector<blink::WebSyncRegistration*>(
(*results)[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>( registrations.size());
registrations[i]).release(); for (size_t i = 0; i < registrations.size(); ++i) {
(*results)[i] = mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(
registrations[i]).release();
}
callbacks->onSuccess(results);
case BACKGROUND_SYNC_ERROR_NOT_FOUND:
// This error should never be returned from
// BackgroundSyncManager::GetRegistrations
NOTREACHED();
break;
case BACKGROUND_SYNC_ERROR_STORAGE:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"Background Sync is disabled."));
break;
case BACKGROUND_SYNC_ERROR_NO_SERVICE_WORKER:
callbacks->onError(
new blink::WebSyncError(blink::WebSyncError::ErrorTypeUnknown,
"No service worker is active."));
break;
} }
callbacks->onSuccess(results);
} }
BackgroundSyncServicePtr& BackgroundSyncServicePtr&
......
...@@ -52,12 +52,18 @@ class BackgroundSyncProvider : public blink::WebSyncProvider { ...@@ -52,12 +52,18 @@ class BackgroundSyncProvider : public blink::WebSyncProvider {
// Callback handlers // Callback handlers
void RegisterCallback( void RegisterCallback(
scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
BackgroundSyncError error,
const SyncRegistrationPtr& options); const SyncRegistrationPtr& options);
void UnregisterCallback( void UnregisterCallback(
scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks,
bool success); BackgroundSyncError error);
void GetRegistrationCallback(
scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks,
BackgroundSyncError error,
const SyncRegistrationPtr& options);
void GetRegistrationsCallback( void GetRegistrationsCallback(
scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks,
BackgroundSyncError error,
const mojo::Array<SyncRegistrationPtr>& registrations); const mojo::Array<SyncRegistrationPtr>& registrations);
// Helper method that returns an initialized BackgroundSyncServicePtr. // Helper method that returns an initialized BackgroundSyncServicePtr.
......
...@@ -6,17 +6,25 @@ module content; ...@@ -6,17 +6,25 @@ module content;
import "content/public/common/background_sync.mojom"; import "content/public/common/background_sync.mojom";
enum BackgroundSyncError {
NONE,
STORAGE,
NOT_FOUND,
NO_SERVICE_WORKER,
MAX=NO_SERVICE_WORKER
};
interface BackgroundSyncService { interface BackgroundSyncService {
Register(SyncRegistration options, int64 service_worker_registration_id) Register(SyncRegistration options, int64 service_worker_registration_id)
=> (SyncRegistration options); => (BackgroundSyncError err, SyncRegistration options);
GetRegistration(BackgroundSyncPeriodicity periodicity, string tag, GetRegistration(BackgroundSyncPeriodicity periodicity, string tag,
int64 service_worker_registration_id) int64 service_worker_registration_id)
=> (SyncRegistration? registration); => (BackgroundSyncError err, SyncRegistration? registration);
GetRegistrations(BackgroundSyncPeriodicity periodicity, GetRegistrations(BackgroundSyncPeriodicity periodicity,
int64 service_worker_registration_id) int64 service_worker_registration_id)
=> (array<SyncRegistration> registrations); => (BackgroundSyncError err, array<SyncRegistration> registrations);
Unregister(BackgroundSyncPeriodicity periodicity, int64 id, string tag, Unregister(BackgroundSyncPeriodicity periodicity, int64 id, string tag,
int64 service_worker_registration_id) => (bool success); int64 service_worker_registration_id) => (BackgroundSyncError err);
}; };
interface BackgoundSyncServiceClient { interface BackgoundSyncServiceClient {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment