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