OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_ | |
6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H_ | |
7 | |
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/WebSyncProv
ider.h" | |
13 | |
14 namespace base { | |
15 class SingleThreadTaskRunner; | |
16 } | |
17 | |
18 namespace content { | |
19 | |
20 class BackgroundSyncProvider; | |
21 | |
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. | |
25 // | |
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 { | |
31 public: | |
32 using DuplicateRegistrationHandleCallback = | |
33 base::Callback<void(BackgroundSyncError, SyncRegistrationPtr)>; | |
34 | |
35 static BackgroundSyncProviderThreadProxy* GetThreadInstance( | |
36 base::SingleThreadTaskRunner* main_thread_task_runner, | |
37 BackgroundSyncProvider* permissions_dispatcher); | |
38 | |
39 // blink::WebSyncProvider implementation | |
40 void registerBackgroundSync( | |
41 const blink::WebSyncRegistration* options, | |
42 blink::WebServiceWorkerRegistration* service_worker_registration, | |
43 bool requested_from_service_worker, | |
44 blink::WebSyncRegistrationCallbacks* callbacks) override; | |
45 void unregisterBackgroundSync( | |
46 int64_t handle_id, | |
47 blink::WebServiceWorkerRegistration* service_worker_registration, | |
48 blink::WebSyncUnregistrationCallbacks* callbacks) override; | |
49 void getRegistration( | |
50 blink::WebSyncRegistration::Periodicity, | |
51 const blink::WebString& tag, | |
52 blink::WebServiceWorkerRegistration* service_worker_registration, | |
53 blink::WebSyncRegistrationCallbacks* callbacks) override; | |
54 void getRegistrations( | |
55 blink::WebSyncRegistration::Periodicity periodicity, | |
56 blink::WebServiceWorkerRegistration* service_worker_registration, | |
57 blink::WebSyncGetRegistrationsCallbacks* callbacks) override; | |
58 void getPermissionStatus( | |
59 blink::WebSyncRegistration::Periodicity periodicity, | |
60 blink::WebServiceWorkerRegistration* service_worker_registration, | |
61 blink::WebSyncGetPermissionStatusCallbacks* callbacks) override; | |
62 void releaseRegistration(int64_t handle_id) override; | |
63 void notifyWhenDone( | |
64 int64_t handle_id, | |
65 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; | |
66 | |
67 // Given |handle_id|, ask the provider for a new handle with the same | |
68 // underlying registration. | |
69 void DuplicateRegistrationHandle( | |
70 int64_t handle_id, | |
71 const DuplicateRegistrationHandleCallback& callback); | |
72 | |
73 // WorkerThread::Observer implementation. | |
74 void WillStopCurrentWorkerThread() override; | |
75 | |
76 private: | |
77 BackgroundSyncProviderThreadProxy( | |
78 base::SingleThreadTaskRunner* main_thread_task_runner, | |
79 BackgroundSyncProvider* sync_provider); | |
80 | |
81 ~BackgroundSyncProviderThreadProxy() override; | |
82 | |
83 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
84 | |
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_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProviderThreadProxy); | |
91 }; | |
92 | |
93 } // namespace content | |
94 | |
95 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H
_ | |
OLD | NEW |