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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MOJO_EVENT_DISPATCHER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MOJO_EVENT_DISPATCHER_H_ |
| 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "content/common/background_sync_service.mojom.h" |
| 10 #include "content/common/service_worker/service_worker_status_code.h" |
| 11 |
| 12 namespace mojo { |
| 13 |
| 14 template <> |
| 15 struct CONTENT_EXPORT TypeConverter<content::ServiceWorkerStatusCode, |
| 16 content::ServiceWorkerEventStatus> { |
| 17 static content::ServiceWorkerStatusCode Convert( |
| 18 content::ServiceWorkerEventStatus status); |
| 19 }; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 namespace content { |
| 24 |
| 25 // This class is used by ServiceWorkerVersion to fire events in the service |
| 26 // worker using mojo IPC. It owns an InterfacePtr to each service, which it will |
| 27 // construct as necessary. |
| 28 // |
| 29 // This class should only be called on the IO thread. |
| 30 class ServiceWorkerMojoEventDispatcher { |
| 31 public: |
| 32 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode)>; |
| 33 |
| 34 ServiceWorkerMojoEventDispatcher(int render_process_id); |
| 35 ~ServiceWorkerMojoEventDispatcher(); |
| 36 |
| 37 // Dispatches the event, establishing a connection to the mojo service if |
| 38 // necessary, and then runs |callback| with the result. |
| 39 void DispatchSyncEvent(int thread_id, const StatusCallback& callback); |
| 40 |
| 41 int render_process_id() { return render_process_id_; } |
| 42 |
| 43 private: |
| 44 void OnEventFinished(const StatusCallback& callback, |
| 45 ServiceWorkerEventStatus result); |
| 46 |
| 47 int render_process_id_; |
| 48 BackgroundSyncServiceClientPtr background_sync_client_; |
| 49 |
| 50 base::WeakPtrFactory<ServiceWorkerMojoEventDispatcher> weak_factory_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerMojoEventDispatcher); |
| 53 }; |
| 54 |
| 55 } // namespace content |
| 56 |
| 57 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_MOJO_EVENT_DISPATCHER_H
_ |
OLD | NEW |