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/public/child/worker_thread.h"
11 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProvider.h"
14 class SingleThreadTaskRunner
;
19 class BackgroundSyncProvider
;
21 // BackgroundSyncProviderThreadProxy is a proxy to the BackgroundSyncProvider
22 // for callers running on a different thread than the main thread. There is one
23 // instance per worker thread.
25 // This class handles all of the thread switching, jumping to the main thread to
26 // call the WebSyncProvider methods, and wrapping the callbacks passed in with
27 // code to switch back to the original calling thread.
28 class BackgroundSyncProviderThreadProxy
: public blink::WebSyncProvider
,
29 public WorkerThread::Observer
{
31 static BackgroundSyncProviderThreadProxy
* GetThreadInstance(
32 base::SingleThreadTaskRunner
* main_thread_task_runner
,
33 BackgroundSyncProvider
* permissions_dispatcher
);
35 // blink::WebSyncProvider implementation
36 void registerBackgroundSync(
37 const blink::WebSyncRegistration
* options
,
38 blink::WebServiceWorkerRegistration
* service_worker_registration
,
39 bool requested_from_service_worker
,
40 blink::WebSyncRegistrationCallbacks
* callbacks
);
41 void unregisterBackgroundSync(
42 blink::WebSyncRegistration::Periodicity periodicity
,
44 const blink::WebString
& tag
,
45 blink::WebServiceWorkerRegistration
* service_worker_registration
,
46 blink::WebSyncUnregistrationCallbacks
* callbacks
);
48 blink::WebSyncRegistration::Periodicity
,
49 const blink::WebString
& tag
,
50 blink::WebServiceWorkerRegistration
* service_worker_registration
,
51 blink::WebSyncRegistrationCallbacks
* callbacks
);
52 void getRegistrations(
53 blink::WebSyncRegistration::Periodicity periodicity
,
54 blink::WebServiceWorkerRegistration
* service_worker_registration
,
55 blink::WebSyncGetRegistrationsCallbacks
* callbacks
);
56 void getPermissionStatus(
57 blink::WebSyncRegistration::Periodicity periodicity
,
58 blink::WebServiceWorkerRegistration
* service_worker_registration
,
59 blink::WebSyncGetPermissionStatusCallbacks
* callbacks
);
61 // WorkerThread::Observer implementation.
62 void WillStopCurrentWorkerThread() override
;
65 BackgroundSyncProviderThreadProxy(
66 base::SingleThreadTaskRunner
* main_thread_task_runner
,
67 BackgroundSyncProvider
* sync_provider
);
69 virtual ~BackgroundSyncProviderThreadProxy();
71 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner_
;
73 // This belongs to the renderer main thread, (created by BlinkPlatformImpl)
74 // and so should outlive the BackgroundSyncProviderThreadProxy, which is
75 // created for a worker thread.
76 BackgroundSyncProvider
* sync_provider_
;
78 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProviderThreadProxy
);
81 } // namespace content
83 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_