| 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> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Returns an embedded worker instance for given |embedded_worker_id|. | 102 // Returns an embedded worker instance for given |embedded_worker_id|. |
| 103 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); | 103 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); |
| 104 | 104 |
| 105 // Returns true if |embedded_worker_id| is managed by this registry. | 105 // Returns true if |embedded_worker_id| is managed by this registry. |
| 106 bool CanHandle(int embedded_worker_id) const; | 106 bool CanHandle(int embedded_worker_id) const; |
| 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 MojoEmbeddedWorkerInstanceTest; |
| 112 friend class EmbeddedWorkerInstance; | 113 friend class EmbeddedWorkerInstance; |
| 113 friend class EmbeddedWorkerInstanceTest; | 114 friend class EmbeddedWorkerInstanceTest; |
| 114 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, | 115 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTestP, |
| 115 RemoveWorkerInSharedProcess); | 116 RemoveWorkerInSharedProcess); |
| 116 | 117 |
| 117 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; | 118 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; |
| 118 using ProcessToSenderMap = std::map<int, IPC::Sender*>; | 119 using ProcessToSenderMap = std::map<int, IPC::Sender*>; |
| 119 using ProcessToMessagePortMessageFilterMap = | 120 using ProcessToMessagePortMessageFilterMap = |
| 120 std::map<int, MessagePortMessageFilter*>; | 121 std::map<int, MessagePortMessageFilter*>; |
| 121 | 122 |
| 122 EmbeddedWorkerRegistry( | 123 EmbeddedWorkerRegistry( |
| 123 const base::WeakPtr<ServiceWorkerContextCore>& context, | 124 const base::WeakPtr<ServiceWorkerContextCore>& context, |
| 124 int initial_embedded_worker_id); | 125 int initial_embedded_worker_id); |
| 125 ~EmbeddedWorkerRegistry(); | 126 ~EmbeddedWorkerRegistry(); |
| 126 | 127 |
| 127 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); | 128 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); |
| 128 | 129 |
| 129 // Called when EmbeddedWorkerInstance gets ready for IPC. This function | 130 // Called when EmbeddedWorkerInstance gets ready for IPC. This function |
| 130 // prepares a route to the child worker thread. | 131 // prepares a route to the child worker thread. |
| 131 // TODO(shimazu): Remove this function once mojofication is completed. | 132 // TODO(shimazu): Remove this function once mojofication is completed. |
| 132 ServiceWorkerStatusCode BindWorkerToProcess(int process_id, | 133 ServiceWorkerStatusCode BindWorkerToProcess(int process_id, |
| 133 int embedded_worker_id); | 134 int embedded_worker_id); |
| 134 | 135 |
| 135 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. | 136 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. |
| 136 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) | 137 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) |
| 137 // if it's not running. | 138 // if it's not running. |
| 138 void RemoveWorker(int process_id, int embedded_worker_id); | 139 void RemoveWorker(int process_id, int embedded_worker_id); |
| 140 // DetachWorker is called when EmbeddedWorkerInstance releases a process. |
| 141 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) |
| 142 // if it's not running. |
| 143 void DetachWorker(int process_id, int embedded_worker_id); |
| 139 | 144 |
| 140 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, | 145 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, |
| 141 int embedded_worker_id); | 146 int embedded_worker_id); |
| 142 | 147 |
| 143 base::WeakPtr<ServiceWorkerContextCore> context_; | 148 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 144 | 149 |
| 145 WorkerInstanceMap worker_map_; | 150 WorkerInstanceMap worker_map_; |
| 146 ProcessToSenderMap process_sender_map_; | 151 ProcessToSenderMap process_sender_map_; |
| 147 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_; | 152 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_; |
| 148 | 153 |
| 149 // Map from process_id to embedded_worker_id. | 154 // Map from process_id to embedded_worker_id. |
| 150 // This map only contains starting and running workers. | 155 // This map only contains starting and running workers. |
| 151 std::map<int, std::set<int> > worker_process_map_; | 156 std::map<int, std::set<int> > worker_process_map_; |
| 152 | 157 |
| 153 int next_embedded_worker_id_; | 158 int next_embedded_worker_id_; |
| 154 const int initial_embedded_worker_id_; | 159 const int initial_embedded_worker_id_; |
| 155 | 160 |
| 156 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); | 161 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 157 }; | 162 }; |
| 158 | 163 |
| 159 } // namespace content | 164 } // namespace content |
| 160 | 165 |
| 161 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 166 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |