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/browser/devtools/shared_worker_devtools_agent_host.h" | |
11 #include "content/browser/shared_worker/shared_worker_instance.h" | |
12 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
14 #include "content/public/browser/worker_service.h" | 12 #include "content/public/browser/worker_service.h" |
15 #include "ipc/ipc_listener.h" | 13 #include "ipc/ipc_listener.h" |
16 | 14 |
17 namespace content { | 15 namespace content { |
18 | 16 |
19 ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( | 17 ServiceWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( |
20 const ServiceWorkerContextCore* context, | 18 const ServiceWorkerContextCore* context, |
21 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 19 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
(...skipping 21 matching lines...) Expand all Loading... |
43 const ServiceWorkerIdentifier& other) const { | 41 const ServiceWorkerIdentifier& other) const { |
44 return context_ == other.context_ && version_id_ == other.version_id_; | 42 return context_ == other.context_ && version_id_ == other.version_id_; |
45 } | 43 } |
46 | 44 |
47 // static | 45 // static |
48 ServiceWorkerDevToolsManager* ServiceWorkerDevToolsManager::GetInstance() { | 46 ServiceWorkerDevToolsManager* ServiceWorkerDevToolsManager::GetInstance() { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
50 return Singleton<ServiceWorkerDevToolsManager>::get(); | 48 return Singleton<ServiceWorkerDevToolsManager>::get(); |
51 } | 49 } |
52 | 50 |
| 51 DevToolsAgentHostImpl* |
| 52 ServiceWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 53 int worker_process_id, |
| 54 int worker_route_id) { |
| 55 AgentHostMap::iterator it = workers_.find( |
| 56 WorkerId(worker_process_id, worker_route_id)); |
| 57 return it == workers_.end() ? NULL : it->second; |
| 58 } |
| 59 |
| 60 void ServiceWorkerDevToolsManager::AddAllAgentHosts( |
| 61 DevToolsAgentHost::List* result) { |
| 62 for (auto& worker : workers_) { |
| 63 if (!worker.second->IsTerminated()) |
| 64 result->push_back(worker.second); |
| 65 } |
| 66 } |
| 67 |
53 bool ServiceWorkerDevToolsManager::WorkerCreated( | 68 bool ServiceWorkerDevToolsManager::WorkerCreated( |
54 int worker_process_id, | 69 int worker_process_id, |
55 int worker_route_id, | 70 int worker_route_id, |
56 const ServiceWorkerIdentifier& service_worker_id) { | 71 const ServiceWorkerIdentifier& service_worker_id) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 const WorkerId id(worker_process_id, worker_route_id); | 73 const WorkerId id(worker_process_id, worker_route_id); |
59 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); | 74 AgentHostMap::iterator it = FindExistingWorkerAgentHost(service_worker_id); |
60 if (it == workers().end()) { | 75 if (it == workers_.end()) { |
61 WorkerDevToolsManager::WorkerCreated(id, | 76 workers_[id] = new ServiceWorkerDevToolsAgentHost( |
62 new ServiceWorkerDevToolsAgentHost(id, service_worker_id, | 77 id, service_worker_id, debug_service_worker_on_start_); |
63 debug_service_worker_on_start_)); | 78 scoped_refptr<WorkerDevToolsAgentHost> protector(workers_[id]); |
| 79 FOR_EACH_OBSERVER(Observer, observer_list_, |
| 80 WorkerCreated(protector.get())); |
| 81 DevToolsManager::GetInstance()->AgentHostChanged(protector.get()); |
64 return debug_service_worker_on_start_; | 82 return debug_service_worker_on_start_; |
65 } | 83 } |
66 WorkerRestarted(id, it); | 84 |
| 85 // Worker was restarted. |
| 86 ServiceWorkerDevToolsAgentHost* agent_host = it->second; |
| 87 agent_host->WorkerRestarted(id); |
| 88 workers_.erase(it); |
| 89 workers_[id] = agent_host; |
| 90 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); |
| 91 |
67 return it->second->IsAttached(); | 92 return it->second->IsAttached(); |
68 } | 93 } |
69 | 94 |
| 95 void ServiceWorkerDevToolsManager::WorkerReadyForInspection( |
| 96 int worker_process_id, int worker_route_id) { |
| 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 98 const WorkerId id(worker_process_id, worker_route_id); |
| 99 AgentHostMap::iterator it = workers_.find(id); |
| 100 DCHECK(it != workers_.end()); |
| 101 it->second->WorkerReadyForInspection(); |
| 102 } |
| 103 |
70 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, | 104 void ServiceWorkerDevToolsManager::WorkerStopIgnored(int worker_process_id, |
71 int worker_route_id) { | 105 int worker_route_id) { |
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
73 // TODO(pfeldman): Show a console message to tell the user that UA didn't | 107 // TODO(pfeldman): Show a console message to tell the user that UA didn't |
74 // terminate the worker because devtools is attached. | 108 // terminate the worker because devtools is attached. |
75 } | 109 } |
76 | 110 |
| 111 void ServiceWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| 112 int worker_route_id) { |
| 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 114 const WorkerId id(worker_process_id, worker_route_id); |
| 115 AgentHostMap::iterator it = workers_.find(id); |
| 116 DCHECK(it != workers_.end()); |
| 117 scoped_refptr<WorkerDevToolsAgentHost> agent_host(it->second); |
| 118 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerDestroyed(it->second)); |
| 119 agent_host->WorkerDestroyed(); |
| 120 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); |
| 121 } |
| 122 |
| 123 void ServiceWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 workers_.erase(id); |
| 126 } |
| 127 |
| 128 void ServiceWorkerDevToolsManager::AddObserver(Observer* observer) { |
| 129 observer_list_.AddObserver(observer); |
| 130 } |
| 131 |
| 132 void ServiceWorkerDevToolsManager::RemoveObserver(Observer* observer) { |
| 133 observer_list_.RemoveObserver(observer); |
| 134 } |
| 135 |
77 ServiceWorkerDevToolsManager::ServiceWorkerDevToolsManager() | 136 ServiceWorkerDevToolsManager::ServiceWorkerDevToolsManager() |
78 : debug_service_worker_on_start_(false) { | 137 : debug_service_worker_on_start_(false) { |
79 } | 138 } |
80 | 139 |
81 ServiceWorkerDevToolsManager::~ServiceWorkerDevToolsManager() { | 140 ServiceWorkerDevToolsManager::~ServiceWorkerDevToolsManager() { |
82 } | 141 } |
83 | 142 |
84 ServiceWorkerDevToolsManager::AgentHostMap::iterator | 143 ServiceWorkerDevToolsManager::AgentHostMap::iterator |
85 ServiceWorkerDevToolsManager::FindExistingWorkerAgentHost( | 144 ServiceWorkerDevToolsManager::FindExistingWorkerAgentHost( |
86 const ServiceWorkerIdentifier& service_worker_id) { | 145 const ServiceWorkerIdentifier& service_worker_id) { |
87 AgentHostMap::iterator it = workers().begin(); | 146 AgentHostMap::iterator it = workers_.begin(); |
88 for (; it != workers().end(); ++it) { | 147 for (; it != workers_.end(); ++it) { |
89 if (static_cast<ServiceWorkerDevToolsAgentHost*>( | 148 if (static_cast<ServiceWorkerDevToolsAgentHost*>( |
90 it->second)->Matches(service_worker_id)) | 149 it->second)->Matches(service_worker_id)) |
91 break; | 150 break; |
92 } | 151 } |
93 return it; | 152 return it; |
94 } | 153 } |
95 | 154 |
| 155 void ServiceWorkerDevToolsManager::ResetForTesting() { |
| 156 workers_.clear(); |
| 157 } |
| 158 |
96 } // namespace content | 159 } // namespace content |
OLD | NEW |