Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/service_worker_devtools_manager.h" | 5 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 6 | 6 |
| 7 #include "content/browser/devtools/devtools_manager.h" | 7 #include "content/browser/devtools/devtools_manager.h" |
| 8 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 8 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
| 9 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 9 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 DevToolsAgentHostImpl* | 51 DevToolsAgentHostImpl* |
| 52 ServiceWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 52 ServiceWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 53 int worker_process_id, | 53 int worker_process_id, |
| 54 int worker_route_id) { | 54 int worker_route_id) { |
| 55 AgentHostMap::iterator it = workers_.find( | 55 AgentHostMap::iterator it = workers_.find( |
| 56 WorkerId(worker_process_id, worker_route_id)); | 56 WorkerId(worker_process_id, worker_route_id)); |
| 57 return it == workers_.end() ? NULL : it->second; | 57 return it == workers_.end() ? NULL : it->second; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ServiceWorkerDevToolsManager::AddAllAgentHosts( | 60 void ServiceWorkerDevToolsManager::AddAllAgentHosts( |
| 61 DevToolsAgentHost::List* result) { | 61 ServiceWorkerDevToolsAgentHost::List* result) { |
| 62 for (auto& worker : workers_) { | 62 for (auto& worker : workers_) { |
| 63 if (!worker.second->IsTerminated()) | 63 if (!worker.second->IsTerminated()) |
| 64 result->push_back(worker.second); | 64 result->push_back(worker.second); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool ServiceWorkerDevToolsManager::WorkerCreated( | 68 bool ServiceWorkerDevToolsManager::WorkerCreated( |
| 69 int worker_process_id, | 69 int worker_process_id, |
| 70 int worker_route_id, | 70 int worker_route_id, |
| 71 const ServiceWorkerIdentifier& service_worker_id) { | 71 const ServiceWorkerIdentifier& service_worker_id) { |
| 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 73 const WorkerId id(worker_process_id, worker_route_id); | 73 const WorkerId id(worker_process_id, worker_route_id); |
| 74 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); | 74 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); |
| 75 if (it == workers_.end()) { | 75 if (it == workers_.end()) { |
| 76 workers_[id] = new ServiceWorkerDevToolsAgentHost( | 76 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = |
| 77 id, service_worker_id, debug_service_worker_on_start_); | 77 new ServiceWorkerDevToolsAgentHost( |
| 78 scoped_refptr<WorkerDevToolsAgentHost> protector(workers_[id]); | 78 id, service_worker_id); |
| 79 FOR_EACH_OBSERVER(Observer, observer_list_, | 79 workers_[id] = host.get(); |
| 80 WorkerCreated(protector.get())); | 80 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host.get())); |
| 81 DevToolsManager::GetInstance()->AgentHostChanged(protector.get()); | 81 DevToolsManager::GetInstance()->AgentHostChanged(host.get()); |
| 82 return debug_service_worker_on_start_; | 82 if (debug_service_worker_on_start_) |
| 83 host->PauseForDebugOnStart(); | |
| 84 return host->IsPausedForDebugOnStart(); | |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Worker was restarted. | 87 // Worker was restarted. |
| 86 ServiceWorkerDevToolsAgentHost* agent_host = it->second; | 88 ServiceWorkerDevToolsAgentHost* agent_host = it->second; |
| 87 agent_host->WorkerRestarted(id); | 89 agent_host->WorkerRestarted(id); |
| 88 workers_.erase(it); | 90 workers_.erase(it); |
| 89 workers_[id] = agent_host; | 91 workers_[id] = agent_host; |
| 90 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | 92 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); |
| 91 | 93 |
| 92 return it->second->IsAttached(); | 94 return it->second->IsAttached(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 void ServiceWorkerDevToolsManager::WorkerReadyForInspection( | 97 void ServiceWorkerDevToolsManager::WorkerReadyForInspection( |
| 96 int worker_process_id, int worker_route_id) { | 98 int worker_process_id, |
| 99 int worker_route_id) { | |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 98 const WorkerId id(worker_process_id, worker_route_id); | 101 const WorkerId id(worker_process_id, worker_route_id); |
| 99 AgentHostMap::iterator it = workers_.find(id); | 102 AgentHostMap::iterator it = workers_.find(id); |
| 100 DCHECK(it != workers_.end()); | 103 DCHECK(it != workers_.end()); |
| 101 it->second->WorkerReadyForInspection(); | 104 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = it->second; |
| 105 host->WorkerReadyForInspection(); | |
| 106 FOR_EACH_OBSERVER(Observer, observer_list_, | |
| 107 WorkerReadyForInspection(host.get())); | |
| 108 | |
| 109 // Then bring up UI for the ones not picked by other clients. | |
| 110 if (host->IsPausedForDebugOnStart() && !host->IsAttached()) { | |
| 111 it->second->Inspect(RenderProcessHost::FromID(worker_process_id)-> | |
|
dgozman
2015/03/08 07:49:56
it->second => host
pfeldman
2015/03/08 08:30:57
Done.
| |
| 112 GetBrowserContext()); | |
| 113 } | |
| 102 } | 114 } |
| 103 | 115 |
| 104 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, | 116 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, |
| 105 int worker_route_id) { | 117 int worker_route_id) { |
| 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 // TODO(pfeldman): Show a console message to tell the user that UA didn't | 119 // TODO(pfeldman): Show a console message to tell the user that UA didn't |
| 108 // terminate the worker because devtools is attached. | 120 // terminate the worker because devtools is attached. |
| 109 } | 121 } |
| 110 | 122 |
| 111 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 123 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 break; | 162 break; |
| 151 } | 163 } |
| 152 return it; | 164 return it; |
| 153 } | 165 } |
| 154 | 166 |
| 155 void ServiceWorkerDevToolsManager::ResetForTesting() { | 167 void ServiceWorkerDevToolsManager::ResetForTesting() { |
| 156 workers_.clear(); | 168 workers_.clear(); |
| 157 } | 169 } |
| 158 | 170 |
| 159 } // namespace content | 171 } // namespace content |
| OLD | NEW |