OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/devtools/worker_devtools_manager.h" | |
6 | |
7 #include "content/browser/devtools/devtools_manager.h" | |
8 #include "content/browser/devtools/service_worker_devtools_manager.h" | |
9 #include "content/browser/devtools/shared_worker_devtools_manager.h" | |
10 #include "content/browser/devtools/worker_devtools_agent_host.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 | |
13 namespace content { | |
14 | |
15 // Called on the UI thread. | |
16 // static | |
17 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( | |
18 int worker_process_id, | |
19 int worker_route_id) { | |
20 if (scoped_refptr<DevToolsAgentHost> host = | |
21 SharedWorkerDevToolsManager::GetInstance() | |
22 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id)) { | |
23 return host; | |
24 } | |
25 return ServiceWorkerDevToolsManager::GetInstance() | |
26 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | |
27 } | |
28 | |
29 DevToolsAgentHostImpl* | |
30 WorkerDevToolsManager::GetDevToolsAgentHostForWorker( | |
31 int worker_process_id, | |
32 int worker_route_id) { | |
33 AgentHostMap::iterator it = workers_.find( | |
34 WorkerId(worker_process_id, worker_route_id)); | |
35 return it == workers_.end() ? NULL : it->second; | |
36 } | |
37 | |
38 void WorkerDevToolsManager::AddAllAgentHosts( | |
39 DevToolsAgentHost::List* result) { | |
40 for (auto& worker : workers_) { | |
41 if (!worker.second->IsTerminated()) | |
42 result->push_back(worker.second); | |
43 } | |
44 } | |
45 | |
46 void WorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | |
47 int worker_route_id) { | |
horo
2014/12/22 01:54:04
indent
kinuko
2014/12/22 07:06:52
Done.
| |
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
49 const WorkerId id(worker_process_id, worker_route_id); | |
50 AgentHostMap::iterator it = workers_.find(id); | |
51 DCHECK(it != workers_.end()); | |
52 scoped_refptr<WorkerDevToolsAgentHost> agent_host(it->second); | |
53 agent_host->WorkerDestroyed(); | |
54 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | |
55 } | |
56 | |
57 void WorkerDevToolsManager::WorkerReadyForInspection( | |
58 int worker_process_id, | |
59 int worker_route_id) { | |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
61 const WorkerId id(worker_process_id, worker_route_id); | |
62 AgentHostMap::iterator it = workers_.find(id); | |
63 DCHECK(it != workers_.end()); | |
64 it->second->WorkerReadyForInspection(); | |
65 } | |
66 | |
67 WorkerDevToolsManager::WorkerDevToolsManager() { | |
68 } | |
69 | |
70 WorkerDevToolsManager::~WorkerDevToolsManager() { | |
71 } | |
72 | |
73 void WorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { | |
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
75 workers_.erase(id); | |
76 } | |
77 | |
78 void WorkerDevToolsManager::WorkerRestarted( | |
79 const WorkerId& id, | |
80 const AgentHostMap::iterator& it) { | |
81 WorkerDevToolsAgentHost* agent_host = it->second; | |
82 agent_host->WorkerRestarted(id); | |
83 workers_.erase(it); | |
84 workers_[id] = agent_host; | |
85 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | |
86 } | |
87 | |
88 } // namespace content | |
OLD | NEW |