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& service_worker_path, | |
46 const GURL& service_worker_scope) | |
47 : service_worker_path_(new base::FilePath(service_worker_path)), | |
48 service_worker_scope_(new GURL(service_worker_scope)), | |
49 state_(WORKER_UNINSPECTED), | |
50 agent_host_(NULL) { | |
51 } | |
52 | |
53 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { | |
54 } | |
55 | |
37 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | 56 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
38 : public IPCDevToolsAgentHost, | 57 : public IPCDevToolsAgentHost, |
39 public IPC::Listener { | 58 public IPC::Listener { |
40 public: | 59 public: |
41 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 60 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) |
42 : worker_id_(worker_id), worker_attached_(true) { | 61 : worker_id_(worker_id), worker_attached_(true) { |
43 AddRef(); | 62 AddRef(); |
44 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 63 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
45 host->AddRoute(worker_id_.second, this); | 64 host->AddRoute(worker_id_.second, this); |
46 } | 65 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 workers_.set(id, info.Pass()); | 172 workers_.set(id, info.Pass()); |
154 return false; | 173 return false; |
155 } | 174 } |
156 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 175 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
157 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 176 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
158 info->set_state(WORKER_PAUSED); | 177 info->set_state(WORKER_PAUSED); |
159 workers_.set(id, info.Pass()); | 178 workers_.set(id, info.Pass()); |
160 return true; | 179 return true; |
161 } | 180 } |
162 | 181 |
182 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | |
183 int worker_process_id, | |
184 int worker_route_id, | |
185 const base::FilePath& path, | |
186 const GURL& scope) { | |
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
188 const WorkerId id(worker_process_id, worker_route_id); | |
189 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(path, scope); | |
190 if (it == workers_.end()) { | |
191 scoped_ptr<WorkerInfo> info(new WorkerInfo(path, scope)); | |
192 workers_.set(id, info.Pass()); | |
193 return false; | |
194 } | |
195 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | |
yurys
2014/05/02 04:35:35
Consider extracting common tail into a separate me
horo
2014/05/02 06:31:55
Done.
| |
196 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | |
197 info->set_state(WORKER_PAUSED); | |
198 workers_.set(id, info.Pass()); | |
199 return true; | |
200 } | |
201 | |
163 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 202 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
164 int worker_route_id) { | 203 int worker_route_id) { |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
166 const WorkerId id(worker_process_id, worker_route_id); | 205 const WorkerId id(worker_process_id, worker_route_id); |
167 WorkerInfoMap::iterator it = workers_.find(id); | 206 WorkerInfoMap::iterator it = workers_.find(id); |
168 DCHECK(it != workers_.end()); | 207 DCHECK(it != workers_.end()); |
169 WorkerInfo* info = it->second; | 208 WorkerInfo* info = it->second; |
170 switch (info->state()) { | 209 switch (info->state()) { |
171 case WORKER_UNINSPECTED: | 210 case WORKER_UNINSPECTED: |
172 workers_.erase(it); | 211 workers_.erase(it); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 return; | 275 return; |
237 } | 276 } |
238 } | 277 } |
239 } | 278 } |
240 | 279 |
241 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 280 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
242 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( | 281 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( |
243 const SharedWorkerInstance& instance) { | 282 const SharedWorkerInstance& instance) { |
244 WorkerInfoMap::iterator it = workers_.begin(); | 283 WorkerInfoMap::iterator it = workers_.begin(); |
245 for (; it != workers_.end(); ++it) { | 284 for (; it != workers_.end(); ++it) { |
246 if (it->second->instance().Matches(instance)) | 285 if (it->second->Matches(instance)) |
247 break; | 286 break; |
248 } | 287 } |
249 return it; | 288 return it; |
289 } | |
290 | |
291 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | |
292 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( | |
293 const base::FilePath& service_worker_path, | |
yurys
2014/05/02 04:35:35
Would it make sense to have ServiceWorkerInstance
horo
2014/05/02 06:31:55
Added comment in .h.
| |
294 const GURL& service_worker_scope) { | |
295 WorkerInfoMap::iterator it = workers_.begin(); | |
296 for (; it != workers_.end(); ++it) { | |
297 if (it->second->Matches(service_worker_path, service_worker_scope)) | |
298 break; | |
299 } | |
300 return it; | |
250 } | 301 } |
251 | 302 |
252 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 303 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
253 workers_.clear(); | 304 workers_.clear(); |
254 } | 305 } |
255 | 306 |
256 } // namespace content | 307 } // namespace content |
OLD | NEW |