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/embedded_worker_devtools_manager.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
6 | 6 |
7 #include "content/browser/devtools/devtools_manager_impl.h" | 7 #include "content/browser/devtools/devtools_manager_impl.h" |
8 #include "content/browser/devtools/devtools_protocol.h" | 8 #include "content/browser/devtools/devtools_protocol.h" |
9 #include "content/browser/devtools/devtools_protocol_constants.h" | 9 #include "content/browser/devtools/devtools_protocol_constants.h" |
10 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 delete message; | 27 delete message; |
28 return false; | 28 return false; |
29 } | 29 } |
30 message->set_routing_id(worker_id.second); | 30 message->set_routing_id(worker_id.second); |
31 host->Send(message); | 31 host->Send(message); |
32 return true; | 32 return true; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
| 37 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
| 38 const SharedWorkerInstance& instance) |
| 39 : shared_worker_instance_(new SharedWorkerInstance(instance)), |
| 40 state_(WORKER_UNINSPECTED), |
| 41 agent_host_(NULL) { |
| 42 } |
| 43 |
| 44 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
| 45 const base::FilePath& storage_partition_path, |
| 46 const GURL& service_worker_scope) |
| 47 : storage_partition_path_(new base::FilePath(storage_partition_path)), |
| 48 service_worker_scope_(new GURL(service_worker_scope)), |
| 49 state_(WORKER_UNINSPECTED), |
| 50 agent_host_(NULL) { |
| 51 } |
| 52 |
| 53 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
| 54 const SharedWorkerInstance& other) { |
| 55 if (!shared_worker_instance_) |
| 56 return false; |
| 57 return shared_worker_instance_->Matches(other); |
| 58 } |
| 59 |
| 60 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
| 61 const base::FilePath& other_storage_partition_path, |
| 62 const GURL& other_service_worker_scope) { |
| 63 if (!storage_partition_path_ || !service_worker_scope_) |
| 64 return false; |
| 65 return *storage_partition_path_ == other_storage_partition_path && |
| 66 *service_worker_scope_ == other_service_worker_scope; |
| 67 } |
| 68 |
| 69 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { |
| 70 } |
| 71 |
37 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | 72 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
38 : public IPCDevToolsAgentHost, | 73 : public IPCDevToolsAgentHost, |
39 public IPC::Listener { | 74 public IPC::Listener { |
40 public: | 75 public: |
41 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 76 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
42 : worker_id_(worker_id), worker_attached_(true) { | 77 : worker_id_(worker_id), worker_attached_(true) { |
43 AddRef(); | 78 AddRef(); |
44 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 79 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
45 host->AddRoute(worker_id_.second, this); | 80 host->AddRoute(worker_id_.second, this); |
46 } | 81 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 int worker_route_id, | 181 int worker_route_id, |
147 const SharedWorkerInstance& instance) { | 182 const SharedWorkerInstance& instance) { |
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
149 const WorkerId id(worker_process_id, worker_route_id); | 184 const WorkerId id(worker_process_id, worker_route_id); |
150 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); | 185 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); |
151 if (it == workers_.end()) { | 186 if (it == workers_.end()) { |
152 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); | 187 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); |
153 workers_.set(id, info.Pass()); | 188 workers_.set(id, info.Pass()); |
154 return false; | 189 return false; |
155 } | 190 } |
156 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 191 MoveToPausedState(id, it); |
157 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | |
158 info->set_state(WORKER_PAUSED); | |
159 workers_.set(id, info.Pass()); | |
160 return true; | 192 return true; |
161 } | 193 } |
162 | 194 |
| 195 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
| 196 int worker_process_id, |
| 197 int worker_route_id, |
| 198 const base::FilePath& storage_partition_path, |
| 199 const GURL& service_worker_scope) { |
| 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 201 const WorkerId id(worker_process_id, worker_route_id); |
| 202 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
| 203 storage_partition_path, service_worker_scope); |
| 204 if (it == workers_.end()) { |
| 205 scoped_ptr<WorkerInfo> info( |
| 206 new WorkerInfo(storage_partition_path, service_worker_scope)); |
| 207 workers_.set(id, info.Pass()); |
| 208 return false; |
| 209 } |
| 210 MoveToPausedState(id, it); |
| 211 return true; |
| 212 } |
| 213 |
163 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 214 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
164 int worker_route_id) { | 215 int worker_route_id) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
166 const WorkerId id(worker_process_id, worker_route_id); | 217 const WorkerId id(worker_process_id, worker_route_id); |
167 WorkerInfoMap::iterator it = workers_.find(id); | 218 WorkerInfoMap::iterator it = workers_.find(id); |
168 DCHECK(it != workers_.end()); | 219 DCHECK(it != workers_.end()); |
169 WorkerInfo* info = it->second; | 220 WorkerInfo* info = it->second; |
170 switch (info->state()) { | 221 switch (info->state()) { |
171 case WORKER_UNINSPECTED: | 222 case WORKER_UNINSPECTED: |
172 workers_.erase(it); | 223 workers_.erase(it); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return; | 287 return; |
237 } | 288 } |
238 } | 289 } |
239 } | 290 } |
240 | 291 |
241 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 292 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
242 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( | 293 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( |
243 const SharedWorkerInstance& instance) { | 294 const SharedWorkerInstance& instance) { |
244 WorkerInfoMap::iterator it = workers_.begin(); | 295 WorkerInfoMap::iterator it = workers_.begin(); |
245 for (; it != workers_.end(); ++it) { | 296 for (; it != workers_.end(); ++it) { |
246 if (it->second->instance().Matches(instance)) | 297 if (it->second->Matches(instance)) |
247 break; | 298 break; |
248 } | 299 } |
249 return it; | 300 return it; |
250 } | 301 } |
251 | 302 |
| 303 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
| 304 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( |
| 305 const base::FilePath& storage_partition_path, |
| 306 const GURL& service_worker_scope) { |
| 307 WorkerInfoMap::iterator it = workers_.begin(); |
| 308 for (; it != workers_.end(); ++it) { |
| 309 if (it->second->Matches(storage_partition_path, service_worker_scope)) |
| 310 break; |
| 311 } |
| 312 return it; |
| 313 } |
| 314 |
| 315 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
| 316 const WorkerId& id, |
| 317 const WorkerInfoMap::iterator& it) { |
| 318 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
| 319 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
| 320 info->set_state(WORKER_PAUSED); |
| 321 workers_.set(id, info.Pass()); |
| 322 } |
| 323 |
252 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 324 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
253 workers_.clear(); | 325 workers_.clear(); |
254 } | 326 } |
255 | 327 |
256 } // namespace content | 328 } // namespace content |
OLD | NEW |