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