Index: content/child/background_sync/background_sync_provider.h |
diff --git a/content/child/background_sync/background_sync_provider.h b/content/child/background_sync/background_sync_provider.h |
index cb4f6af5dcf34c8431f89f19d8b718f42f2adb20..864e4735ef57a1c272d2c5e941490129e6b86850 100644 |
--- a/content/child/background_sync/background_sync_provider.h |
+++ b/content/child/background_sync/background_sync_provider.h |
@@ -8,25 +8,31 @@ |
#include <string> |
#include "base/memory/scoped_ptr.h" |
-#include "content/child/worker_task_runner.h" |
#include "content/common/background_sync_service.mojom.h" |
+#include "content/public/child/worker_thread.h" |
#include "third_party/WebKit/public/platform/modules/background_sync/WebSyncProvider.h" |
-namespace content { |
+namespace base { |
+class SingleThreadTaskRunner; |
+} |
-class ServiceRegistry; |
+namespace content { |
// The BackgroundSyncProvider is called by the SyncManager and SyncRegistration |
// objects (and their Periodic counterparts) and communicates with the |
-// BackgroundSyncManager object in the browser process. This class is |
-// instantiated on the main thread by BlinkPlatformImpl, and its methods can be |
-// called directly from the main thread. |
-class BackgroundSyncProvider : public blink::WebSyncProvider { |
+// BackgroundSyncManager object in the browser process. Each thread will have |
+// its own instance (e.g. main thread, worker threads), instantiated as needed |
+// by BlinkPlatformImpl. Each instance of the provider creates a new mojo |
+// connection to a new BackgroundSyncManagerImpl, which then talks to the |
+// BackgroundSyncManager object. |
+class BackgroundSyncProvider : public blink::WebSyncProvider, |
+ public WorkerThread::Observer { |
public: |
- explicit BackgroundSyncProvider(ServiceRegistry* service_registry); |
- |
~BackgroundSyncProvider() override; |
+ static BackgroundSyncProvider* GetOrCreateThreadSpecificInstance( |
+ base::SingleThreadTaskRunner* main_thread_task_runner); |
+ |
// blink::WebSyncProvider implementation |
void registerBackgroundSync( |
const blink::WebSyncRegistration* options, |
@@ -61,7 +67,13 @@ class BackgroundSyncProvider : public blink::WebSyncProvider { |
const BackgroundSyncService::DuplicateRegistrationHandleCallback& |
callback); |
+ // WorkerThread::Observer implementation. |
+ void WillStopCurrentWorkerThread() override; |
+ |
private: |
+ explicit BackgroundSyncProvider( |
+ const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner); |
+ |
// Callback handlers |
void RegisterCallback( |
scoped_ptr<blink::WebSyncRegistrationCallbacks> callbacks, |
@@ -90,8 +102,8 @@ class BackgroundSyncProvider : public blink::WebSyncProvider { |
// Helper method that returns an initialized BackgroundSyncServicePtr. |
BackgroundSyncServicePtr& GetBackgroundSyncServicePtr(); |
- ServiceRegistry* service_registry_; |
BackgroundSyncServicePtr background_sync_service_; |
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
DISALLOW_COPY_AND_ASSIGN(BackgroundSyncProvider); |
}; |