Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Side by Side Diff: content/browser/service_worker/embedded_worker_registry.h

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Remove a break line Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class GURL; 21 class GURL;
22 22
23 namespace IPC { 23 namespace IPC {
24 class Message; 24 class Message;
25 class Sender;
26 } 25 }
27 26
28 namespace content { 27 namespace content {
29 28
30 class EmbeddedWorkerInstance; 29 class EmbeddedWorkerInstance;
31 class MessagePortMessageFilter; 30 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.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 int line_number, 80 int line_number,
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 // Detaches the process and removes all workers living on the process.
92 void AddChildProcessSender( 91 void DetachProcess(int process_id);
falken 2017/02/08 06:53:51 Can we have a better name than "Detach". Historica
shimazu 2017/02/13 03:25:56 Done.
93 int process_id,
94 IPC::Sender* sender,
95 MessagePortMessageFilter* message_port_message_filter);
96 void RemoveChildProcessSender(int process_id);
97 92
98 // Returns an embedded worker instance for given |embedded_worker_id|. 93 // Returns an embedded worker instance for given |embedded_worker_id|.
99 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); 94 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id);
100 95
101 // Returns true if |embedded_worker_id| is managed by this registry. 96 // Returns true if |embedded_worker_id| is managed by this registry.
102 bool CanHandle(int embedded_worker_id) const; 97 bool CanHandle(int embedded_worker_id) const;
103 98
104 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id); 99 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id);
105 100
106 private: 101 private:
107 friend class base::RefCounted<EmbeddedWorkerRegistry>; 102 friend class base::RefCounted<EmbeddedWorkerRegistry>;
108 friend class MojoEmbeddedWorkerInstanceTest; 103 friend class MojoEmbeddedWorkerInstanceTest;
109 friend class EmbeddedWorkerInstance; 104 friend class EmbeddedWorkerInstance;
110 friend class EmbeddedWorkerInstanceTest; 105 friend class EmbeddedWorkerInstanceTest;
111 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, 106 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest,
112 RemoveWorkerInSharedProcess); 107 RemoveWorkerInSharedProcess);
113 108
114 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; 109 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>;
115 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_;
147 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_;
148 138
149 // Map from process_id to embedded_worker_id. 139 // Map from process_id to embedded_worker_id.
150 // This map only contains starting and running workers. 140 // This map only contains starting and running workers.
151 std::map<int, std::set<int> > worker_process_map_; 141 std::map<int, std::set<int> > worker_process_map_;
152 142
153 int next_embedded_worker_id_; 143 int next_embedded_worker_id_;
154 const int initial_embedded_worker_id_; 144 const int initial_embedded_worker_id_;
155 145
156 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); 146 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
157 }; 147 };
158 148
159 } // namespace content 149 } // namespace content
160 150
161 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 151 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698