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

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

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Fix an include guard 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 // Removes information about the service workers running on the process and
92 void AddChildProcessSender( 91 // calls ServiceWorkerVersion::OnDetached() on each. Called when the process
93 int process_id, 92 // is terminated. Under normal operation, the workers should already have
94 IPC::Sender* sender, 93 // been stopped before the process is terminated, in which case this function
95 MessagePortMessageFilter* message_port_message_filter); 94 // does nothing. But in some cases the process can be terminated unexpectedly
96 void RemoveChildProcessSender(int process_id); 95 // or the workers can fail to stop cleanly.
96 void RemoveProcess(int process_id);
97 97
98 // Returns an embedded worker instance for given |embedded_worker_id|. 98 // Returns an embedded worker instance for given |embedded_worker_id|.
99 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); 99 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id);
100 100
101 // Returns true if |embedded_worker_id| is managed by this registry. 101 // Returns true if |embedded_worker_id| is managed by this registry.
102 bool CanHandle(int embedded_worker_id) const; 102 bool CanHandle(int embedded_worker_id) const;
103 103
104 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id); 104 MessagePortMessageFilter* MessagePortMessageFilterForProcess(int process_id);
105 105
106 private: 106 private:
107 friend class base::RefCounted<EmbeddedWorkerRegistry>; 107 friend class base::RefCounted<EmbeddedWorkerRegistry>;
108 friend class MojoEmbeddedWorkerInstanceTest; 108 friend class MojoEmbeddedWorkerInstanceTest;
109 friend class EmbeddedWorkerInstance; 109 friend class EmbeddedWorkerInstance;
110 friend class EmbeddedWorkerInstanceTest; 110 friend class EmbeddedWorkerInstanceTest;
111 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest, 111 FRIEND_TEST_ALL_PREFIXES(EmbeddedWorkerInstanceTest,
112 RemoveWorkerInSharedProcess); 112 RemoveWorkerInSharedProcess);
113 113
114 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>; 114 using WorkerInstanceMap = std::map<int, EmbeddedWorkerInstance*>;
115 using ProcessToSenderMap = std::map<int, IPC::Sender*>;
116 using ProcessToMessagePortMessageFilterMap =
117 std::map<int, MessagePortMessageFilter*>;
118 115
119 EmbeddedWorkerRegistry( 116 EmbeddedWorkerRegistry(
120 const base::WeakPtr<ServiceWorkerContextCore>& context, 117 const base::WeakPtr<ServiceWorkerContextCore>& context,
121 int initial_embedded_worker_id); 118 int initial_embedded_worker_id);
122 ~EmbeddedWorkerRegistry(); 119 ~EmbeddedWorkerRegistry();
123 120
124 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); 121 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message);
125 122
126 // Called when EmbeddedWorkerInstance is ready for IPC. This function 123 // Called when EmbeddedWorkerInstance is ready for IPC. This function
127 // prepares a route to the child worker thread. 124 // prepares a route to the child worker thread.
128 // TODO(shimazu): Remove this function once mojofication is completed. 125 // TODO(shimazu): Remove this function once mojofication is completed.
129 void BindWorkerToProcess(int process_id, int embedded_worker_id); 126 void BindWorkerToProcess(int process_id, int embedded_worker_id);
130 127
131 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. 128 // RemoveWorker is called when EmbeddedWorkerInstance is destructed.
132 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) 129 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID)
133 // if it's not running. 130 // if it's not running.
134 void RemoveWorker(int process_id, int embedded_worker_id); 131 void RemoveWorker(int process_id, int embedded_worker_id);
135 // DetachWorker is called when EmbeddedWorkerInstance releases a process. 132 // DetachWorker is called when EmbeddedWorkerInstance releases a process.
136 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID) 133 // |process_id| could be invalid (i.e. ChildProcessHost::kInvalidUniqueID)
137 // if it's not running. 134 // if it's not running.
138 void DetachWorker(int process_id, int embedded_worker_id); 135 void DetachWorker(int process_id, int embedded_worker_id);
139 136
140 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id, 137 EmbeddedWorkerInstance* GetWorkerForMessage(int process_id,
141 int embedded_worker_id); 138 int embedded_worker_id);
142 139
143 base::WeakPtr<ServiceWorkerContextCore> context_; 140 base::WeakPtr<ServiceWorkerContextCore> context_;
144 141
145 WorkerInstanceMap worker_map_; 142 WorkerInstanceMap worker_map_;
146 ProcessToSenderMap process_sender_map_;
147 ProcessToMessagePortMessageFilterMap process_message_port_message_filter_map_;
148 143
149 // Map from process_id to embedded_worker_id. 144 // Map from process_id to embedded_worker_id.
150 // This map only contains starting and running workers. 145 // This map only contains starting and running workers.
151 std::map<int, std::set<int> > worker_process_map_; 146 std::map<int, std::set<int> > worker_process_map_;
152 147
153 int next_embedded_worker_id_; 148 int next_embedded_worker_id_;
154 const int initial_embedded_worker_id_; 149 const int initial_embedded_worker_id_;
155 150
156 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); 151 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry);
157 }; 152 };
158 153
159 } // namespace content 154 } // namespace content
160 155
161 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ 156 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698