| 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 26 matching lines...) Expand all Loading... |
| 37 ServiceWorkerIdentifier::~ServiceWorkerIdentifier() { | 37 ServiceWorkerIdentifier::~ServiceWorkerIdentifier() { |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( | 40 bool ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( |
| 41 const ServiceWorkerIdentifier& other) const { | 41 const ServiceWorkerIdentifier& other) const { |
| 42 return context_ == other.context_ && version_id_ == other.version_id_; | 42 return context_ == other.context_ && version_id_ == other.version_id_; |
| 43 } | 43 } |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 ServiceWorkerDevToolsManager* ServiceWorkerDevToolsManager::GetInstance() { | 46 ServiceWorkerDevToolsManager* ServiceWorkerDevToolsManager::GetInstance() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 return Singleton<ServiceWorkerDevToolsManager>::get(); | 48 return Singleton<ServiceWorkerDevToolsManager>::get(); |
| 49 } | 49 } |
| 50 | 50 |
| 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 ServiceWorkerDevToolsAgentHost::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_CURRENTLY_ON(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 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = | 76 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = |
| 77 new ServiceWorkerDevToolsAgentHost( | 77 new ServiceWorkerDevToolsAgentHost( |
| 78 id, service_worker_id); | 78 id, service_worker_id); |
| 79 workers_[id] = host.get(); | 79 workers_[id] = host.get(); |
| 80 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host.get())); | 80 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host.get())); |
| 81 DevToolsManager::GetInstance()->AgentHostChanged(host.get()); | 81 DevToolsManager::GetInstance()->AgentHostChanged(host.get()); |
| 82 if (debug_service_worker_on_start_) | 82 if (debug_service_worker_on_start_) |
| 83 host->PauseForDebugOnStart(); | 83 host->PauseForDebugOnStart(); |
| 84 return host->IsPausedForDebugOnStart(); | 84 return host->IsPausedForDebugOnStart(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Worker was restarted. | 87 // Worker was restarted. |
| 88 ServiceWorkerDevToolsAgentHost* agent_host = it->second; | 88 ServiceWorkerDevToolsAgentHost* agent_host = it->second; |
| 89 agent_host->WorkerRestarted(id); | 89 agent_host->WorkerRestarted(id); |
| 90 workers_.erase(it); | 90 workers_.erase(it); |
| 91 workers_[id] = agent_host; | 91 workers_[id] = agent_host; |
| 92 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | 92 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); |
| 93 | 93 |
| 94 return it->second->IsAttached(); | 94 return it->second->IsAttached(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ServiceWorkerDevToolsManager::WorkerReadyForInspection( | 97 void ServiceWorkerDevToolsManager::WorkerReadyForInspection( |
| 98 int worker_process_id, | 98 int worker_process_id, |
| 99 int worker_route_id) { | 99 int worker_route_id) { |
| 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 100 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 101 const WorkerId id(worker_process_id, worker_route_id); | 101 const WorkerId id(worker_process_id, worker_route_id); |
| 102 AgentHostMap::iterator it = workers_.find(id); | 102 AgentHostMap::iterator it = workers_.find(id); |
| 103 DCHECK(it != workers_.end()); | 103 DCHECK(it != workers_.end()); |
| 104 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = it->second; | 104 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = it->second; |
| 105 host->WorkerReadyForInspection(); | 105 host->WorkerReadyForInspection(); |
| 106 FOR_EACH_OBSERVER(Observer, observer_list_, | 106 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 107 WorkerReadyForInspection(host.get())); | 107 WorkerReadyForInspection(host.get())); |
| 108 | 108 |
| 109 // Then bring up UI for the ones not picked by other clients. | 109 // Then bring up UI for the ones not picked by other clients. |
| 110 if (host->IsPausedForDebugOnStart() && !host->IsAttached()) { | 110 if (host->IsPausedForDebugOnStart() && !host->IsAttached()) { |
| 111 host->Inspect(RenderProcessHost::FromID(worker_process_id)-> | 111 host->Inspect(RenderProcessHost::FromID(worker_process_id)-> |
| 112 GetBrowserContext()); | 112 GetBrowserContext()); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, | 116 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, |
| 117 int worker_route_id) { | 117 int worker_route_id) { |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 // 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 |
| 120 // terminate the worker because devtools is attached. | 120 // terminate the worker because devtools is attached. |
| 121 } | 121 } |
| 122 | 122 |
| 123 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 123 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| 124 int worker_route_id) { | 124 int worker_route_id) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 125 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 126 const WorkerId id(worker_process_id, worker_route_id); | 126 const WorkerId id(worker_process_id, worker_route_id); |
| 127 AgentHostMap::iterator it = workers_.find(id); | 127 AgentHostMap::iterator it = workers_.find(id); |
| 128 DCHECK(it != workers_.end()); | 128 DCHECK(it != workers_.end()); |
| 129 scoped_refptr<WorkerDevToolsAgentHost> agent_host(it->second); | 129 scoped_refptr<WorkerDevToolsAgentHost> agent_host(it->second); |
| 130 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerDestroyed(it->second)); | 130 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerDestroyed(it->second)); |
| 131 agent_host->WorkerDestroyed(); | 131 agent_host->WorkerDestroyed(); |
| 132 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | 132 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void ServiceWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { | 135 void ServiceWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { |
| 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 136 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 137 workers_.erase(id); | 137 workers_.erase(id); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void ServiceWorkerDevToolsManager::AddObserver(Observer* observer) { | 140 void ServiceWorkerDevToolsManager::AddObserver(Observer* observer) { |
| 141 observer_list_.AddObserver(observer); | 141 observer_list_.AddObserver(observer); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void ServiceWorkerDevToolsManager::RemoveObserver(Observer* observer) { | 144 void ServiceWorkerDevToolsManager::RemoveObserver(Observer* observer) { |
| 145 observer_list_.RemoveObserver(observer); | 145 observer_list_.RemoveObserver(observer); |
| 146 } | 146 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 162 break; | 162 break; |
| 163 } | 163 } |
| 164 return it; | 164 return it; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ServiceWorkerDevToolsManager::ResetForTesting() { | 167 void ServiceWorkerDevToolsManager::ResetForTesting() { |
| 168 workers_.clear(); | 168 workers_.clear(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 } // namespace content | 171 } // namespace content |
| OLD | NEW |