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

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, 7 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( 50 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches(
51 const ServiceWorkerIdentifier& other) const { 51 const ServiceWorkerIdentifier& other) const {
52 return service_worker_context_ == other.service_worker_context_ && 52 return service_worker_context_ == other.service_worker_context_ &&
53 service_worker_version_id_ == other.service_worker_version_id_; 53 service_worker_version_id_ == other.service_worker_version_id_;
54 } 54 }
55 55
56 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( 56 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo(
57 const SharedWorkerInstance& instance) 57 const SharedWorkerInstance& instance)
58 : shared_worker_instance_(new SharedWorkerInstance(instance)), 58 : shared_worker_instance_(new SharedWorkerInstance(instance)),
59 debug_on_start_(false),
59 state_(WORKER_UNINSPECTED), 60 state_(WORKER_UNINSPECTED),
60 agent_host_(NULL) { 61 agent_host_(NULL) {
61 } 62 }
62 63
63 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( 64 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo(
64 const ServiceWorkerIdentifier& service_worker_id) 65 const ServiceWorkerIdentifier& service_worker_id,
66 bool debug_on_start)
65 : service_worker_id_(new ServiceWorkerIdentifier(service_worker_id)), 67 : service_worker_id_(new ServiceWorkerIdentifier(service_worker_id)),
68 debug_on_start_(debug_on_start),
66 state_(WORKER_UNINSPECTED), 69 state_(WORKER_UNINSPECTED),
67 agent_host_(NULL) { 70 agent_host_(NULL) {
68 } 71 }
69 72
70 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( 73 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches(
71 const SharedWorkerInstance& other) { 74 const SharedWorkerInstance& other) {
72 if (!shared_worker_instance_) 75 if (!shared_worker_instance_)
73 return false; 76 return false;
74 return shared_worker_instance_->Matches(other); 77 return shared_worker_instance_->Matches(other);
75 } 78 }
76 79
77 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( 80 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches(
78 const ServiceWorkerIdentifier& other) { 81 const ServiceWorkerIdentifier& other) {
79 if (!service_worker_id_) 82 if (!service_worker_id_)
80 return false; 83 return false;
81 return service_worker_id_->Matches(other); 84 return service_worker_id_->Matches(other);
82 } 85 }
83 86
84 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { 87 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() {
85 } 88 }
86 89
87 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost 90 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost
88 : public IPCDevToolsAgentHost, 91 : public IPCDevToolsAgentHost,
89 public IPC::Listener { 92 public IPC::Listener {
90 public: 93 public:
91 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) 94 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id,
92 : worker_id_(worker_id), worker_attached_(true) { 95 bool debug_on_start)
96 : worker_id_(worker_id),
97 worker_attached_(true) {
93 AddRef(); 98 AddRef();
94 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 99 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
95 host->AddRoute(worker_id_.second, this); 100 host->AddRoute(worker_id_.second, this);
96 } 101 }
97 102
98 // DevToolsAgentHost override. 103 // DevToolsAgentHost override.
99 virtual bool IsWorker() const OVERRIDE { return true; } 104 virtual bool IsWorker() const OVERRIDE { return true; }
100 105
101 // IPCDevToolsAgentHost implementation. 106 // IPCDevToolsAgentHost implementation.
102 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { 107 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 180
176 WorkerInfoMap::iterator it = workers_.find(id); 181 WorkerInfoMap::iterator it = workers_.find(id);
177 if (it == workers_.end()) 182 if (it == workers_.end())
178 return NULL; 183 return NULL;
179 184
180 WorkerInfo* info = it->second; 185 WorkerInfo* info = it->second;
181 if (info->state() != WORKER_UNINSPECTED) 186 if (info->state() != WORKER_UNINSPECTED)
182 return info->agent_host(); 187 return info->agent_host();
183 188
184 EmbeddedWorkerDevToolsAgentHost* agent_host = 189 EmbeddedWorkerDevToolsAgentHost* agent_host =
185 new EmbeddedWorkerDevToolsAgentHost(id); 190 new EmbeddedWorkerDevToolsAgentHost(id, info->debug_on_start());
186 info->set_agent_host(agent_host); 191 info->set_agent_host(agent_host);
187 info->set_state(WORKER_INSPECTED); 192 info->set_state(WORKER_INSPECTED);
188 return agent_host; 193 return agent_host;
189 } 194 }
190 195
191 DevToolsAgentHost* 196 DevToolsAgentHost*
192 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( 197 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker(
193 const ServiceWorkerIdentifier& service_worker_id) { 198 const ServiceWorkerIdentifier& service_worker_id) {
194 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 199 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id);
195 if (it == workers_.end()) 200 if (it == workers_.end())
196 return NULL; 201 return NULL;
197 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); 202 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second);
198 } 203 }
199 204
200 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { 205 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager()
206 : debug_service_worker_on_start_(false) {
201 } 207 }
202 208
203 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { 209 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() {
204 } 210 }
205 211
206 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( 212 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated(
207 int worker_process_id, 213 int worker_process_id,
208 int worker_route_id, 214 int worker_route_id,
209 const SharedWorkerInstance& instance) { 215 const SharedWorkerInstance& instance) {
210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
211 const WorkerId id(worker_process_id, worker_route_id); 217 const WorkerId id(worker_process_id, worker_route_id);
212 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); 218 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance);
213 if (it == workers_.end()) { 219 if (it == workers_.end()) {
214 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); 220 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance));
215 workers_.set(id, info.Pass()); 221 workers_.set(id, info.Pass());
216 return false; 222 return false;
217 } 223 }
218 MoveToPausedState(id, it); 224 MoveToPausedState(id, it);
219 return true; 225 return true;
220 } 226 }
221 227
222 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( 228 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated(
223 int worker_process_id, 229 int worker_process_id,
224 int worker_route_id, 230 int worker_route_id,
225 const ServiceWorkerIdentifier& service_worker_id) { 231 const ServiceWorkerIdentifier& service_worker_id) {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
227 const WorkerId id(worker_process_id, worker_route_id); 233 const WorkerId id(worker_process_id, worker_route_id);
228 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); 234 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id);
229 if (it == workers_.end()) { 235 if (it == workers_.end()) {
230 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); 236 scoped_ptr<WorkerInfo> info(
237 new WorkerInfo(service_worker_id, debug_service_worker_on_start_));
231 workers_.set(id, info.Pass()); 238 workers_.set(id, info.Pass());
232 return false; 239 return debug_service_worker_on_start_;
233 } 240 }
234 MoveToPausedState(id, it); 241 MoveToPausedState(id, it);
235 return true; 242 return true;
236 } 243 }
237 244
238 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, 245 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id,
239 int worker_route_id) { 246 int worker_route_id) {
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
241 const WorkerId id(worker_process_id, worker_route_id); 248 const WorkerId id(worker_process_id, worker_route_id);
242 WorkerInfoMap::iterator it = workers_.find(id); 249 WorkerInfoMap::iterator it = workers_.find(id);
(...skipping 17 matching lines...) Expand all
260 devtools::Worker::disconnectedFromWorker::kName, NULL) 267 devtools::Worker::disconnectedFromWorker::kName, NULL)
261 ->Serialize(); 268 ->Serialize();
262 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( 269 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(
263 agent_host, notification); 270 agent_host, notification);
264 agent_host->DetachFromWorker(); 271 agent_host->DetachFromWorker();
265 break; 272 break;
266 } 273 }
267 case WORKER_TERMINATED: 274 case WORKER_TERMINATED:
268 NOTREACHED(); 275 NOTREACHED();
269 break; 276 break;
270 case WORKER_PAUSED: { 277 case WORKER_PAUSED_FOR_REATTACH: {
271 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); 278 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it);
272 worker_info->set_state(WORKER_TERMINATED); 279 worker_info->set_state(WORKER_TERMINATED);
273 const WorkerId old_id = worker_info->agent_host()->worker_id(); 280 const WorkerId old_id = worker_info->agent_host()->worker_id();
274 workers_.set(old_id, worker_info.Pass()); 281 workers_.set(old_id, worker_info.Pass());
275 break; 282 break;
276 } 283 }
277 } 284 }
278 } 285 }
279 286
280 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, 287 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id,
281 int worker_route_id) { 288 int worker_route_id) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
283 const WorkerId id(worker_process_id, worker_route_id); 290 const WorkerId id(worker_process_id, worker_route_id);
284 WorkerInfoMap::iterator it = workers_.find(id); 291 WorkerInfoMap::iterator it = workers_.find(id);
285 DCHECK(it != workers_.end()); 292 DCHECK(it != workers_.end());
286 WorkerInfo* info = it->second; 293 WorkerInfo* info = it->second;
287 if (info->state() != WORKER_PAUSED) 294 if (info->state() != WORKER_PAUSED_FOR_REATTACH) {
295 if (!info->debug_on_start())
yurys 2014/05/27 12:02:31 Why is it not enough to check debug_service_worker
horo 2014/05/27 12:29:27 It is because debug_service_worker_on_start_ could
yurys 2014/05/27 14:22:48 I see. That makes sense. I'd rather we used a new
296 return;
297 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id);
298 scoped_refptr<DevToolsAgentHost> agent_host(
299 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id));
300 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(),
301 agent_host.get());
288 return; 302 return;
303 }
289 info->agent_host()->ReattachToWorker(id); 304 info->agent_host()->ReattachToWorker(id);
290 info->set_state(WORKER_INSPECTED); 305 info->set_state(WORKER_INSPECTED);
291 } 306 }
292 307
293 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( 308 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData(
294 EmbeddedWorkerDevToolsAgentHost* agent_host) { 309 EmbeddedWorkerDevToolsAgentHost* agent_host) {
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
296 const WorkerId id(agent_host->worker_id()); 311 const WorkerId id(agent_host->worker_id());
297 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); 312 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id);
298 if (worker_info) { 313 if (worker_info) {
299 DCHECK_EQ(WORKER_TERMINATED, worker_info->state()); 314 DCHECK_EQ(WORKER_TERMINATED, worker_info->state());
300 return; 315 return;
301 } 316 }
302 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); 317 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end();
303 ++it) { 318 ++it) {
304 if (it->second->agent_host() == agent_host) { 319 if (it->second->agent_host() == agent_host) {
305 DCHECK_EQ(WORKER_PAUSED, it->second->state()); 320 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state());
306 SendMessageToWorker( 321 SendMessageToWorker(
307 it->first, 322 it->first,
308 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); 323 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second));
309 it->second->set_agent_host(NULL); 324 it->second->set_agent_host(NULL);
310 it->second->set_state(WORKER_UNINSPECTED); 325 it->second->set_state(WORKER_UNINSPECTED);
311 return; 326 return;
312 } 327 }
313 } 328 }
314 } 329 }
315 330
(...skipping 17 matching lines...) Expand all
333 break; 348 break;
334 } 349 }
335 return it; 350 return it;
336 } 351 }
337 352
338 void EmbeddedWorkerDevToolsManager::MoveToPausedState( 353 void EmbeddedWorkerDevToolsManager::MoveToPausedState(
339 const WorkerId& id, 354 const WorkerId& id,
340 const WorkerInfoMap::iterator& it) { 355 const WorkerInfoMap::iterator& it) {
341 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); 356 DCHECK_EQ(WORKER_TERMINATED, it->second->state());
342 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); 357 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it);
343 info->set_state(WORKER_PAUSED); 358 info->set_state(WORKER_PAUSED_FOR_REATTACH);
344 workers_.set(id, info.Pass()); 359 workers_.set(id, info.Pass());
345 } 360 }
346 361
347 void EmbeddedWorkerDevToolsManager::ResetForTesting() { 362 void EmbeddedWorkerDevToolsManager::ResetForTesting() {
348 workers_.clear(); 363 workers_.clear();
349 } 364 }
350 365
351 } // namespace content 366 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698