| 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_H_ | |
| 6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "content/public/child/worker_thread.h" | |
| 15 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProv
ider.h" | |
| 16 #include "third_party/WebKit/public/platform/modules/background_sync/background_
sync.mojom.h" | |
| 17 | |
| 18 namespace base { | |
| 19 class SingleThreadTaskRunner; | |
| 20 } | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 // The BackgroundSyncProvider is called by the SyncManager and SyncRegistration | |
| 25 // objects and communicates with the BackgroundSyncManager object in the browser | |
| 26 // process. Each thread will have its own instance (e.g. main thread, worker | |
| 27 // threads), instantiated as needed by BlinkPlatformImpl. Each instance of | |
| 28 // the provider creates a new mojo connection to a new | |
| 29 // BackgroundSyncManagerImpl, which then talks to the BackgroundSyncManager | |
| 30 // object. | |
| 31 class BackgroundSyncProvider : public blink::WebSyncProvider, | |
| 32 public WorkerThread::Observer { | |
| 33 public: | |
| 34 // Constructor made public to allow BlinkPlatformImpl to own a copy for the | |
| 35 // main thread. Everyone else should use GetOrCreateThreadSpecificInstance(). | |
| 36 explicit BackgroundSyncProvider( | |
| 37 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); | |
| 38 | |
| 39 ~BackgroundSyncProvider() override; | |
| 40 | |
| 41 // Returns thread-specific instance (if exists). Otherwise, a new instance | |
| 42 // will be created for the thread, except when called for a worker thread that | |
| 43 // has already been stopped. | |
| 44 static BackgroundSyncProvider* GetOrCreateThreadSpecificInstance( | |
| 45 base::SingleThreadTaskRunner* main_thread_task_runner); | |
| 46 | |
| 47 // blink::WebSyncProvider implementation | |
| 48 void registerBackgroundSync( | |
| 49 const blink::WebSyncRegistration* options, | |
| 50 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 51 blink::WebSyncRegistrationCallbacks* callbacks) override; | |
| 52 void getRegistrations( | |
| 53 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 54 blink::WebSyncGetRegistrationsCallbacks* callbacks) override; | |
| 55 | |
| 56 // WorkerThread::Observer implementation. | |
| 57 void WillStopCurrentWorkerThread() override; | |
| 58 | |
| 59 private: | |
| 60 // Callback handlers | |
| 61 void RegisterCallback( | |
| 62 std::unique_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | |
| 63 blink::mojom::BackgroundSyncError error, | |
| 64 blink::mojom::SyncRegistrationPtr options); | |
| 65 void GetRegistrationsCallback( | |
| 66 std::unique_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, | |
| 67 blink::mojom::BackgroundSyncError error, | |
| 68 mojo::Array<blink::mojom::SyncRegistrationPtr> registrations); | |
| 69 | |
| 70 // Helper method that returns an initialized BackgroundSyncServicePtr. | |
| 71 blink::mojom::BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); | |
| 72 | |
| 73 blink::mojom::BackgroundSyncServicePtr background_sync_service_; | |
| 74 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); | |
| 77 }; | |
| 78 | |
| 79 } // namespace content | |
| 80 | |
| 81 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | |
| OLD | NEW |