| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace IPC { | 23 namespace IPC { |
| 24 class Message; | 24 class Message; |
| 25 class Sender; | 25 class Sender; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 class EmbeddedWorkerInstance; | 30 class EmbeddedWorkerInstance; |
| 31 struct EmbeddedWorkerStartParams; | 31 struct EmbeddedWorkerStartParams; |
| 32 class MessagePortMessageFilter; | |
| 33 class ServiceWorkerContextCore; | 32 class ServiceWorkerContextCore; |
| 34 | 33 |
| 35 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, | 34 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, |
| 36 // which sends/receives messages to/from each EmbeddedWorker in child process. | 35 // which sends/receives messages to/from each EmbeddedWorker in child process. |
| 37 // | 36 // |
| 38 // Hangs off ServiceWorkerContextCore (its reference is also held by each | 37 // Hangs off ServiceWorkerContextCore (its reference is also held by each |
| 39 // EmbeddedWorkerInstance). Operated only on IO thread. | 38 // EmbeddedWorkerInstance). Operated only on IO thread. |
| 40 class CONTENT_EXPORT EmbeddedWorkerRegistry | 39 class CONTENT_EXPORT EmbeddedWorkerRegistry |
| 41 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { | 40 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { |
| 42 public: | 41 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 int column_number, | 85 int column_number, |
| 87 const GURL& source_url); | 86 const GURL& source_url); |
| 88 void OnReportConsoleMessage(int embedded_worker_id, | 87 void OnReportConsoleMessage(int embedded_worker_id, |
| 89 int source_identifier, | 88 int source_identifier, |
| 90 int message_level, | 89 int message_level, |
| 91 const base::string16& message, | 90 const base::string16& message, |
| 92 int line_number, | 91 int line_number, |
| 93 const GURL& source_url); | 92 const GURL& source_url); |
| 94 | 93 |
| 95 // Keeps a map from process_id to sender information. | 94 // Keeps a map from process_id to sender information. |
| 96 void AddChildProcessSender( | 95 void AddChildProcessSender(int process_id, IPC::Sender* sender); |
| 97 int process_id, | |
| 98 IPC::Sender* sender, | |
| 99 MessagePortMessageFilter* message_port_message_filter); | |
| 100 void RemoveChildProcessSender(int process_id); | 96 void RemoveChildProcessSender(int process_id); |
| 101 | 97 |
| 102 // Returns an embedded worker instance for given |embedded_worker_id|. | 98 // Returns an embedded worker instance for given |embedded_worker_id|. |
| 103 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); | 99 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); |
| 104 | 100 |
| 105 // Returns true if |embedded_worker_id| is managed by this registry. | 101 // Returns true if |embedded_worker_id| is managed by this registry. |
| 106 bool CanHandle(int embedded_worker_id) const; | 102 bool CanHandle(int embedded_worker_id) const; |
| 107 | 103 |
| 108 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id); | |
| 109 | |
| 110 private: | 104 private: |
| 111 friend class base::RefCounted<EmbeddedWorkerRegistry>; | 105 friend class base::RefCounted<EmbeddedWorkerRegistry>; |
| 112 friend class MojoEmbeddedWorkerInstanceTest; | 106 friend class MojoEmbeddedWorkerInstanceTest; |
| 113 friend class EmbeddedWorkerInstance; | 107 friend class EmbeddedWorkerInstance; |
| 114 friend class EmbeddedWorkerInstanceTest; | 108 friend class EmbeddedWorkerInstanceTest; |
| 115 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTestP, | 109 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTestP, |
| 116 RemoveWorkerInSharedProcess); | 110 RemoveWorkerInSharedProcess); |
| 117 | 111 |
| 118 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; | 112 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; |
| 119 using ProcessToSenderMap = std::map<int, IPC::Sender*>; | 113 using ProcessToSenderMap = std::map<int, IPC::Sender*>; |
| 120 using ProcessToMessagePortMessageFilterMap = | |
| 121 std::map<int, MessagePortMessageFilter*>; | |
| 122 | 114 |
| 123 EmbeddedWorkerRegistry( | 115 EmbeddedWorkerRegistry( |
| 124 const base::WeakPtr<ServiceWorkerContextCore>& context, | 116 const base::WeakPtr<ServiceWorkerContextCore>& context, |
| 125 int initial_embedded_worker_id); | 117 int initial_embedded_worker_id); |
| 126 ~EmbeddedWorkerRegistry(); | 118 ~EmbeddedWorkerRegistry(); |
| 127 | 119 |
| 128 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); | 120 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); |
| 129 | 121 |
| 130 // Called when EmbeddedWorkerInstance is ready for IPC. This function | 122 // Called when EmbeddedWorkerInstance is ready for IPC. This function |
| 131 // prepares a route to the child worker thread. | 123 // prepares a route to the child worker thread. |
| 132 // TODO(shimazu): Remove this function once mojofication is completed. | 124 // TODO(shimazu): Remove this function once mojofication is completed. |
| 133 void BindWorkerToProcess(int process_id, int embedded_worker_id); | 125 void BindWorkerToProcess(int process_id, int embedded_worker_id); |
| 134 | 126 |
| 135 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. | 127 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. |
| 136 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) | 128 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) |
| 137 // if it's not running. | 129 // if it's not running. |
| 138 void RemoveWorker(int process_id, int embedded_worker_id); | 130 void RemoveWorker(int process_id, int embedded_worker_id); |
| 139 // DetachWorker is called when EmbeddedWorkerInstance releases a process. | 131 // DetachWorker is called when EmbeddedWorkerInstance releases a process. |
| 140 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) | 132 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) |
| 141 // if it's not running. | 133 // if it's not running. |
| 142 void DetachWorker(int process_id, int embedded_worker_id); | 134 void DetachWorker(int process_id, int embedded_worker_id); |
| 143 | 135 |
| 144 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, | 136 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, |
| 145 int embedded_worker_id); | 137 int embedded_worker_id); |
| 146 | 138 |
| 147 base::WeakPtr<ServiceWorkerContextCore> context_; | 139 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 148 | 140 |
| 149 WorkerInstanceMap worker_map_; | 141 WorkerInstanceMap worker_map_; |
| 150 ProcessToSenderMap process_sender_map_; | 142 ProcessToSenderMap process_sender_map_; |
| 151 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_; | |
| 152 | 143 |
| 153 // Map from process_id to embedded_worker_id. | 144 // Map from process_id to embedded_worker_id. |
| 154 // This map only contains starting and running workers. | 145 // This map only contains starting and running workers. |
| 155 std::map<int, std::set<int> > worker_process_map_; | 146 std::map<int, std::set<int> > worker_process_map_; |
| 156 | 147 |
| 157 int next_embedded_worker_id_; | 148 int next_embedded_worker_id_; |
| 158 const int initial_embedded_worker_id_; | 149 const int initial_embedded_worker_id_; |
| 159 | 150 |
| 160 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); | 151 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 161 }; | 152 }; |
| 162 | 153 |
| 163 } // namespace content | 154 } // namespace content |
| 164 | 155 |
| 165 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 156 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |