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_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "content/common/background_sync_service.mojom.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 // This class implements the mojo service for firing background sync events in a |
| 17 // service worker thread. It is constructed and lives on the renderer main |
| 18 // thread, but can dispatch to any worker thread to fire events. |
| 19 // Return messages from the workers are rerouted to the main thread in order to |
| 20 // be sent back over the mojo message channel. |
| 21 class CONTENT_EXPORT BackgroundSyncClientImpl |
| 22 : public NON_EXPORTED_BASE(BackgroundSyncServiceClient) { |
| 23 public: |
| 24 static void Create( |
| 25 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 26 main_thread_task_runner, |
| 27 mojo::InterfaceRequest<BackgroundSyncServiceClient> request); |
| 28 |
| 29 ~BackgroundSyncClientImpl() override; |
| 30 |
| 31 private: |
| 32 using SyncCallback = mojo::Callback<void(ServiceWorkerEventStatus)>; |
| 33 explicit BackgroundSyncClientImpl( |
| 34 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 35 main_thread_task_runner, |
| 36 mojo::InterfaceRequest<BackgroundSyncServiceClient> request); |
| 37 |
| 38 // BackgroundSyncClient methods: |
| 39 void Sync(content::SyncRegistrationPtr registration, |
| 40 int thread_id, |
| 41 const SyncCallback& callback) override; |
| 42 |
| 43 static void DispatchSyncOnWorkerThread( |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 45 main_thread_task_runner, |
| 46 content::SyncRegistrationPtr event, |
| 47 const SyncCallback& callback); |
| 48 static void OnSyncCompleteOnWorkerThread( |
| 49 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 50 main_thread_task_runner, |
| 51 const SyncCallback& callback, |
| 52 ServiceWorkerEventStatus status); |
| 53 static void OnSyncCompleteOnMainThread(const SyncCallback& callback, |
| 54 ServiceWorkerEventStatus status); |
| 55 |
| 56 mojo::StrongBinding<BackgroundSyncServiceClient> binding_; |
| 57 |
| 58 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 59 |
| 60 base::WeakPtrFactory<BackgroundSyncClientImpl> weak_ptr_factory_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncClientImpl); |
| 63 }; |
| 64 |
| 65 } // namespace content |
| 66 |
| 67 #endif // CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_ |
OLD | NEW |