| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/protocol/service_worker_handler.h" | 5 #include "content/browser/devtools/protocol/service_worker_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 10 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 client_->DispatchMessage( | 293 client_->DispatchMessage( |
| 294 DispatchMessageParams::Create()-> | 294 DispatchMessageParams::Create()-> |
| 295 set_worker_id(host->GetId())-> | 295 set_worker_id(host->GetId())-> |
| 296 set_message(message)); | 296 set_message(message)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void ServiceWorkerHandler::AgentHostClosed( | 299 void ServiceWorkerHandler::AgentHostClosed( |
| 300 DevToolsAgentHost* host, | 300 DevToolsAgentHost* host, |
| 301 bool replaced_with_another_client) { | 301 bool replaced_with_another_client) { |
| 302 WorkerDestroyed(static_cast<ServiceWorkerDevToolsAgentHost*>(host)); | 302 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 303 set_worker_id(host->GetId())); |
| 304 attached_hosts_.erase(host->GetId()); |
| 303 } | 305 } |
| 304 | 306 |
| 305 void ServiceWorkerHandler::WorkerCreated( | 307 void ServiceWorkerHandler::WorkerCreated( |
| 306 ServiceWorkerDevToolsAgentHost* host) { | 308 ServiceWorkerDevToolsAgentHost* host) { |
| 307 auto hosts = GetMatchingServiceWorkers(urls_); | 309 auto hosts = GetMatchingServiceWorkers(urls_); |
| 308 if (hosts.find(host->GetId()) != hosts.end()) | 310 if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached()) |
| 309 host->PauseForDebugOnStart(); | 311 host->PauseForDebugOnStart(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 void ServiceWorkerHandler::WorkerReadyForInspection( | 314 void ServiceWorkerHandler::WorkerReadyForInspection( |
| 313 ServiceWorkerDevToolsAgentHost* host) { | 315 ServiceWorkerDevToolsAgentHost* host) { |
| 314 UpdateHosts(); | 316 UpdateHosts(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 void ServiceWorkerHandler::WorkerDestroyed( | 319 void ServiceWorkerHandler::WorkerDestroyed( |
| 318 ServiceWorkerDevToolsAgentHost* host) { | 320 ServiceWorkerDevToolsAgentHost* host) { |
| 319 UpdateHosts(); | 321 UpdateHosts(); |
| 320 } | 322 } |
| 321 | 323 |
| 322 void ServiceWorkerHandler::ReportWorkerCreated( | 324 void ServiceWorkerHandler::ReportWorkerCreated( |
| 323 ServiceWorkerDevToolsAgentHost* host) { | 325 ServiceWorkerDevToolsAgentHost* host) { |
| 324 if (host->IsAttached()) | 326 if (host->IsAttached()) |
| 325 return; | 327 return; |
| 326 attached_hosts_[host->GetId()] = host; | 328 attached_hosts_[host->GetId()] = host; |
| 327 host->AttachClient(this); | 329 host->AttachClient(this); |
| 328 client_->WorkerCreated(WorkerCreatedParams::Create()-> | 330 client_->WorkerCreated(WorkerCreatedParams::Create()-> |
| 329 set_worker_id(host->GetId())-> | 331 set_worker_id(host->GetId())-> |
| 330 set_url(host->GetURL().spec())); | 332 set_url(host->GetURL().spec())); |
| 331 } | 333 } |
| 332 | 334 |
| 333 void ServiceWorkerHandler::ReportWorkerTerminated( | 335 void ServiceWorkerHandler::ReportWorkerTerminated( |
| 334 ServiceWorkerDevToolsAgentHost* host) { | 336 ServiceWorkerDevToolsAgentHost* host) { |
| 335 auto it = attached_hosts_.find(host->GetId()); | 337 auto it = attached_hosts_.find(host->GetId()); |
| 336 if (it == attached_hosts_.end()) | 338 if (it == attached_hosts_.end()) |
| 337 return; | 339 return; |
| 338 it->second->DetachClient(); | 340 host->DetachClient(); |
| 339 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 341 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 340 set_worker_id(host->GetId())); | 342 set_worker_id(host->GetId())); |
| 341 attached_hosts_.erase(it); | 343 attached_hosts_.erase(it); |
| 342 } | 344 } |
| 343 | 345 |
| 344 } // namespace service_worker | 346 } // namespace service_worker |
| 345 } // namespace devtools | 347 } // namespace devtools |
| 346 } // namespace content | 348 } // namespace content |
| OLD | NEW |