| 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 blink::WebSyncRegistration::Periodicity periodicity, | |
| 47 int64_t id, | |
| 48 const blink::WebString& tag, | |
| 49 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 50 blink::WebSyncUnregistrationCallbacks* callbacks) override; | |
| 51 void getRegistration( | |
| 52 blink::WebSyncRegistration::Periodicity, | |
| 53 const blink::WebString& tag, | |
| 54 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 55 blink::WebSyncRegistrationCallbacks* callbacks) override; | |
| 56 void getRegistrations( | |
| 57 blink::WebSyncRegistration::Periodicity periodicity, | |
| 58 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 59 blink::WebSyncGetRegistrationsCallbacks* callbacks) override; | |
| 60 void getPermissionStatus( | |
| 61 blink::WebSyncRegistration::Periodicity periodicity, | |
| 62 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 63 blink::WebSyncGetPermissionStatusCallbacks* callbacks) override; | |
| 64 void releaseRegistration(int64_t handle_id) override; | |
| 65 void notifyWhenDone( | |
| 66 int64_t handle_id, | |
| 67 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; | |
| 68 | |
| 69 // Given |handle_id|, ask the provider for a new handle with the same | |
| 70 // underlying registration. | |
| 71 void DuplicateRegistrationHandle( | |
| 72 int64 handle_id, | |
| 73 const DuplicateRegistrationHandleCallback& callback); | |
| 74 | |
| 75 // WorkerThread::Observer implementation. | |
| 76 void WillStopCurrentWorkerThread() override; | |
| 77 | |
| 78 private: | |
| 79 BackgroundSyncProviderThreadProxy( | |
| 80 base::SingleThreadTaskRunner* main_thread_task_runner, | |
| 81 BackgroundSyncProvider* sync_provider); | |
| 82 | |
| 83 virtual ~BackgroundSyncProviderThreadProxy(); | |
| 84 | |
| 85 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
| 86 | |
| 87 // This belongs to the renderer main thread, (created by BlinkPlatformImpl) | |
| 88 // and so should outlive the BackgroundSyncProviderThreadProxy, which is | |
| 89 // created for a worker thread. | |
| 90 BackgroundSyncProvider* sync_provider_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProviderThreadProxy); | |
| 93 }; | |
| 94 | |
| 95 } // namespace content | |
| 96 | |
| 97 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_THREAD_PROXY_H
_ | |
| OLD | NEW |