| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ | 5 #ifndef EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ |
| 6 #define EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ | 6 #define EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
| 9 #include "content/public/renderer/render_thread_observer.h" | 9 #include "content/public/renderer/render_thread_observer.h" |
| 10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 class ListValue; | 13 class ListValue; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 class RenderThread; | 17 class RenderThread; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 class RequestSender; | 21 class RequestSender; |
| 22 class ServiceWorkerRequestSender; |
| 22 class V8SchemaRegistry; | 23 class V8SchemaRegistry; |
| 23 | 24 |
| 24 // Sends and receives IPC in an extension Service Worker. | 25 // Sends and receives IPC in an extension Service Worker. |
| 25 // TODO(lazyboy): This class should really be a combination of the following | 26 // TODO(lazyboy): This class should really be a combination of the following |
| 26 // two: | 27 // two: |
| 27 // 1) A content::WorkerThreadMessageFilter, so that we can receive IPC directly | 28 // 1) A content::WorkerThreadMessageFilter, so that we can receive IPC directly |
| 28 // on worker thread. | 29 // on worker thread. |
| 29 // 2) A content::ThreadSafeSender, so we can safely send IPC from worker thread. | 30 // 2) A content::ThreadSafeSender, so we can safely send IPC from worker thread. |
| 30 class WorkerThreadDispatcher : public content::RenderThreadObserver { | 31 class WorkerThreadDispatcher : public content::RenderThreadObserver { |
| 31 public: | 32 public: |
| 32 WorkerThreadDispatcher(); | 33 WorkerThreadDispatcher(); |
| 33 ~WorkerThreadDispatcher() override; | 34 ~WorkerThreadDispatcher() override; |
| 34 | 35 |
| 35 // Thread safe. | 36 // Thread safe. |
| 36 static WorkerThreadDispatcher* Get(); | 37 static WorkerThreadDispatcher* Get(); |
| 37 static RequestSender* GetRequestSender(); | 38 static ServiceWorkerRequestSender* GetRequestSender(); |
| 38 | 39 |
| 39 void Init(content::RenderThread* render_thread); | 40 void Init(content::RenderThread* render_thread); |
| 40 bool Send(IPC::Message* message); | 41 bool Send(IPC::Message* message); |
| 41 void AddWorkerData(int embedded_worker_id); | 42 void AddWorkerData(int64_t service_worker_version_id); |
| 42 void RemoveWorkerData(int embedded_worker_id); | 43 void RemoveWorkerData(int64_t service_worker_version_id); |
| 43 V8SchemaRegistry* GetV8SchemaRegistry(); | 44 V8SchemaRegistry* GetV8SchemaRegistry(); |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 // content::RenderThreadObserver: | 47 // content::RenderThreadObserver: |
| 47 bool OnControlMessageReceived(const IPC::Message& message) override; | 48 bool OnControlMessageReceived(const IPC::Message& message) override; |
| 48 | 49 |
| 49 // IPC handlers. | 50 // IPC handlers. |
| 50 void OnResponseWorker(int worker_thread_id, | 51 void OnResponseWorker(int worker_thread_id, |
| 51 int request_id, | 52 int request_id, |
| 52 bool succeeded, | 53 bool succeeded, |
| 53 const base::ListValue& response, | 54 const base::ListValue& response, |
| 54 const std::string& error); | 55 const std::string& error); |
| 55 | 56 |
| 56 // IPC sender. Belongs to the render thread, but thread safe. | 57 // IPC sender. Belongs to the render thread, but thread safe. |
| 57 scoped_refptr<IPC::SyncMessageFilter> message_filter_; | 58 scoped_refptr<IPC::SyncMessageFilter> message_filter_; |
| 58 | 59 |
| 59 DISALLOW_COPY_AND_ASSIGN(WorkerThreadDispatcher); | 60 DISALLOW_COPY_AND_ASSIGN(WorkerThreadDispatcher); |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 } // namespace extensions | 63 } // namespace extensions |
| 63 | 64 |
| 64 #endif // EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ | 65 #endif // EXTENSIONS_RENDERER_WORKER_THREAD_DISPATCHER_H_ |
| OLD | NEW |