| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/service_worker/service_worker_status_code.h" | 19 #include "content/common/service_worker/service_worker_status_code.h" |
| 20 | 20 |
| 21 struct EmbeddedWorkerMsg_StartWorker_Params; | |
| 22 class GURL; | 21 class GURL; |
| 23 | 22 |
| 24 namespace IPC { | 23 namespace IPC { |
| 25 class Message; | 24 class Message; |
| 26 class Sender; | 25 class Sender; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 | 29 |
| 31 class EmbeddedWorkerInstance; | 30 class EmbeddedWorkerInstance; |
| 31 struct EmbeddedWorkerStartParams; |
| 32 class MessagePortMessageFilter; | 32 class MessagePortMessageFilter; |
| 33 class ServiceWorkerContextCore; | 33 class ServiceWorkerContextCore; |
| 34 | 34 |
| 35 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, | 35 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, |
| 36 // which sends/receives messages to/from each EmbeddedWorker in child process. | 36 // which sends/receives messages to/from each EmbeddedWorker in child process. |
| 37 // | 37 // |
| 38 // Hangs off ServiceWorkerContextCore (its reference is also held by each | 38 // Hangs off ServiceWorkerContextCore (its reference is also held by each |
| 39 // EmbeddedWorkerInstance). Operated only on IO thread. | 39 // EmbeddedWorkerInstance). Operated only on IO thread. |
| 40 class CONTENT_EXPORT EmbeddedWorkerRegistry | 40 class CONTENT_EXPORT EmbeddedWorkerRegistry |
| 41 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { | 41 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 EmbeddedWorkerRegistry* old_registry); | 52 EmbeddedWorkerRegistry* old_registry); |
| 53 | 53 |
| 54 bool OnMessageReceived(const IPC::Message& message, int process_id); | 54 bool OnMessageReceived(const IPC::Message& message, int process_id); |
| 55 | 55 |
| 56 // Creates and removes a new worker instance entry for bookkeeping. | 56 // Creates and removes a new worker instance entry for bookkeeping. |
| 57 // This doesn't actually start or stop the worker. | 57 // This doesn't actually start or stop the worker. |
| 58 std::unique_ptr<EmbeddedWorkerInstance> CreateWorker(); | 58 std::unique_ptr<EmbeddedWorkerInstance> CreateWorker(); |
| 59 | 59 |
| 60 // Called from EmbeddedWorkerInstance, relayed to the child process. | 60 // Called from EmbeddedWorkerInstance, relayed to the child process. |
| 61 ServiceWorkerStatusCode SendStartWorker( | 61 ServiceWorkerStatusCode SendStartWorker( |
| 62 std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 62 std::unique_ptr<EmbeddedWorkerStartParams> params, |
| 63 int process_id); | 63 int process_id); |
| 64 ServiceWorkerStatusCode StopWorker(int process_id, | 64 ServiceWorkerStatusCode StopWorker(int process_id, |
| 65 int embedded_worker_id); | 65 int embedded_worker_id); |
| 66 | 66 |
| 67 // Stop all active workers, even if they're handling events. | 67 // Stop all active workers, even if they're handling events. |
| 68 void Shutdown(); | 68 void Shutdown(); |
| 69 | 69 |
| 70 // Called back from EmbeddedWorker in the child process, relayed via | 70 // Called back from EmbeddedWorker in the child process, relayed via |
| 71 // ServiceWorkerDispatcherHost. | 71 // ServiceWorkerDispatcherHost. |
| 72 void OnWorkerReadyForInspection(int process_id, int embedded_worker_id); | 72 void OnWorkerReadyForInspection(int process_id, int embedded_worker_id); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id); | 108 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 friend class base::RefCounted<EmbeddedWorkerRegistry>; | 111 friend class base::RefCounted<EmbeddedWorkerRegistry>; |
| 112 friend class EmbeddedWorkerInstance; | 112 friend class EmbeddedWorkerInstance; |
| 113 friend class EmbeddedWorkerInstanceTest; | 113 friend class EmbeddedWorkerInstanceTest; |
| 114 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, | 114 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, |
| 115 RemoveWorkerInSharedProcess); | 115 RemoveWorkerInSharedProcess); |
| 116 | 116 |
| 117 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; | 117 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; |
| 118 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; | 118 using ProcessToSenderMap = std::map<int, IPC::Sender*>; |
| 119 typedef std::map<int, MessagePortMessageFilter*> | 119 using ProcessToMessagePortMessageFilterMap = |
| 120 ProcessToMessagePortMessageFilterMap; | 120 std::map<int, MessagePortMessageFilter*>; |
| 121 | 121 |
| 122 EmbeddedWorkerRegistry( | 122 EmbeddedWorkerRegistry( |
| 123 const base::WeakPtr<ServiceWorkerContextCore>& context, | 123 const base::WeakPtr<ServiceWorkerContextCore>& context, |
| 124 int initial_embedded_worker_id); | 124 int initial_embedded_worker_id); |
| 125 ~EmbeddedWorkerRegistry(); | 125 ~EmbeddedWorkerRegistry(); |
| 126 | 126 |
| 127 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); | 127 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); |
| 128 | 128 |
| 129 // Called when EmbeddedWorkerInstance is ready for IPC. This function |
| 130 // prepares a route to the child worker thread. |
| 131 // TODO(shimazu): Remove this function once mojofication is completed. |
| 132 void BindWorkerToProcess(int process_id, int embedded_worker_id); |
| 133 |
| 129 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. | 134 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. |
| 130 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) | 135 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) |
| 131 // if it's not running. | 136 // if it's not running. |
| 132 void RemoveWorker(int process_id, int embedded_worker_id); | 137 void RemoveWorker(int process_id, int embedded_worker_id); |
| 133 | 138 |
| 134 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, | 139 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, |
| 135 int embedded_worker_id); | 140 int embedded_worker_id); |
| 136 | 141 |
| 137 base::WeakPtr<ServiceWorkerContextCore> context_; | 142 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 138 | 143 |
| 139 WorkerInstanceMap worker_map_; | 144 WorkerInstanceMap worker_map_; |
| 140 ProcessToSenderMap process_sender_map_; | 145 ProcessToSenderMap process_sender_map_; |
| 141 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_; | 146 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_; |
| 142 | 147 |
| 143 // Map from process_id to embedded_worker_id. | 148 // Map from process_id to embedded_worker_id. |
| 144 // This map only contains starting and running workers. | 149 // This map only contains starting and running workers. |
| 145 std::map<int, std::set<int> > worker_process_map_; | 150 std::map<int, std::set<int> > worker_process_map_; |
| 146 | 151 |
| 147 int next_embedded_worker_id_; | 152 int next_embedded_worker_id_; |
| 148 const int initial_embedded_worker_id_; | 153 const int initial_embedded_worker_id_; |
| 149 | 154 |
| 150 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); | 155 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 } // namespace content | 158 } // namespace content |
| 154 | 159 |
| 155 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 160 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |