OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | 5 #ifndef CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ |
6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | 6 #define CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "content/child/worker_task_runner.h" | |
12 #include "content/common/background_sync_service.mojom.h" | 11 #include "content/common/background_sync_service.mojom.h" |
| 12 #include "content/public/child/worker_thread.h" |
13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProv
ider.h" | 13 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProv
ider.h" |
14 | 14 |
| 15 namespace base { |
| 16 class SingleThreadTaskRunner; |
| 17 } |
| 18 |
15 namespace content { | 19 namespace content { |
16 | 20 |
17 class ServiceRegistry; | |
18 | |
19 // The BackgroundSyncProvider is called by the SyncManager and SyncRegistration | 21 // The BackgroundSyncProvider is called by the SyncManager and SyncRegistration |
20 // objects (and their Periodic counterparts) and communicates with the | 22 // objects (and their Periodic counterparts) and communicates with the |
21 // BackgroundSyncManager object in the browser process. This class is | 23 // BackgroundSyncManager object in the browser process. Each thread will have |
22 // instantiated on the main thread by BlinkPlatformImpl, and its methods can be | 24 // its own instance (e.g. main thread, worker threads), instantiated as needed |
23 // called directly from the main thread. | 25 // by BlinkPlatformImpl. Each instance of the provider creates a new mojo |
24 class BackgroundSyncProvider : public blink::WebSyncProvider { | 26 // connection to a new BackgroundSyncManagerImpl, which then talks to the |
| 27 // BackgroundSyncManager object. |
| 28 class BackgroundSyncProvider : public blink::WebSyncProvider, |
| 29 public WorkerThread::Observer { |
25 public: | 30 public: |
26 explicit BackgroundSyncProvider(ServiceRegistry* service_registry); | 31 // Constructor made public to allow BlinkPlatformImpl to own a copy for the |
| 32 // main thread. Everyone else should use GetOrCreateThreadSpecificInstance(). |
| 33 explicit BackgroundSyncProvider( |
| 34 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); |
27 | 35 |
28 ~BackgroundSyncProvider() override; | 36 ~BackgroundSyncProvider() override; |
29 | 37 |
| 38 // Returns thread-specific instance (if exists). Otherwise, a new instance |
| 39 // will be created for the thread, except when called for a worker thread that |
| 40 // has already been stopped. |
| 41 static BackgroundSyncProvider* GetOrCreateThreadSpecificInstance( |
| 42 base::SingleThreadTaskRunner* main_thread_task_runner); |
| 43 |
30 // blink::WebSyncProvider implementation | 44 // blink::WebSyncProvider implementation |
31 void registerBackgroundSync( | 45 void registerBackgroundSync( |
32 const blink::WebSyncRegistration* options, | 46 const blink::WebSyncRegistration* options, |
33 blink::WebServiceWorkerRegistration* service_worker_registration, | 47 blink::WebServiceWorkerRegistration* service_worker_registration, |
34 bool requested_from_service_worker, | 48 bool requested_from_service_worker, |
35 blink::WebSyncRegistrationCallbacks* callbacks) override; | 49 blink::WebSyncRegistrationCallbacks* callbacks) override; |
36 void unregisterBackgroundSync( | 50 void unregisterBackgroundSync( |
37 int64_t handle_id, | 51 int64_t handle_id, |
38 blink::WebServiceWorkerRegistration* service_worker_registration, | 52 blink::WebServiceWorkerRegistration* service_worker_registration, |
39 blink::WebSyncUnregistrationCallbacks* callbacks) override; | 53 blink::WebSyncUnregistrationCallbacks* callbacks) override; |
(...skipping 14 matching lines...) Expand all Loading... |
54 void releaseRegistration(int64_t handle_id) override; | 68 void releaseRegistration(int64_t handle_id) override; |
55 void notifyWhenDone( | 69 void notifyWhenDone( |
56 int64_t handle_id, | 70 int64_t handle_id, |
57 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; | 71 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; |
58 | 72 |
59 void DuplicateRegistrationHandle( | 73 void DuplicateRegistrationHandle( |
60 int64_t handle_id, | 74 int64_t handle_id, |
61 const BackgroundSyncService::DuplicateRegistrationHandleCallback& | 75 const BackgroundSyncService::DuplicateRegistrationHandleCallback& |
62 callback); | 76 callback); |
63 | 77 |
| 78 // WorkerThread::Observer implementation. |
| 79 void WillStopCurrentWorkerThread() override; |
| 80 |
64 private: | 81 private: |
65 // Callback handlers | 82 // Callback handlers |
66 void RegisterCallback( | 83 void RegisterCallback( |
67 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 84 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
68 BackgroundSyncError error, | 85 BackgroundSyncError error, |
69 const SyncRegistrationPtr& options); | 86 const SyncRegistrationPtr& options); |
70 void UnregisterCallback( | 87 void UnregisterCallback( |
71 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, | 88 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, |
72 BackgroundSyncError error); | 89 BackgroundSyncError error); |
73 void GetRegistrationCallback( | 90 void GetRegistrationCallback( |
74 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 91 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
75 BackgroundSyncError error, | 92 BackgroundSyncError error, |
76 const SyncRegistrationPtr& options); | 93 const SyncRegistrationPtr& options); |
77 void GetRegistrationsCallback( | 94 void GetRegistrationsCallback( |
78 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, | 95 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, |
79 BackgroundSyncError error, | 96 BackgroundSyncError error, |
80 const mojo::Array<SyncRegistrationPtr>& registrations); | 97 const mojo::Array<SyncRegistrationPtr>& registrations); |
81 void GetPermissionStatusCallback( | 98 void GetPermissionStatusCallback( |
82 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks, | 99 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks, |
83 BackgroundSyncError error, | 100 BackgroundSyncError error, |
84 PermissionStatus status); | 101 PermissionStatus status); |
85 void NotifyWhenDoneCallback( | 102 void NotifyWhenDoneCallback( |
86 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks, | 103 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks, |
87 BackgroundSyncError error, | 104 BackgroundSyncError error, |
88 BackgroundSyncState state); | 105 BackgroundSyncState state); |
89 | 106 |
90 // Helper method that returns an initialized BackgroundSyncServicePtr. | 107 // Helper method that returns an initialized BackgroundSyncServicePtr. |
91 BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); | 108 BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); |
92 | 109 |
93 ServiceRegistry* service_registry_; | |
94 BackgroundSyncServicePtr background_sync_service_; | 110 BackgroundSyncServicePtr background_sync_service_; |
| 111 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
95 | 112 |
96 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); | 113 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); |
97 }; | 114 }; |
98 | 115 |
99 } // namespace content | 116 } // namespace content |
100 | 117 |
101 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | 118 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ |
OLD | NEW |