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