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" |
11 #include "content/browser/shared_worker/shared_worker_instance.h" | 11 #include "content/browser/shared_worker/shared_worker_instance.h" |
12 #include "content/common/devtools_messages.h" | 12 #include "content/common/devtools_messages.h" |
| 13 #include "content/common/service_worker/service_worker_types.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/worker_service.h" | 16 #include "content/public/browser/worker_service.h" |
16 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 bool SendMessageToWorker( | 23 bool SendMessageToWorker( |
23 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, | 24 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, |
24 IPC::Message* message) { | 25 IPC::Message* message) { |
25 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); | 26 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); |
26 if (!host) { | 27 if (!host) { |
27 delete message; | 28 delete message; |
28 return false; | 29 return false; |
29 } | 30 } |
30 message->set_routing_id(worker_id.second); | 31 message->set_routing_id(worker_id.second); |
31 host->Send(message); | 32 host->Send(message); |
32 return true; | 33 return true; |
33 } | 34 } |
34 | 35 |
35 } // namespace | 36 } // namespace |
36 | 37 |
37 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | 38 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
38 const SharedWorkerInstance& instance) | 39 const SharedWorkerInstance& instance) |
39 : shared_worker_instance_(new SharedWorkerInstance(instance)), | 40 : shared_worker_instance_(new SharedWorkerInstance(instance)), |
| 41 service_worker_version_id_(kInvalidServiceWorkerVersionId), |
40 state_(WORKER_UNINSPECTED), | 42 state_(WORKER_UNINSPECTED), |
41 agent_host_(NULL) { | 43 agent_host_(NULL) { |
42 } | 44 } |
43 | 45 |
44 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | 46 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( |
45 const base::FilePath& storage_partition_path, | 47 const base::FilePath& storage_partition_path, |
46 const GURL& service_worker_scope) | 48 int64 service_worker_version_id) |
47 : storage_partition_path_(new base::FilePath(storage_partition_path)), | 49 : storage_partition_path_(new base::FilePath(storage_partition_path)), |
48 service_worker_scope_(new GURL(service_worker_scope)), | 50 service_worker_version_id_(service_worker_version_id), |
49 state_(WORKER_UNINSPECTED), | 51 state_(WORKER_UNINSPECTED), |
50 agent_host_(NULL) { | 52 agent_host_(NULL) { |
51 } | 53 } |
52 | 54 |
53 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | 55 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
54 const SharedWorkerInstance& other) { | 56 const SharedWorkerInstance& other) { |
55 if (!shared_worker_instance_) | 57 if (!shared_worker_instance_) |
56 return false; | 58 return false; |
57 return shared_worker_instance_->Matches(other); | 59 return shared_worker_instance_->Matches(other); |
58 } | 60 } |
59 | 61 |
60 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | 62 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( |
61 const base::FilePath& other_storage_partition_path, | 63 const base::FilePath& other_storage_partition_path, |
62 const GURL& other_service_worker_scope) { | 64 int64 other_service_worker_version_id) { |
63 if (!storage_partition_path_ || !service_worker_scope_) | 65 if (!storage_partition_path_) |
64 return false; | 66 return false; |
65 return *storage_partition_path_ == other_storage_partition_path && | 67 return *storage_partition_path_ == other_storage_partition_path && |
66 *service_worker_scope_ == other_service_worker_scope; | 68 service_worker_version_id_ == other_service_worker_version_id; |
67 } | 69 } |
68 | 70 |
69 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { | 71 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { |
70 } | 72 } |
71 | 73 |
72 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | 74 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
73 : public IPCDevToolsAgentHost, | 75 : public IPCDevToolsAgentHost, |
74 public IPC::Listener { | 76 public IPC::Listener { |
75 public: | 77 public: |
76 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 78 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 EmbeddedWorkerDevToolsAgentHost* agent_host = | 171 EmbeddedWorkerDevToolsAgentHost* agent_host = |
170 new EmbeddedWorkerDevToolsAgentHost(id); | 172 new EmbeddedWorkerDevToolsAgentHost(id); |
171 info->set_agent_host(agent_host); | 173 info->set_agent_host(agent_host); |
172 info->set_state(WORKER_INSPECTED); | 174 info->set_state(WORKER_INSPECTED); |
173 return agent_host; | 175 return agent_host; |
174 } | 176 } |
175 | 177 |
176 DevToolsAgentHost* | 178 DevToolsAgentHost* |
177 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 179 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
178 const base::FilePath& storage_partition_path, | 180 const base::FilePath& storage_partition_path, |
179 const GURL& service_worker_scope) { | 181 int64 service_worker_version_id) { |
180 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( | 182 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
181 storage_partition_path, service_worker_scope); | 183 storage_partition_path, service_worker_version_id); |
182 if (it == workers_.end()) | 184 if (it == workers_.end()) |
183 return NULL; | 185 return NULL; |
184 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 186 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
185 } | 187 } |
186 | 188 |
187 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { | 189 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() { |
188 } | 190 } |
189 | 191 |
190 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 192 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
191 } | 193 } |
(...skipping 11 matching lines...) Expand all Loading... |
203 return false; | 205 return false; |
204 } | 206 } |
205 MoveToPausedState(id, it); | 207 MoveToPausedState(id, it); |
206 return true; | 208 return true; |
207 } | 209 } |
208 | 210 |
209 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | 211 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
210 int worker_process_id, | 212 int worker_process_id, |
211 int worker_route_id, | 213 int worker_route_id, |
212 const base::FilePath& storage_partition_path, | 214 const base::FilePath& storage_partition_path, |
213 const GURL& service_worker_scope) { | 215 int64 service_worker_version_id) { |
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
215 const WorkerId id(worker_process_id, worker_route_id); | 217 const WorkerId id(worker_process_id, worker_route_id); |
216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( | 218 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo( |
217 storage_partition_path, service_worker_scope); | 219 storage_partition_path, service_worker_version_id); |
218 if (it == workers_.end()) { | 220 if (it == workers_.end()) { |
219 scoped_ptr<WorkerInfo> info( | 221 scoped_ptr<WorkerInfo> info( |
220 new WorkerInfo(storage_partition_path, service_worker_scope)); | 222 new WorkerInfo(storage_partition_path, service_worker_version_id)); |
221 workers_.set(id, info.Pass()); | 223 workers_.set(id, info.Pass()); |
222 return false; | 224 return false; |
223 } | 225 } |
224 MoveToPausedState(id, it); | 226 MoveToPausedState(id, it); |
225 return true; | 227 return true; |
226 } | 228 } |
227 | 229 |
228 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 230 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
229 int worker_route_id) { | 231 int worker_route_id) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 for (; it != workers_.end(); ++it) { | 312 for (; it != workers_.end(); ++it) { |
311 if (it->second->Matches(instance)) | 313 if (it->second->Matches(instance)) |
312 break; | 314 break; |
313 } | 315 } |
314 return it; | 316 return it; |
315 } | 317 } |
316 | 318 |
317 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 319 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
318 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( | 320 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( |
319 const base::FilePath& storage_partition_path, | 321 const base::FilePath& storage_partition_path, |
320 const GURL& service_worker_scope) { | 322 int64 service_worker_version_id) { |
321 WorkerInfoMap::iterator it = workers_.begin(); | 323 WorkerInfoMap::iterator it = workers_.begin(); |
322 for (; it != workers_.end(); ++it) { | 324 for (; it != workers_.end(); ++it) { |
323 if (it->second->Matches(storage_partition_path, service_worker_scope)) | 325 if (it->second->Matches(storage_partition_path, service_worker_version_id)) |
324 break; | 326 break; |
325 } | 327 } |
326 return it; | 328 return it; |
327 } | 329 } |
328 | 330 |
329 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 331 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
330 const WorkerId& id, | 332 const WorkerId& id, |
331 const WorkerInfoMap::iterator& it) { | 333 const WorkerInfoMap::iterator& it) { |
332 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 334 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
333 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 335 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
334 info->set_state(WORKER_PAUSED); | 336 info->set_state(WORKER_PAUSED); |
335 workers_.set(id, info.Pass()); | 337 workers_.set(id, info.Pass()); |
336 } | 338 } |
337 | 339 |
338 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 340 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
339 workers_.clear(); | 341 workers_.clear(); |
340 } | 342 } |
341 | 343 |
342 } // namespace content | 344 } // namespace content |
OLD | NEW |