Chromium Code Reviews| Index: content/renderer/background_sync/background_sync_client_impl.cc |
| diff --git a/content/renderer/background_sync/background_sync_client_impl.cc b/content/renderer/background_sync/background_sync_client_impl.cc |
| index 2eb1c40019da279279e19a5813eef0786524426b..7ee5bd932f2e944e995a3bb94e7143bbeb5e2e7a 100644 |
| --- a/content/renderer/background_sync/background_sync_client_impl.cc |
| +++ b/content/renderer/background_sync/background_sync_client_impl.cc |
| @@ -4,35 +4,70 @@ |
| #include "content/renderer/background_sync/background_sync_client_impl.h" |
| +#include "content/child/background_sync/background_sync_provider_thread_proxy.h" |
| #include "content/child/background_sync/background_sync_type_converters.h" |
| #include "content/renderer/service_worker/service_worker_context_client.h" |
| +#include "third_party/WebKit/public/platform/Platform.h" |
| +#include "third_party/WebKit/public/platform/WebThread.h" |
| +#include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProvider.h" |
| #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegistration.h" |
| namespace content { |
| // static |
| void BackgroundSyncClientImpl::Create( |
| + int64 service_worker_registration_id, |
| mojo::InterfaceRequest<BackgroundSyncServiceClient> request) { |
| - new BackgroundSyncClientImpl(request.Pass()); |
| + new BackgroundSyncClientImpl(service_worker_registration_id, request.Pass()); |
| } |
| BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {} |
| BackgroundSyncClientImpl::BackgroundSyncClientImpl( |
| + int64 service_worker_registration_id, |
| mojo::InterfaceRequest<BackgroundSyncServiceClient> request) |
| - : binding_(this, request.Pass()) {} |
| + : service_worker_registration_id_(service_worker_registration_id), |
| + binding_(this, request.Pass()) {} |
| -void BackgroundSyncClientImpl::Sync(content::SyncRegistrationPtr registration, |
| +void BackgroundSyncClientImpl::Sync(int64 handle_id, |
| const SyncCallback& callback) { |
| + DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread()); |
| + // Get a registration for the given handle_id from the provider. This way |
| + // the provider knows about the handle and can delete it once Blink releases |
| + // it. |
| + // TODO(jkarlin): Change the WebSyncPlatform to support |
| + // DuplicateRegistrationHandle and then this cast can go. |
| + BackgroundSyncProviderThreadProxy* provider = |
| + static_cast<BackgroundSyncProviderThreadProxy*>( |
| + blink::Platform::current()->backgroundSyncProvider()); |
| + DCHECK(provider); |
| + |
| + provider->DuplicateRegistrationHandle( |
|
michaeln
2015/08/28 02:53:11
Eeek, the thread and msg round trips are kinda ugl
jkarlin
2015/09/02 23:51:41
Agreed. On the plus side, this isn't a latency-sen
|
| + handle_id, service_worker_registration_id_, |
| + base::Bind(&BackgroundSyncClientImpl::SyncDidGetRegistration, |
| + base::Unretained(this), callback)); |
| +} |
| + |
| +void BackgroundSyncClientImpl::SyncDidGetRegistration( |
| + const SyncCallback& callback, |
| + BackgroundSyncError error, |
| + const SyncRegistrationPtr& registration) { |
| + if (error != BACKGROUND_SYNC_ERROR_NONE) { |
| + callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); |
| + return; |
| + } |
| + |
| ServiceWorkerContextClient* client = |
| ServiceWorkerContextClient::ThreadSpecificInstance(); |
| if (!client) { |
| callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); |
| return; |
| } |
| - scoped_ptr<blink::WebSyncRegistration> reg = |
| + |
| + scoped_ptr<blink::WebSyncRegistration> web_registration = |
| mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration); |
| - client->DispatchSyncEvent(*reg, callback); |
| + |
| + client->DispatchSyncEvent(*web_registration, callback); |
| } |
| } // namespace content |