Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / renderer / background_sync / background_sync_client_impl.cc
blob65153b1b50a69ae6faae60eb2287a667dbc45f96
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
3 // found in the LICENSE file.
5 #include "content/renderer/background_sync/background_sync_client_impl.h"
7 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
8 #include "content/child/background_sync/background_sync_type_converters.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/WebSyncProvider.h"
13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegistration.h"
15 namespace content {
17 // static
18 void BackgroundSyncClientImpl::Create(
19 int64 service_worker_registration_id,
20 mojo::InterfaceRequest<BackgroundSyncServiceClient> request) {
21 new BackgroundSyncClientImpl(service_worker_registration_id, request.Pass());
24 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {}
26 BackgroundSyncClientImpl::BackgroundSyncClientImpl(
27 int64 service_worker_registration_id,
28 mojo::InterfaceRequest<BackgroundSyncServiceClient> request)
29 : service_worker_registration_id_(service_worker_registration_id),
30 binding_(this, request.Pass()) {}
32 void BackgroundSyncClientImpl::Sync(int handle_id,
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);
45 // TODO(jkarlin): Find a way to claim the handle safely without requiring a
46 // round-trip IPC.
47 provider->DuplicateRegistrationHandle(
48 handle_id, base::Bind(&BackgroundSyncClientImpl::SyncDidGetRegistration,
49 base::Unretained(this), callback));
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;
61 ServiceWorkerContextClient* client =
62 ServiceWorkerContextClient::ThreadSpecificInstance();
63 if (!client) {
64 callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED);
65 return;
68 scoped_ptr<blink::WebSyncRegistration> web_registration =
69 mojo::ConvertTo<scoped_ptr<blink::WebSyncRegistration>>(registration);
71 client->DispatchSyncEvent(*web_registration, callback);
74 } // namespace content