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 #ifndef CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_
6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_
8 #include "base/macros.h"
9 #include "content/child/worker_task_runner.h"
10 #include "content/common/background_sync_service.mojom.h"
11 #include "content/public/child/worker_thread.h"
12 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProvider.h"
15 class SingleThreadTaskRunner
;
20 class BackgroundSyncProvider
;
22 // BackgroundSyncProviderThreadProxy is a proxy to the BackgroundSyncProvider
23 // for callers running on a different thread than the main thread. There is one
24 // instance per worker thread.
26 // This class handles all of the thread switching, jumping to the main thread to
27 // call the WebSyncProvider methods, and wrapping the callbacks passed in with
28 // code to switch back to the original calling thread.
29 class BackgroundSyncProviderThreadProxy
: public blink::WebSyncProvider
,
30 public WorkerThread::Observer
{
32 static BackgroundSyncProviderThreadProxy
* GetThreadInstance(
33 base::SingleThreadTaskRunner
* main_thread_task_runner
,
34 BackgroundSyncProvider
* permissions_dispatcher
);
36 // blink::WebSyncProvider implementation
37 void registerBackgroundSync(
38 const blink::WebSyncRegistration
* options
,
39 blink::WebServiceWorkerRegistration
* service_worker_registration
,
40 bool requested_from_service_worker
,
41 blink::WebSyncRegistrationCallbacks
* callbacks
) override
;
42 void unregisterBackgroundSync(
43 blink::WebSyncRegistration::Periodicity periodicity
,
45 const blink::WebString
& tag
,
46 blink::WebServiceWorkerRegistration
* service_worker_registration
,
47 blink::WebSyncUnregistrationCallbacks
* callbacks
) override
;
49 blink::WebSyncRegistration::Periodicity
,
50 const blink::WebString
& tag
,
51 blink::WebServiceWorkerRegistration
* service_worker_registration
,
52 blink::WebSyncRegistrationCallbacks
* callbacks
) override
;
53 void getRegistrations(
54 blink::WebSyncRegistration::Periodicity periodicity
,
55 blink::WebServiceWorkerRegistration
* service_worker_registration
,
56 blink::WebSyncGetRegistrationsCallbacks
* callbacks
) override
;
57 void getPermissionStatus(
58 blink::WebSyncRegistration::Periodicity periodicity
,
59 blink::WebServiceWorkerRegistration
* service_worker_registration
,
60 blink::WebSyncGetPermissionStatusCallbacks
* callbacks
) override
;
61 void releaseRegistration(int64_t handle_id
) override
;
64 blink::WebSyncNotifyWhenDoneCallbacks
* callbacks
) override
;
66 // Given |handle_id|, ask the provider for a new handle with the same
67 // underlying registration.
68 void DuplicateRegistrationHandle(
70 const BackgroundSyncService::DuplicateRegistrationHandleCallback
&
73 // WorkerThread::Observer implementation.
74 void WillStopCurrentWorkerThread() override
;
77 BackgroundSyncProviderThreadProxy(
78 base::SingleThreadTaskRunner
* main_thread_task_runner
,
79 BackgroundSyncProvider
* sync_provider
);
81 virtual ~BackgroundSyncProviderThreadProxy();
83 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
85 // This belongs to the renderer main thread, (created by BlinkPlatformImpl)
86 // and so should outlive the BackgroundSyncProviderThreadProxy, which is
87 // created for a worker thread.
88 BackgroundSyncProvider
* sync_provider_
;
90 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProviderThreadProxy
);
93 } // namespace content
95 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_