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

Side by Side Diff: content/browser/devtools/embedded_worker_devtools_manager.cc

Issue 405603002: DevTools: Merge WorkerInfo into EmbeddedWorkerDevToolsAgentHost (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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
« no previous file with comments | « content/browser/devtools/embedded_worker_devtools_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/browser/devtools/embedded_worker_devtools_manager.h" 5 #include "content/browser/devtools/embedded_worker_devtools_manager.h"
6 6
7 #include "content/browser/devtools/devtools_manager_impl.h" 7 #include "content/browser/devtools/devtools_manager_impl.h"
8 #include "content/browser/devtools/devtools_protocol.h" 8 #include "content/browser/devtools/devtools_protocol.h"
9 #include "content/browser/devtools/devtools_protocol_constants.h" 9 #include "content/browser/devtools/devtools_protocol_constants.h"
10 #include "content/browser/devtools/ipc_devtools_agent_host.h" 10 #include "content/browser/devtools/ipc_devtools_agent_host.h"
(...skipping 23 matching lines...) Expand all
34 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); 34 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first);
35 if (!host) { 35 if (!host) {
36 delete message; 36 delete message;
37 return false; 37 return false;
38 } 38 }
39 message->set_routing_id(worker_id.second); 39 message->set_routing_id(worker_id.second);
40 host->Send(message); 40 host->Send(message);
41 return true; 41 return true;
42 } 42 }
43 43
44 enum WorkerState {
45 WORKER_UNINSPECTED,
46 WORKER_INSPECTED,
47 WORKER_TERMINATED,
48 WORKER_PAUSED_FOR_DEBUG_ON_START,
49 WORKER_PAUSED_FOR_REATTACH,
50 };
51
44 } // namespace 52 } // namespace
45 53
46 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( 54 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
47 const ServiceWorkerContextCore* const service_worker_context, 55 const ServiceWorkerContextCore* const service_worker_context,
48 int64 service_worker_version_id) 56 int64 service_worker_version_id)
49 : service_worker_context_(service_worker_context), 57 : service_worker_context_(service_worker_context),
50 service_worker_version_id_(service_worker_version_id) { 58 service_worker_version_id_(service_worker_version_id) {
51 } 59 }
52 60
53 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( 61 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier(
54 const ServiceWorkerIdentifier& other) 62 const ServiceWorkerIdentifier& other)
55 : service_worker_context_(other.service_worker_context_), 63 : service_worker_context_(other.service_worker_context_),
56 service_worker_version_id_(other.service_worker_version_id_) { 64 service_worker_version_id_(other.service_worker_version_id_) {
57 } 65 }
58 66
59 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( 67 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches(
60 const ServiceWorkerIdentifier& other) const { 68 const ServiceWorkerIdentifier& other) const {
61 return service_worker_context_ == other.service_worker_context_ && 69 return service_worker_context_ == other.service_worker_context_ &&
62 service_worker_version_id_ == other.service_worker_version_id_; 70 service_worker_version_id_ == other.service_worker_version_id_;
63 } 71 }
64 72
65 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo(
66 const SharedWorkerInstance& instance)
67 : shared_worker_instance_(new SharedWorkerInstance(instance)),
68 state_(WORKER_UNINSPECTED),
69 agent_host_(NULL) {
70 }
71
72 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo(
73 const ServiceWorkerIdentifier& service_worker_id)
74 : service_worker_id_(new ServiceWorkerIdentifier(service_worker_id)),
75 state_(WORKER_UNINSPECTED),
76 agent_host_(NULL) {
77 }
78
79 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches(
80 const SharedWorkerInstance& other) {
81 if (!shared_worker_instance_)
82 return false;
83 return shared_worker_instance_->Matches(other);
84 }
85
86 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches(
87 const ServiceWorkerIdentifier& other) {
88 if (!service_worker_id_)
89 return false;
90 return service_worker_id_->Matches(other);
91 }
92
93 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() {
94 }
95
96 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost 73 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost
97 : public IPCDevToolsAgentHost, 74 : public IPCDevToolsAgentHost,
98 public IPC::Listener { 75 public IPC::Listener {
99 public: 76 public:
100 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) 77 EmbeddedWorkerDevToolsAgentHost(
101 : worker_id_(worker_id), worker_attached_(false) { 78 WorkerId worker_id,
102 AttachToWorker(); 79 const SharedWorkerInstance& shared_worker)
80 : shared_worker_(new SharedWorkerInstance(shared_worker)),
81 state_(WORKER_UNINSPECTED),
82 worker_id_(worker_id),
83 worker_attached_(false) {
84 WorkerCreated();
85 }
86
87 EmbeddedWorkerDevToolsAgentHost(
88 WorkerId worker_id,
89 const ServiceWorkerIdentifier& service_worker)
90 : service_worker_(new ServiceWorkerIdentifier(service_worker)),
91 state_(WORKER_UNINSPECTED),
92 worker_id_(worker_id),
93 worker_attached_(false) {
94 WorkerCreated();
103 } 95 }
104 96
105 // DevToolsAgentHost override. 97 // DevToolsAgentHost override.
106 virtual bool IsWorker() const OVERRIDE { return true; } 98 virtual bool IsWorker() const OVERRIDE { return true; }
107 99
108 // IPCDevToolsAgentHost implementation. 100 // IPCDevToolsAgentHost implementation.
109 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { 101 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
110 if (worker_attached_) 102 if (worker_attached_)
111 SendMessageToWorker(worker_id_, message); 103 SendMessageToWorker(worker_id_, message);
112 else 104 else
113 delete message; 105 delete message;
114 } 106 }
115 virtual void Attach() OVERRIDE { 107 virtual void Attach() OVERRIDE {
116 AttachToWorker(); 108 AttachToWorker();
117 IPCDevToolsAgentHost::Attach(); 109 IPCDevToolsAgentHost::Attach();
118 } 110 }
119 virtual void OnClientAttached() OVERRIDE {} 111 virtual void OnClientAttached() OVERRIDE {}
120 virtual void OnClientDetached() OVERRIDE { DetachFromWorker(); } 112 virtual void OnClientDetached() OVERRIDE { DetachFromWorker(); }
dgozman 2014/08/06 10:11:36 You should check for WORKER_INSPECTED here and mov
vkuzkokov 2014/08/06 11:43:04 Added to DetachFromWorker
121 113
122 // IPC::Listener implementation. 114 // IPC::Listener implementation.
123 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { 115 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 bool handled = true; 117 bool handled = true;
126 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg) 118 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg)
127 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, 119 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
128 OnDispatchOnInspectorFrontend) 120 OnDispatchOnInspectorFrontend)
129 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, 121 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState,
130 OnSaveAgentRuntimeState) 122 OnSaveAgentRuntimeState)
131 IPC_MESSAGE_UNHANDLED(handled = false) 123 IPC_MESSAGE_UNHANDLED(handled = false)
132 IPC_END_MESSAGE_MAP() 124 IPC_END_MESSAGE_MAP()
133 return handled; 125 return handled;
134 } 126 }
135 127
136 void ReattachToWorker(WorkerId worker_id) { 128 void ReattachToWorker(WorkerId worker_id) {
137 CHECK(!worker_attached_); 129 CHECK(!worker_attached_);
138 worker_id_ = worker_id; 130 worker_id_ = worker_id;
139 if (!IsAttached()) 131 if (!IsAttached())
140 return; 132 return;
141 AttachToWorker(); 133 AttachToWorker();
142 Reattach(state_); 134 Reattach(saved_agent_state_);
143 } 135 }
144 136
145 void DetachFromWorker() { 137 void DetachFromWorker() {
146 if (!worker_attached_) 138 if (!worker_attached_)
147 return; 139 return;
148 worker_attached_ = false; 140 worker_attached_ = false;
149 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 141 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
150 host->RemoveRoute(worker_id_.second); 142 host->RemoveRoute(worker_id_.second);
143 }
144
145 void WorkerCreated() {
146 AddRef();
147 }
148
149 void WorkerDestroyed() {
151 Release(); 150 Release();
152 } 151 }
153 152
154 WorkerId worker_id() const { return worker_id_; } 153 WorkerId worker_id() const { return worker_id_; }
154 WorkerState state() const { return state_; }
155 void set_worker_id(WorkerId worker_id) { worker_id_ = worker_id; }
156 void set_state(WorkerState state) { state_ = state; };
157
158 bool Matches(const SharedWorkerInstance& other) {
159 return shared_worker_ && shared_worker_->Matches(other);
160 }
161
162 bool Matches(const ServiceWorkerIdentifier& other) {
163 return service_worker_ && service_worker_->Matches(other);
164 }
155 165
156 private: 166 private:
157 virtual ~EmbeddedWorkerDevToolsAgentHost() { 167 virtual ~EmbeddedWorkerDevToolsAgentHost() {
158 CHECK(!worker_attached_); 168 CHECK(!worker_attached_);
159 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( 169 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(
160 this); 170 this);
161 } 171 }
162 172
163 void OnDispatchOnInspectorFrontend(const std::string& message) { 173 void OnDispatchOnInspectorFrontend(const std::string& message) {
164 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, 174 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this,
165 message); 175 message);
166 } 176 }
167 177
168 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } 178 void OnSaveAgentRuntimeState(const std::string& state) {
179 saved_agent_state_ = state;
180 }
169 181
170 void AttachToWorker() { 182 void AttachToWorker() {
171 if (worker_attached_) 183 if (worker_attached_)
172 return; 184 return;
173 worker_attached_ = true; 185 worker_attached_ = true;
174 AddRef(); 186 set_state(WORKER_INSPECTED);
175 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 187 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
176 host->AddRoute(worker_id_.second, this); 188 host->AddRoute(worker_id_.second, this);
177 } 189 }
178 190
191 scoped_ptr<SharedWorkerInstance> shared_worker_;
192 scoped_ptr<ServiceWorkerIdentifier> service_worker_;
193 WorkerState state_;
179 WorkerId worker_id_; 194 WorkerId worker_id_;
180 bool worker_attached_; 195 bool worker_attached_;
181 std::string state_; 196 std::string saved_agent_state_;
182 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); 197 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost);
183 }; 198 };
184 199
185 // static 200 // static
186 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { 201 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188 return Singleton<EmbeddedWorkerDevToolsManager>::get(); 203 return Singleton<EmbeddedWorkerDevToolsManager>::get();
189 } 204 }
190 205
191 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( 206 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
192 int worker_process_id, 207 int worker_process_id,
193 int worker_route_id) { 208 int worker_route_id) {
194 WorkerId id(worker_process_id, worker_route_id); 209 AgentHostMap::iterator it = workers_.find(
195 210 WorkerId(worker_process_id, worker_route_id));
196 WorkerInfoMap::iterator it = workers_.find(id); 211 return it == workers_.end() ? NULL : it->second;
197 if (it == workers_.end())
198 return NULL;
199
200 WorkerInfo* info = it->second;
201 if (info->state() != WORKER_UNINSPECTED &&
202 info->state() != WORKER_PAUSED_FOR_DEBUG_ON_START) {
203 return info->agent_host();
204 }
205
206 EmbeddedWorkerDevToolsAgentHost* agent_host =
207 new EmbeddedWorkerDevToolsAgentHost(id);
208 info->set_agent_host(agent_host);
209 info->set_state(WORKER_INSPECTED);
210 return agent_host;
211 } 212 }
212 213
213 DevToolsAgentHost* 214 DevToolsAgentHost*
214 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( 215 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker(
215 const ServiceWorkerIdentifier& service_worker_id) { 216 const ServiceWorkerIdentifier& service_worker_id) {
216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 217 AgentHostMap::iterator it =
218 FindExistingServiceWorkerAgentHost(service_worker_id);
217 if (it == workers_.end()) 219 if (it == workers_.end())
218 return NULL; 220 return NULL;
219 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); 221 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second);
220 } 222 }
221 223
222 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() 224 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager()
223 : debug_service_worker_on_start_(false) { 225 : debug_service_worker_on_start_(false) {
224 } 226 }
225 227
226 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { 228 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() {
227 } 229 }
228 230
229 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( 231 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated(
230 int worker_process_id, 232 int worker_process_id,
231 int worker_route_id, 233 int worker_route_id,
232 const SharedWorkerInstance& instance) { 234 const SharedWorkerInstance& instance) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 const WorkerId id(worker_process_id, worker_route_id); 236 const WorkerId id(worker_process_id, worker_route_id);
235 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); 237 AgentHostMap::iterator it = FindExistingSharedWorkerAgentHost(instance);
236 if (it == workers_.end()) { 238 if (it == workers_.end()) {
237 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); 239 EmbeddedWorkerDevToolsAgentHost* agent_host =
yurys 2014/08/06 11:26:19 inline agent_host as it is used only once
vkuzkokov 2014/08/06 11:43:04 Done.
238 workers_.set(id, info.Pass()); 240 new EmbeddedWorkerDevToolsAgentHost(id, instance);
241 workers_[id] = agent_host;
239 return false; 242 return false;
240 } 243 }
241 MoveToPausedState(id, it); 244 WorkerRestarted(id, it);
242 return true; 245 return true;
243 } 246 }
244 247
245 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( 248 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated(
246 int worker_process_id, 249 int worker_process_id,
247 int worker_route_id, 250 int worker_route_id,
248 const ServiceWorkerIdentifier& service_worker_id) { 251 const ServiceWorkerIdentifier& service_worker_id) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
250 const WorkerId id(worker_process_id, worker_route_id); 253 const WorkerId id(worker_process_id, worker_route_id);
251 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 254 AgentHostMap::iterator it =
255 FindExistingServiceWorkerAgentHost(service_worker_id);
252 if (it == workers_.end()) { 256 if (it == workers_.end()) {
253 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); 257 EmbeddedWorkerDevToolsAgentHost* agent_host =
258 new EmbeddedWorkerDevToolsAgentHost(id, service_worker_id);
254 if (debug_service_worker_on_start_) 259 if (debug_service_worker_on_start_)
255 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); 260 agent_host->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START);
256 workers_.set(id, info.Pass()); 261 workers_[id] = agent_host;
257 return debug_service_worker_on_start_; 262 return debug_service_worker_on_start_;
258 } 263 }
259 MoveToPausedState(id, it); 264 WorkerRestarted(id, it);
260 return true; 265 return true;
261 } 266 }
262 267
263 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, 268 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
264 int worker_route_id) { 269 int worker_route_id) {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
266 const WorkerId id(worker_process_id, worker_route_id); 271 const WorkerId id(worker_process_id, worker_route_id);
267 WorkerInfoMap::iterator it = workers_.find(id); 272 AgentHostMap::iterator it = workers_.find(id);
268 DCHECK(it != workers_.end()); 273 DCHECK(it != workers_.end());
269 WorkerInfo* info = it->second; 274 EmbeddedWorkerDevToolsAgentHost* agent_host = it->second;
270 switch (info->state()) { 275 switch (agent_host->state()) {
271 case WORKER_UNINSPECTED: 276 case WORKER_UNINSPECTED:
272 case WORKER_PAUSED_FOR_DEBUG_ON_START: 277 case WORKER_PAUSED_FOR_DEBUG_ON_START:
273 workers_.erase(it); 278 agent_host->DetachFromWorker();
dgozman 2014/08/06 10:11:36 Calling DetachFromWorker here is strange. Agent ho
yurys 2014/08/06 11:26:19 I agree with Dmitry. Looks like we need a DCHECK h
vkuzkokov 2014/08/06 11:43:04 It is strange. Kept as DCHECK.
274 break; 279 break;
275 case WORKER_INSPECTED: { 280 case WORKER_INSPECTED: {
276 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); 281 if (agent_host->IsAttached()) {
dgozman 2014/08/06 10:11:36 How can agent host not be attached in this case?
vkuzkokov 2014/08/06 11:43:04 It most likely can't. Fixed.
277 info->set_state(WORKER_TERMINATED); 282 // Client host is debugging this worker agent host.
278 if (!agent_host->IsAttached()) { 283 std::string notification =
279 agent_host->DetachFromWorker(); 284 DevToolsProtocol::CreateNotification(
280 return; 285 devtools::Worker::disconnectedFromWorker::kName, NULL)
286 ->Serialize();
287 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
288 agent_host, notification);
281 } 289 }
282 // Client host is debugging this worker agent host.
283 std::string notification =
284 DevToolsProtocol::CreateNotification(
285 devtools::Worker::disconnectedFromWorker::kName, NULL)
286 ->Serialize();
287 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
288 agent_host, notification);
289 agent_host->DetachFromWorker(); 290 agent_host->DetachFromWorker();
290 break; 291 break;
291 } 292 }
292 case WORKER_TERMINATED: 293 case WORKER_TERMINATED:
293 NOTREACHED(); 294 NOTREACHED();
294 break; 295 break;
295 case WORKER_PAUSED_FOR_REATTACH: { 296 case WORKER_PAUSED_FOR_REATTACH: {
296 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); 297 workers_.erase(it);
297 worker_info->set_state(WORKER_TERMINATED); 298 workers_[agent_host->worker_id()] = agent_host;
yurys 2014/08/06 11:26:19 Isn't it->first == agent_host->worker_id() ?
vkuzkokov 2014/08/06 11:43:04 It didn't use to be. Now it is. Fixed.
298 const WorkerId old_id = worker_info->agent_host()->worker_id();
299 workers_.set(old_id, worker_info.Pass());
300 break; 299 break;
301 } 300 }
302 } 301 }
302 agent_host->set_state(WORKER_TERMINATED);
303 agent_host->WorkerDestroyed();
303 } 304 }
304 305
305 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, 306 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id,
306 int worker_route_id) { 307 int worker_route_id) {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
308 const WorkerId id(worker_process_id, worker_route_id); 309 const WorkerId id(worker_process_id, worker_route_id);
309 WorkerInfoMap::iterator it = workers_.find(id); 310 AgentHostMap::iterator it = workers_.find(id);
310 DCHECK(it != workers_.end()); 311 DCHECK(it != workers_.end());
311 WorkerInfo* info = it->second; 312 EmbeddedWorkerDevToolsAgentHost* agent_host = it->second;
312 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { 313 if (agent_host->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) {
313 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id); 314 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id);
314 scoped_refptr<DevToolsAgentHost> agent_host( 315 DevToolsManagerImpl::GetInstance()->Inspect(
315 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id)); 316 rph->GetBrowserContext(), agent_host);
316 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), 317 } else if (agent_host->state() == WORKER_PAUSED_FOR_REATTACH) {
317 agent_host.get()); 318 agent_host->ReattachToWorker(id);
318 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) {
319 info->agent_host()->ReattachToWorker(id);
320 info->set_state(WORKER_INSPECTED);
321 } 319 }
322 } 320 }
323 321
324 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( 322 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData(
325 EmbeddedWorkerDevToolsAgentHost* agent_host) { 323 EmbeddedWorkerDevToolsAgentHost* agent_host) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
327 const WorkerId id(agent_host->worker_id()); 325 workers_.erase(agent_host->worker_id());
328 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id);
329 if (worker_info) {
330 DCHECK_EQ(worker_info->agent_host(), agent_host);
331 if (worker_info->state() == WORKER_TERMINATED)
332 return;
333 DCHECK_EQ(worker_info->state(), WORKER_INSPECTED);
334 worker_info->set_agent_host(NULL);
335 worker_info->set_state(WORKER_UNINSPECTED);
336 workers_.set(id, worker_info.Pass());
337 return;
338 }
339 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end();
340 ++it) {
341 if (it->second->agent_host() == agent_host) {
342 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state());
343 SendMessageToWorker(
344 it->first,
345 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second));
346 it->second->set_agent_host(NULL);
347 it->second->set_state(WORKER_UNINSPECTED);
348 return;
349 }
350 }
351 } 326 }
352 327
353 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator 328 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator
354 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( 329 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerAgentHost(
355 const SharedWorkerInstance& instance) { 330 const SharedWorkerInstance& instance) {
356 WorkerInfoMap::iterator it = workers_.begin(); 331 AgentHostMap::iterator it = workers_.begin();
357 for (; it != workers_.end(); ++it) { 332 for (; it != workers_.end(); ++it) {
358 if (it->second->Matches(instance)) 333 if (it->second->Matches(instance))
359 break; 334 break;
360 } 335 }
361 return it; 336 return it;
362 } 337 }
363 338
364 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator 339 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator
365 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( 340 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerAgentHost(
366 const ServiceWorkerIdentifier& service_worker_id) { 341 const ServiceWorkerIdentifier& service_worker_id) {
367 WorkerInfoMap::iterator it = workers_.begin(); 342 AgentHostMap::iterator it = workers_.begin();
368 for (; it != workers_.end(); ++it) { 343 for (; it != workers_.end(); ++it) {
369 if (it->second->Matches(service_worker_id)) 344 if (it->second->Matches(service_worker_id))
370 break; 345 break;
371 } 346 }
372 return it; 347 return it;
373 } 348 }
374 349
375 void EmbeddedWorkerDevToolsManager::MoveToPausedState( 350 void EmbeddedWorkerDevToolsManager::WorkerRestarted(
376 const WorkerId& id, 351 const WorkerId& id,
377 const WorkerInfoMap::iterator& it) { 352 const AgentHostMap::iterator& it) {
378 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); 353 DCHECK_EQ(WORKER_TERMINATED, it->second->state());
379 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); 354 EmbeddedWorkerDevToolsAgentHost* agent_host = it->second;
380 info->set_state(WORKER_PAUSED_FOR_REATTACH); 355 agent_host->set_state(WORKER_PAUSED_FOR_REATTACH);
381 workers_.set(id, info.Pass()); 356 agent_host->set_worker_id(id);
357 agent_host->WorkerCreated();
358 workers_.erase(it);
359 workers_[id] = agent_host;
382 } 360 }
383 361
384 void EmbeddedWorkerDevToolsManager::ResetForTesting() { 362 void EmbeddedWorkerDevToolsManager::ResetForTesting() {
385 workers_.clear(); 363 workers_.clear();
386 } 364 }
387 365
388 } // namespace content 366 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/embedded_worker_devtools_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698