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 |
jkarlin
2015/09/28 20:10:05
It communicates with the BackgroundSyncManager via
chasej
2015/10/08 03:28:53
Acknowledged.
| |
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 will create a separate |
24 class BackgroundSyncProvider : public blink::WebSyncProvider { | 26 // mojo connection to the BackgroundSyncManager object in the browser process. |
jkarlin
2015/09/28 20:10:05
Each instance creates a new mojo connection to a n
chasej
2015/10/08 03:28:53
Comment updated to be more precise about the behav
| |
27 class BackgroundSyncProvider : public blink::WebSyncProvider, | |
28 public WorkerThread::Observer { | |
25 public: | 29 public: |
26 explicit BackgroundSyncProvider(ServiceRegistry* service_registry); | 30 static BackgroundSyncProvider* GetThreadInstance( |
27 | 31 base::SingleThreadTaskRunner* main_thread_task_runner); |
28 ~BackgroundSyncProvider() override; | |
29 | 32 |
30 // blink::WebSyncProvider implementation | 33 // blink::WebSyncProvider implementation |
31 // TODO(jkarlin) convert int64_t handle_id to int handle_id in all | 34 // TODO(jkarlin) convert int64_t handle_id to int handle_id in all |
32 // WebSyncProvider functions. | 35 // WebSyncProvider functions. |
33 void registerBackgroundSync( | 36 void registerBackgroundSync( |
34 const blink::WebSyncRegistration* options, | 37 const blink::WebSyncRegistration* options, |
35 blink::WebServiceWorkerRegistration* service_worker_registration, | 38 blink::WebServiceWorkerRegistration* service_worker_registration, |
36 bool requested_from_service_worker, | 39 bool requested_from_service_worker, |
37 blink::WebSyncRegistrationCallbacks* callbacks) override; | 40 blink::WebSyncRegistrationCallbacks* callbacks) override; |
38 // TODO(jkarlin) remove |tag| parameter. | 41 // TODO(jkarlin) remove |tag| parameter. |
(...skipping 20 matching lines...) Expand all Loading... | |
59 void releaseRegistration(int64_t handle_id) override; | 62 void releaseRegistration(int64_t handle_id) override; |
60 void notifyWhenDone( | 63 void notifyWhenDone( |
61 int64_t handle_id, | 64 int64_t handle_id, |
62 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; | 65 blink::WebSyncNotifyWhenDoneCallbacks* callbacks) override; |
63 | 66 |
64 void DuplicateRegistrationHandle( | 67 void DuplicateRegistrationHandle( |
65 int handle_id, | 68 int handle_id, |
66 const BackgroundSyncService::DuplicateRegistrationHandleCallback& | 69 const BackgroundSyncService::DuplicateRegistrationHandleCallback& |
67 callback); | 70 callback); |
68 | 71 |
72 // WorkerThread::Observer implementation. | |
73 void WillStopCurrentWorkerThread() override; | |
jkarlin
2015/09/28 20:12:51
I see how worker threads get killed, thanks to thi
michaeln
2015/10/02 00:13:08
For other threadspecific classes like this, the in
| |
74 | |
69 private: | 75 private: |
76 explicit BackgroundSyncProvider( | |
77 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); | |
78 | |
79 ~BackgroundSyncProvider() override; | |
80 | |
70 // Callback handlers | 81 // Callback handlers |
71 void RegisterCallback( | 82 void RegisterCallback( |
72 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 83 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
73 BackgroundSyncError error, | 84 BackgroundSyncError error, |
74 const SyncRegistrationPtr& options); | 85 const SyncRegistrationPtr& options); |
75 void UnregisterCallback( | 86 void UnregisterCallback( |
76 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, | 87 scoped_ptr<blink::WebSyncUnregistrationCallbacks> callbacks, |
77 BackgroundSyncError error); | 88 BackgroundSyncError error); |
78 void GetRegistrationCallback( | 89 void GetRegistrationCallback( |
79 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, | 90 scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
80 BackgroundSyncError error, | 91 BackgroundSyncError error, |
81 const SyncRegistrationPtr& options); | 92 const SyncRegistrationPtr& options); |
82 void GetRegistrationsCallback( | 93 void GetRegistrationsCallback( |
83 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, | 94 scoped_ptr<blink::WebSyncGetRegistrationsCallbacks> callbacks, |
84 BackgroundSyncError error, | 95 BackgroundSyncError error, |
85 const mojo::Array<SyncRegistrationPtr>& registrations); | 96 const mojo::Array<SyncRegistrationPtr>& registrations); |
86 void GetPermissionStatusCallback( | 97 void GetPermissionStatusCallback( |
87 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks, | 98 scoped_ptr<blink::WebSyncGetPermissionStatusCallbacks> callbacks, |
88 BackgroundSyncError error, | 99 BackgroundSyncError error, |
89 PermissionStatus status); | 100 PermissionStatus status); |
90 void NotifyWhenDoneCallback( | 101 void NotifyWhenDoneCallback( |
91 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks, | 102 scoped_ptr<blink::WebSyncNotifyWhenDoneCallbacks> callbacks, |
92 BackgroundSyncError error, | 103 BackgroundSyncError error, |
93 BackgroundSyncState state); | 104 BackgroundSyncState state); |
94 | 105 |
95 // Helper method that returns an initialized BackgroundSyncServicePtr. | 106 // Helper method that returns an initialized BackgroundSyncServicePtr. |
96 BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); | 107 BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); |
97 | 108 |
98 ServiceRegistry* service_registry_; | |
99 BackgroundSyncServicePtr background_sync_service_; | 109 BackgroundSyncServicePtr background_sync_service_; |
110 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | |
100 | 111 |
101 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); | 112 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); |
102 }; | 113 }; |
103 | 114 |
104 } // namespace content | 115 } // namespace content |
105 | 116 |
106 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ | 117 #endif // CONTENT_CHILD_BACKGROUND_SYNC_BACKGROUND_SYNC_PROVIDER_H_ |
OLD | NEW |