Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/renderer/background_sync/background_sync_client_impl.h" | 5 #include "content/renderer/background_sync/background_sync_client_impl.h" |
| 6 | 6 |
| 7 #include "content/child/background_sync/background_sync_provider_thread_proxy.h" | |
| 7 #include "content/child/background_sync/background_sync_type_converters.h" | 8 #include "content/child/background_sync/background_sync_type_converters.h" |
| 8 #include "content/renderer/service_worker/service_worker_context_client.h" | 9 #include "content/renderer/service_worker/service_worker_context_client.h" |
| 10 #include "third_party/WebKit/public/platform/Platform.h" | |
| 11 #include "third_party/WebKit/public/platform/WebThread.h" | |
| 12 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProv ider.h" | |
| 9 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" | 13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" |
| 10 | 14 |
| 11 namespace content { | 15 namespace content { |
| 12 | 16 |
| 13 // static | 17 // static |
| 14 void BackgroundSyncClientImpl::Create( | 18 void BackgroundSyncClientImpl::Create( |
| 19 int64 service_worker_registration_id, | |
| 15 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) { | 20 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) { |
| 16 new BackgroundSyncClientImpl(request.Pass()); | 21 new BackgroundSyncClientImpl(service_worker_registration_id, request.Pass()); |
| 17 } | 22 } |
| 18 | 23 |
| 19 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {} | 24 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {} |
| 20 | 25 |
| 21 BackgroundSyncClientImpl::BackgroundSyncClientImpl( | 26 BackgroundSyncClientImpl::BackgroundSyncClientImpl( |
| 27 int64 service_worker_registration_id, | |
| 22 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) | 28 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) |
| 23 : binding_(this, request.Pass()) {} | 29 : service_worker_registration_id_(service_worker_registration_id), |
| 30 binding_(this, request.Pass()) {} | |
| 24 | 31 |
| 25 void BackgroundSyncClientImpl::Sync(content::SyncRegistrationPtr registration, | 32 void BackgroundSyncClientImpl::Sync(int handle_id, |
| 26 const SyncCallback& callback) { | 33 const SyncCallback& callback) { |
| 34 DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread()); | |
| 35 // Get a registration for the given handle_id from the provider. This way | |
| 36 // the provider knows about the handle and can delete it once Blink releases | |
| 37 // it. | |
| 38 // TODO(jkarlin): Change the WebSyncPlatform to support | |
| 39 // DuplicateRegistrationHandle and then this cast can go. | |
| 40 BackgroundSyncProviderThreadProxy* provider = | |
| 41 static_cast<BackgroundSyncProviderThreadProxy*>( | |
| 42 blink::Platform::current()->backgroundSyncProvider()); | |
| 43 DCHECK(provider); | |
| 44 | |
| 45 // TODO(jkarlin): Find a way to claim the handle safely without requiring a | |
|
michaeln
2015/09/10 21:21:33
I guess the trouble is having to get a new id valu
jkarlin
2015/09/10 23:26:01
Acknowledged.
| |
| 46 // round-trip IPC. | |
| 47 provider->DuplicateRegistrationHandle( | |
| 48 handle_id, base::Bind(&BackgroundSyncClientImpl::SyncDidGetRegistration, | |
| 49 base::Unretained(this), callback)); | |
| 50 } | |
| 51 | |
| 52 void BackgroundSyncClientImpl::SyncDidGetRegistration( | |
| 53 const SyncCallback& callback, | |
| 54 BackgroundSyncError error, | |
| 55 const SyncRegistrationPtr& registration) { | |
| 56 if (error != BACKGROUND_SYNC_ERROR_NONE) { | |
| 57 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); | |
| 58 return; | |
| 59 } | |
| 60 | |
| 27 ServiceWorkerContextClient* client = | 61 ServiceWorkerContextClient* client = |
| 28 ServiceWorkerContextClient::ThreadSpecificInstance(); | 62 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 29 if (!client) { | 63 if (!client) { |
| 30 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); | 64 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED); |
| 31 return; | 65 return; |
| 32 } | 66 } |
| 33 scoped_ptr<blink::WebSyncRegistration> reg = | 67 |
| 68 scoped_ptr<blink::WebSyncRegistration> web_registration = | |
| 34 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration); | 69 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration); |
| 35 client->DispatchSyncEvent(*reg, callback); | 70 |
| 71 client->DispatchSyncEvent(*web_registration, callback); | |
| 36 } | 72 } |
| 37 | 73 |
| 38 } // namespace content | 74 } // namespace content |
| OLD | NEW |