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

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

Issue 299693002: Add option to open the DevTools window for ServiceWorker on start in serviceworker-internals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 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 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( 171 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker(
172 int worker_process_id, 172 int worker_process_id,
173 int worker_route_id) { 173 int worker_route_id) {
174 WorkerId id(worker_process_id, worker_route_id); 174 WorkerId id(worker_process_id, worker_route_id);
175 175
176 WorkerInfoMap::iterator it = workers_.find(id); 176 WorkerInfoMap::iterator it = workers_.find(id);
177 if (it == workers_.end()) 177 if (it == workers_.end())
178 return NULL; 178 return NULL;
179 179
180 WorkerInfo* info = it->second; 180 WorkerInfo* info = it->second;
181 if (info->state() != WORKER_UNINSPECTED) 181 if (info->state() != WORKER_UNINSPECTED &&
182 info->state() != WORKER_PAUSED_FOR_DEBUG_ON_START) {
182 return info->agent_host(); 183 return info->agent_host();
184 }
183 185
184 EmbeddedWorkerDevToolsAgentHost* agent_host = 186 EmbeddedWorkerDevToolsAgentHost* agent_host =
185 new EmbeddedWorkerDevToolsAgentHost(id); 187 new EmbeddedWorkerDevToolsAgentHost(id);
186 info->set_agent_host(agent_host); 188 info->set_agent_host(agent_host);
187 info->set_state(WORKER_INSPECTED); 189 info->set_state(WORKER_INSPECTED);
188 return agent_host; 190 return agent_host;
189 } 191 }
190 192
191 DevToolsAgentHost* 193 DevToolsAgentHost*
192 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( 194 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker(
193 const ServiceWorkerIdentifier& service_worker_id) { 195 const ServiceWorkerIdentifier& service_worker_id) {
194 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 196 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id);
195 if (it == workers_.end()) 197 if (it == workers_.end())
196 return NULL; 198 return NULL;
197 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); 199 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second);
198 } 200 }
199 201
200 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { 202 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager()
203 : debug_service_worker_on_start_(false) {
201 } 204 }
202 205
203 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { 206 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() {
204 } 207 }
205 208
206 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( 209 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated(
207 int worker_process_id, 210 int worker_process_id,
208 int worker_route_id, 211 int worker_route_id,
209 const SharedWorkerInstance& instance) { 212 const SharedWorkerInstance& instance) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 10 matching lines...) Expand all
221 224
222 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( 225 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated(
223 int worker_process_id, 226 int worker_process_id,
224 int worker_route_id, 227 int worker_route_id,
225 const ServiceWorkerIdentifier& service_worker_id) { 228 const ServiceWorkerIdentifier& service_worker_id) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
227 const WorkerId id(worker_process_id, worker_route_id); 230 const WorkerId id(worker_process_id, worker_route_id);
228 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 231 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id);
229 if (it == workers_.end()) { 232 if (it == workers_.end()) {
230 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); 233 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id));
234 if (debug_service_worker_on_start_)
235 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START);
231 workers_.set(id, info.Pass()); 236 workers_.set(id, info.Pass());
232 return false; 237 return debug_service_worker_on_start_;
233 } 238 }
234 MoveToPausedState(id, it); 239 MoveToPausedState(id, it);
235 return true; 240 return true;
236 } 241 }
237 242
238 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, 243 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
239 int worker_route_id) { 244 int worker_route_id) {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
241 const WorkerId id(worker_process_id, worker_route_id); 246 const WorkerId id(worker_process_id, worker_route_id);
242 WorkerInfoMap::iterator it = workers_.find(id); 247 WorkerInfoMap::iterator it = workers_.find(id);
243 DCHECK(it != workers_.end()); 248 DCHECK(it != workers_.end());
244 WorkerInfo* info = it->second; 249 WorkerInfo* info = it->second;
245 switch (info->state()) { 250 switch (info->state()) {
246 case WORKER_UNINSPECTED: 251 case WORKER_UNINSPECTED:
252 case WORKER_PAUSED_FOR_DEBUG_ON_START:
247 workers_.erase(it); 253 workers_.erase(it);
248 break; 254 break;
249 case WORKER_INSPECTED: { 255 case WORKER_INSPECTED: {
250 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); 256 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host();
251 if (!agent_host->IsAttached()) { 257 if (!agent_host->IsAttached()) {
252 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); 258 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it);
253 agent_host->DetachFromWorker(); 259 agent_host->DetachFromWorker();
254 return; 260 return;
255 } 261 }
256 info->set_state(WORKER_TERMINATED); 262 info->set_state(WORKER_TERMINATED);
257 // Client host is debugging this worker agent host. 263 // Client host is debugging this worker agent host.
258 std::string notification = 264 std::string notification =
259 DevToolsProtocol::CreateNotification( 265 DevToolsProtocol::CreateNotification(
260 devtools::Worker::disconnectedFromWorker::kName, NULL) 266 devtools::Worker::disconnectedFromWorker::kName, NULL)
261 ->Serialize(); 267 ->Serialize();
262 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( 268 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
263 agent_host, notification); 269 agent_host, notification);
264 agent_host->DetachFromWorker(); 270 agent_host->DetachFromWorker();
265 break; 271 break;
266 } 272 }
267 case WORKER_TERMINATED: 273 case WORKER_TERMINATED:
268 NOTREACHED(); 274 NOTREACHED();
269 break; 275 break;
270 case WORKER_PAUSED: { 276 case WORKER_PAUSED_FOR_REATTACH: {
271 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); 277 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it);
272 worker_info->set_state(WORKER_TERMINATED); 278 worker_info->set_state(WORKER_TERMINATED);
273 const WorkerId old_id = worker_info->agent_host()->worker_id(); 279 const WorkerId old_id = worker_info->agent_host()->worker_id();
274 workers_.set(old_id, worker_info.Pass()); 280 workers_.set(old_id, worker_info.Pass());
275 break; 281 break;
276 } 282 }
277 } 283 }
278 } 284 }
279 285
280 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, 286 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id,
281 int worker_route_id) { 287 int worker_route_id) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
283 const WorkerId id(worker_process_id, worker_route_id); 289 const WorkerId id(worker_process_id, worker_route_id);
284 WorkerInfoMap::iterator it = workers_.find(id); 290 WorkerInfoMap::iterator it = workers_.find(id);
285 DCHECK(it != workers_.end()); 291 DCHECK(it != workers_.end());
286 WorkerInfo* info = it->second; 292 WorkerInfo* info = it->second;
287 if (info->state() != WORKER_PAUSED) 293 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) {
288 return; 294 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id);
289 info->agent_host()->ReattachToWorker(id); 295 scoped_refptr<DevToolsAgentHost> agent_host(
290 info->set_state(WORKER_INSPECTED); 296 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id));
297 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(),
298 agent_host.get());
299 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) {
300 info->agent_host()->ReattachToWorker(id);
301 info->set_state(WORKER_INSPECTED);
302 }
291 } 303 }
292 304
293 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( 305 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData(
294 EmbeddedWorkerDevToolsAgentHost* agent_host) { 306 EmbeddedWorkerDevToolsAgentHost* agent_host) {
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
296 const WorkerId id(agent_host->worker_id()); 308 const WorkerId id(agent_host->worker_id());
297 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); 309 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id);
298 if (worker_info) { 310 if (worker_info) {
299 DCHECK_EQ(WORKER_TERMINATED, worker_info->state()); 311 DCHECK_EQ(WORKER_TERMINATED, worker_info->state());
300 return; 312 return;
301 } 313 }
302 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); 314 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end();
303 ++it) { 315 ++it) {
304 if (it->second->agent_host() == agent_host) { 316 if (it->second->agent_host() == agent_host) {
305 DCHECK_EQ(WORKER_PAUSED, it->second->state()); 317 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state());
306 SendMessageToWorker( 318 SendMessageToWorker(
307 it->first, 319 it->first,
308 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); 320 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second));
309 it->second->set_agent_host(NULL); 321 it->second->set_agent_host(NULL);
310 it->second->set_state(WORKER_UNINSPECTED); 322 it->second->set_state(WORKER_UNINSPECTED);
311 return; 323 return;
312 } 324 }
313 } 325 }
314 } 326 }
315 327
(...skipping 17 matching lines...) Expand all
333 break; 345 break;
334 } 346 }
335 return it; 347 return it;
336 } 348 }
337 349
338 void EmbeddedWorkerDevToolsManager::MoveToPausedState( 350 void EmbeddedWorkerDevToolsManager::MoveToPausedState(
339 const WorkerId& id, 351 const WorkerId& id,
340 const WorkerInfoMap::iterator& it) { 352 const WorkerInfoMap::iterator& it) {
341 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); 353 DCHECK_EQ(WORKER_TERMINATED, it->second->state());
342 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); 354 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it);
343 info->set_state(WORKER_PAUSED); 355 info->set_state(WORKER_PAUSED_FOR_REATTACH);
344 workers_.set(id, info.Pass()); 356 workers_.set(id, info.Pass());
345 } 357 }
346 358
347 void EmbeddedWorkerDevToolsManager::ResetForTesting() { 359 void EmbeddedWorkerDevToolsManager::ResetForTesting() {
348 workers_.clear(); 360 workers_.clear();
349 } 361 }
350 362
351 } // namespace content 363 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698