| 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/service_worker_devtools_agent_host.h" | 7 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/worker_service.h" | 10 #include "content/public/browser/worker_service.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 if (!worker.second->IsTerminated() && | 71 if (!worker.second->IsTerminated() && |
| 72 worker.second->GetBrowserContext() == browser_context) { | 72 worker.second->GetBrowserContext() == browser_context) { |
| 73 result->push_back(worker.second); | 73 result->push_back(worker.second); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool ServiceWorkerDevToolsManager::WorkerCreated( | 78 bool ServiceWorkerDevToolsManager::WorkerCreated( |
| 79 int worker_process_id, | 79 int worker_process_id, |
| 80 int worker_route_id, | 80 int worker_route_id, |
| 81 const ServiceWorkerIdentifier& service_worker_id) { | 81 const ServiceWorkerIdentifier& service_worker_id, |
| 82 bool is_installed_version) { |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 83 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 83 const WorkerId id(worker_process_id, worker_route_id); | 84 const WorkerId id(worker_process_id, worker_route_id); |
| 84 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); | 85 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); |
| 85 if (it == workers_.end()) { | 86 if (it == workers_.end()) { |
| 86 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = | 87 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = |
| 87 new ServiceWorkerDevToolsAgentHost( | 88 new ServiceWorkerDevToolsAgentHost(id, service_worker_id, |
| 88 id, service_worker_id); | 89 is_installed_version); |
| 89 workers_[id] = host.get(); | 90 workers_[id] = host.get(); |
| 90 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host.get())); | 91 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host.get())); |
| 91 if (debug_service_worker_on_start_) | 92 if (debug_service_worker_on_start_) |
| 92 host->PauseForDebugOnStart(); | 93 host->PauseForDebugOnStart(); |
| 93 return host->IsPausedForDebugOnStart(); | 94 return host->IsPausedForDebugOnStart(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Worker was restarted. | 97 // Worker was restarted. |
| 97 ServiceWorkerDevToolsAgentHost* agent_host = it->second; | 98 ServiceWorkerDevToolsAgentHost* agent_host = it->second; |
| 98 agent_host->WorkerRestarted(id); | 99 agent_host->WorkerRestarted(id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 115 FOR_EACH_OBSERVER(Observer, observer_list_, | 116 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 116 WorkerReadyForInspection(host.get())); | 117 WorkerReadyForInspection(host.get())); |
| 117 | 118 |
| 118 // Then bring up UI for the ones not picked by other clients. | 119 // Then bring up UI for the ones not picked by other clients. |
| 119 if (host->IsPausedForDebugOnStart() && !host->IsAttached()) { | 120 if (host->IsPausedForDebugOnStart() && !host->IsAttached()) { |
| 120 host->Inspect(RenderProcessHost::FromID(worker_process_id)-> | 121 host->Inspect(RenderProcessHost::FromID(worker_process_id)-> |
| 121 GetBrowserContext()); | 122 GetBrowserContext()); |
| 122 } | 123 } |
| 123 } | 124 } |
| 124 | 125 |
| 126 void ServiceWorkerDevToolsManager::WorkerVersionInstalled(int worker_process_id, |
| 127 int worker_route_id) { |
| 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 129 const WorkerId id(worker_process_id, worker_route_id); |
| 130 AgentHostMap::iterator it = workers_.find(id); |
| 131 if (it == workers_.end()) |
| 132 return; |
| 133 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = it->second; |
| 134 host->WorkerVersionInstalled(); |
| 135 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 136 WorkerVersionInstalled(host.get())); |
| 137 } |
| 138 |
| 139 void ServiceWorkerDevToolsManager::WorkerVersionDoomed(int worker_process_id, |
| 140 int worker_route_id) { |
| 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 142 const WorkerId id(worker_process_id, worker_route_id); |
| 143 AgentHostMap::iterator it = workers_.find(id); |
| 144 if (it == workers_.end()) |
| 145 return; |
| 146 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = it->second; |
| 147 host->WorkerVersionDoomed(); |
| 148 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerVersionDoomed(host.get())); |
| 149 } |
| 150 |
| 125 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, | 151 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, |
| 126 int worker_route_id) { | 152 int worker_route_id) { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 153 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 // TODO(pfeldman): Show a console message to tell the user that UA didn't | 154 // TODO(pfeldman): Show a console message to tell the user that UA didn't |
| 129 // terminate the worker because devtools is attached. | 155 // terminate the worker because devtools is attached. |
| 130 } | 156 } |
| 131 | 157 |
| 132 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 158 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| 133 int worker_route_id) { | 159 int worker_route_id) { |
| 134 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 break; | 201 break; |
| 176 } | 202 } |
| 177 return it; | 203 return it; |
| 178 } | 204 } |
| 179 | 205 |
| 180 void ServiceWorkerDevToolsManager::ResetForTesting() { | 206 void ServiceWorkerDevToolsManager::ResetForTesting() { |
| 181 workers_.clear(); | 207 workers_.clear(); |
| 182 } | 208 } |
| 183 | 209 |
| 184 } // namespace content | 210 } // namespace content |
| OLD | NEW |