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

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: Encapsulated EWDTAH from EWDTM 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 WorkerCreated();
84 }
85
86 EmbeddedWorkerDevToolsAgentHost(
87 WorkerId worker_id,
88 const ServiceWorkerIdentifier& service_worker,
89 bool debug_service_worker_on_start)
90 : service_worker_(new ServiceWorkerIdentifier(service_worker)),
91 state_(WORKER_UNINSPECTED),
92 worker_id_(worker_id) {
93 if (debug_service_worker_on_start)
94 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START;
95 WorkerCreated();
103 } 96 }
104 97
105 // DevToolsAgentHost override. 98 // DevToolsAgentHost override.
106 virtual bool IsWorker() const OVERRIDE { return true; } 99 virtual bool IsWorker() const OVERRIDE { return true; }
107 100
108 // IPCDevToolsAgentHost implementation. 101 // IPCDevToolsAgentHost implementation.
109 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { 102 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
110 if (worker_attached_) 103 if (state_ == WORKER_INSPECTED)
111 SendMessageToWorker(worker_id_, message); 104 SendMessageToWorker(worker_id_, message);
112 else 105 else
113 delete message; 106 delete message;
114 } 107 }
108
115 virtual void Attach() OVERRIDE { 109 virtual void Attach() OVERRIDE {
116 AttachToWorker(); 110 if (state_ != WORKER_INSPECTED) {
111 state_ = WORKER_INSPECTED;
112 AttachToWorker();
113 }
117 IPCDevToolsAgentHost::Attach(); 114 IPCDevToolsAgentHost::Attach();
118 } 115 }
116
119 virtual void OnClientAttached() OVERRIDE {} 117 virtual void OnClientAttached() OVERRIDE {}
120 virtual void OnClientDetached() OVERRIDE { DetachFromWorker(); } 118
119 virtual void OnClientDetached() OVERRIDE {
120 if (state_ == WORKER_INSPECTED) {
121 state_ = WORKER_UNINSPECTED;
122 DetachFromWorker();
123 }
124 }
121 125
122 // IPC::Listener implementation. 126 // IPC::Listener implementation.
123 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { 127 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 bool handled = true; 129 bool handled = true;
126 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg) 130 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg)
127 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, 131 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
128 OnDispatchOnInspectorFrontend) 132 OnDispatchOnInspectorFrontend)
129 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, 133 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState,
130 OnSaveAgentRuntimeState) 134 OnSaveAgentRuntimeState)
131 IPC_MESSAGE_UNHANDLED(handled = false) 135 IPC_MESSAGE_UNHANDLED(handled = false)
132 IPC_END_MESSAGE_MAP() 136 IPC_END_MESSAGE_MAP()
133 return handled; 137 return handled;
134 } 138 }
135 139
136 void ReattachToWorker(WorkerId worker_id) { 140 void WorkerContextStarted() {
137 CHECK(!worker_attached_); 141 if (state_ == WORKER_PAUSED_FOR_DEBUG_ON_START) {
142 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first);
143 DevToolsManagerImpl::GetInstance()->Inspect(
144 rph->GetBrowserContext(), this);
145 } else if (state_ == WORKER_PAUSED_FOR_REATTACH && IsAttached()) {
146 state_ = WORKER_INSPECTED;
147 AttachToWorker();
148 Reattach(saved_agent_state_);
149 }
150 }
151
152 void WorkerRestarted(WorkerId worker_id) {
153 DCHECK_EQ(state_, WORKER_TERMINATED);
dgozman 2014/08/07 17:07:21 DCHECK_EQ (as well as other comparison macros like
154 state_ = WORKER_PAUSED_FOR_REATTACH;
138 worker_id_ = worker_id; 155 worker_id_ = worker_id;
139 if (!IsAttached()) 156 WorkerCreated();
140 return; 157 }
141 AttachToWorker(); 158
142 Reattach(state_); 159 void WorkerDestroyed() {
160 DCHECK_NE(state_, WORKER_TERMINATED);
161 if (state_ == WORKER_INSPECTED) {
162 DCHECK(IsAttached());
163 // Client host is debugging this worker agent host.
164 std::string notification =
165 DevToolsProtocol::CreateNotification(
166 devtools::Worker::disconnectedFromWorker::kName, NULL)
167 ->Serialize();
168 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
169 this, notification);
170 DetachFromWorker();
171 }
172 state_ = WORKER_TERMINATED;
173 Release(); // Balanced in WorkerCreated()
174 }
175
176 bool Matches(const SharedWorkerInstance& other) {
177 return shared_worker_ && shared_worker_->Matches(other);
178 }
179
180 bool Matches(const ServiceWorkerIdentifier& other) {
181 return service_worker_ && service_worker_->Matches(other);
182 }
183
184 private:
185 virtual ~EmbeddedWorkerDevToolsAgentHost() {
186 CHECK_EQ(state_, WORKER_TERMINATED);
dgozman 2014/08/07 17:07:21 DCHECK_EQ
187 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(
188 worker_id_);
189 }
190
191 void AttachToWorker() {
192 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
193 host->AddRoute(worker_id_.second, this);
143 } 194 }
144 195
145 void DetachFromWorker() { 196 void DetachFromWorker() {
146 if (!worker_attached_)
147 return;
148 worker_attached_ = false;
149 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 197 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
150 host->RemoveRoute(worker_id_.second); 198 host->RemoveRoute(worker_id_.second);
151 Release();
152 } 199 }
153 200
154 WorkerId worker_id() const { return worker_id_; } 201 void WorkerCreated() {
155 202 AddRef(); // Balanced in WorkerDestroyed()
156 private:
157 virtual ~EmbeddedWorkerDevToolsAgentHost() {
158 CHECK(!worker_attached_);
159 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData(
160 this);
161 } 203 }
162 204
163 void OnDispatchOnInspectorFrontend(const std::string& message) { 205 void OnDispatchOnInspectorFrontend(const std::string& message) {
164 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, 206 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this,
165 message); 207 message);
166 } 208 }
167 209
168 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } 210 void OnSaveAgentRuntimeState(const std::string& state) {
169 211 saved_agent_state_ = state;
170 void AttachToWorker() {
171 if (worker_attached_)
172 return;
173 worker_attached_ = true;
174 AddRef();
175 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
176 host->AddRoute(worker_id_.second, this);
177 } 212 }
178 213
214 scoped_ptr<SharedWorkerInstance> shared_worker_;
215 scoped_ptr<ServiceWorkerIdentifier> service_worker_;
216 WorkerState state_;
179 WorkerId worker_id_; 217 WorkerId worker_id_;
180 bool worker_attached_; 218 std::string saved_agent_state_;
181 std::string state_;
182 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); 219 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost);
183 }; 220 };
184 221
185 // static 222 // static
186 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { 223 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188 return Singleton<EmbeddedWorkerDevToolsManager>::get(); 225 return Singleton<EmbeddedWorkerDevToolsManager>::get();
189 } 226 }
190 227
191 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( 228 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
192 int worker_process_id, 229 int worker_process_id,
193 int worker_route_id) { 230 int worker_route_id) {
194 WorkerId id(worker_process_id, worker_route_id); 231 AgentHostMap::iterator it = workers_.find(
195 232 WorkerId(worker_process_id, worker_route_id));
196 WorkerInfoMap::iterator it = workers_.find(id); 233 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 } 234 }
212 235
213 DevToolsAgentHost* 236 DevToolsAgentHost*
214 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( 237 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker(
215 const ServiceWorkerIdentifier& service_worker_id) { 238 const ServiceWorkerIdentifier& service_worker_id) {
216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 239 AgentHostMap::iterator it =
240 FindExistingServiceWorkerAgentHost(service_worker_id);
217 if (it == workers_.end()) 241 if (it == workers_.end())
218 return NULL; 242 return NULL;
219 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); 243 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second);
220 } 244 }
221 245
222 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() 246 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager()
223 : debug_service_worker_on_start_(false) { 247 : debug_service_worker_on_start_(false) {
224 } 248 }
225 249
226 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { 250 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() {
227 } 251 }
228 252
229 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( 253 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated(
230 int worker_process_id, 254 int worker_process_id,
231 int worker_route_id, 255 int worker_route_id,
232 const SharedWorkerInstance& instance) { 256 const SharedWorkerInstance& instance) {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 const WorkerId id(worker_process_id, worker_route_id); 258 const WorkerId id(worker_process_id, worker_route_id);
235 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); 259 AgentHostMap::iterator it = FindExistingSharedWorkerAgentHost(instance);
236 if (it == workers_.end()) { 260 if (it == workers_.end()) {
237 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); 261 workers_[id] = new EmbeddedWorkerDevToolsAgentHost(id, instance);
238 workers_.set(id, info.Pass());
239 return false; 262 return false;
240 } 263 }
241 MoveToPausedState(id, it); 264 WorkerRestarted(id, it);
242 return true; 265 return true;
243 } 266 }
244 267
245 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( 268 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated(
246 int worker_process_id, 269 int worker_process_id,
247 int worker_route_id, 270 int worker_route_id,
248 const ServiceWorkerIdentifier& service_worker_id) { 271 const ServiceWorkerIdentifier& service_worker_id) {
249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
250 const WorkerId id(worker_process_id, worker_route_id); 273 const WorkerId id(worker_process_id, worker_route_id);
251 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 274 AgentHostMap::iterator it =
275 FindExistingServiceWorkerAgentHost(service_worker_id);
252 if (it == workers_.end()) { 276 if (it == workers_.end()) {
253 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); 277 workers_[id] = new EmbeddedWorkerDevToolsAgentHost(
254 if (debug_service_worker_on_start_) 278 id, service_worker_id, debug_service_worker_on_start_);
255 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START);
256 workers_.set(id, info.Pass());
257 return debug_service_worker_on_start_; 279 return debug_service_worker_on_start_;
258 } 280 }
259 MoveToPausedState(id, it); 281 WorkerRestarted(id, it);
260 return true; 282 return true;
261 } 283 }
262 284
263 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, 285 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
264 int worker_route_id) { 286 int worker_route_id) {
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
266 const WorkerId id(worker_process_id, worker_route_id); 288 const WorkerId id(worker_process_id, worker_route_id);
267 WorkerInfoMap::iterator it = workers_.find(id); 289 AgentHostMap::iterator it = workers_.find(id);
268 DCHECK(it != workers_.end()); 290 DCHECK(it != workers_.end());
269 WorkerInfo* info = it->second; 291 it->second->WorkerDestroyed();
270 switch (info->state()) {
271 case WORKER_UNINSPECTED:
272 case WORKER_PAUSED_FOR_DEBUG_ON_START:
273 workers_.erase(it);
274 break;
275 case WORKER_INSPECTED: {
276 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host();
277 info->set_state(WORKER_TERMINATED);
278 if (!agent_host->IsAttached()) {
279 agent_host->DetachFromWorker();
280 return;
281 }
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 break;
291 }
292 case WORKER_TERMINATED:
293 NOTREACHED();
294 break;
295 case WORKER_PAUSED_FOR_REATTACH: {
296 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it);
297 worker_info->set_state(WORKER_TERMINATED);
298 const WorkerId old_id = worker_info->agent_host()->worker_id();
299 workers_.set(old_id, worker_info.Pass());
300 break;
301 }
302 }
303 } 292 }
304 293
305 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, 294 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id,
306 int worker_route_id) { 295 int worker_route_id) {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
308 const WorkerId id(worker_process_id, worker_route_id); 297 const WorkerId id(worker_process_id, worker_route_id);
309 WorkerInfoMap::iterator it = workers_.find(id); 298 AgentHostMap::iterator it = workers_.find(id);
310 DCHECK(it != workers_.end()); 299 DCHECK(it != workers_.end());
311 WorkerInfo* info = it->second; 300 it->second->WorkerContextStarted();
312 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) {
313 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id);
314 scoped_refptr<DevToolsAgentHost> agent_host(
315 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id));
316 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(),
317 agent_host.get());
318 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) {
319 info->agent_host()->ReattachToWorker(id);
320 info->set_state(WORKER_INSPECTED);
321 }
322 } 301 }
323 302
324 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( 303 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) {
325 EmbeddedWorkerDevToolsAgentHost* agent_host) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
327 const WorkerId id(agent_host->worker_id()); 305 workers_.erase(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 } 306 }
352 307
353 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator 308 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator
354 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( 309 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerAgentHost(
355 const SharedWorkerInstance& instance) { 310 const SharedWorkerInstance& instance) {
356 WorkerInfoMap::iterator it = workers_.begin(); 311 AgentHostMap::iterator it = workers_.begin();
357 for (; it != workers_.end(); ++it) { 312 for (; it != workers_.end(); ++it) {
358 if (it->second->Matches(instance)) 313 if (it->second->Matches(instance))
359 break; 314 break;
360 } 315 }
361 return it; 316 return it;
362 } 317 }
363 318
364 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator 319 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator
365 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( 320 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerAgentHost(
366 const ServiceWorkerIdentifier& service_worker_id) { 321 const ServiceWorkerIdentifier& service_worker_id) {
367 WorkerInfoMap::iterator it = workers_.begin(); 322 AgentHostMap::iterator it = workers_.begin();
368 for (; it != workers_.end(); ++it) { 323 for (; it != workers_.end(); ++it) {
369 if (it->second->Matches(service_worker_id)) 324 if (it->second->Matches(service_worker_id))
370 break; 325 break;
371 } 326 }
372 return it; 327 return it;
373 } 328 }
374 329
375 void EmbeddedWorkerDevToolsManager::MoveToPausedState( 330 void EmbeddedWorkerDevToolsManager::WorkerRestarted(
376 const WorkerId& id, 331 const WorkerId& id,
377 const WorkerInfoMap::iterator& it) { 332 const AgentHostMap::iterator& it) {
378 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); 333 EmbeddedWorkerDevToolsAgentHost* agent_host = it->second;
379 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); 334 agent_host->WorkerRestarted(id);
380 info->set_state(WORKER_PAUSED_FOR_REATTACH); 335 workers_.erase(it);
381 workers_.set(id, info.Pass()); 336 workers_[id] = agent_host;
382 } 337 }
383 338
384 void EmbeddedWorkerDevToolsManager::ResetForTesting() { 339 void EmbeddedWorkerDevToolsManager::ResetForTesting() {
385 workers_.clear(); 340 workers_.clear();
386 } 341 }
387 342
388 } // namespace content 343 } // 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