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(int worker_process_id, | |
31 int worker_route_id) { | |
32 AgentHostMap::iterator it = workers_.find( | |
33 WorkerId(worker_process_id, worker_route_id)); | |
34 return it == workers_.end() ? NULL : it->second; | |
35 } | |
36 | |
37 void WorkerDevToolsManager::AddAllAgentHosts(DevToolsAgentHost::List* result) { | |
38 for (auto& worker : workers_) { | |
39 if (!worker.second->IsTerminated()) | |
40 result->push_back(worker.second); | |
41 } | |
42 } | |
43 | |
44 void WorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | |
45 int worker_route_id) { | |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
47 const WorkerId id(worker_process_id, worker_route_id); | |
48 AgentHostMap::iterator it = workers_.find(id); | |
49 DCHECK(it != workers_.end()); | |
50 scoped_refptr<WorkerDevToolsAgentHost> agent_host(it->second); | |
51 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerDestroyed(it->second)); | |
52 agent_host->WorkerDestroyed(); | |
53 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | |
54 } | |
55 | |
56 void WorkerDevToolsManager::WorkerReadyForInspection(int worker_process_id, | |
57 int worker_route_id) { | |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
59 const WorkerId id(worker_process_id, worker_route_id); | |
60 AgentHostMap::iterator it = workers_.find(id); | |
61 DCHECK(it != workers_.end()); | |
62 it->second->WorkerReadyForInspection(); | |
63 } | |
64 | |
65 void WorkerDevToolsManager::AddObserver(Observer* observer) { | |
66 observer_list_.AddObserver(observer); | |
67 } | |
68 | |
69 void WorkerDevToolsManager::RemoveObserver(Observer* observer) { | |
70 observer_list_.RemoveObserver(observer); | |
71 } | |
72 | |
73 WorkerDevToolsManager::WorkerDevToolsManager() { | |
74 } | |
75 | |
76 WorkerDevToolsManager::~WorkerDevToolsManager() { | |
77 } | |
78 | |
79 void WorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { | |
80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
81 workers_.erase(id); | |
82 } | |
83 | |
84 void WorkerDevToolsManager::WorkerCreated( | |
85 const WorkerId& id, | |
86 WorkerDevToolsAgentHost* host) { | |
87 workers_[id] = host; | |
88 DevToolsManager::GetInstance()->AgentHostChanged(host); | |
89 scoped_refptr<WorkerDevToolsAgentHost> protector(host); | |
90 FOR_EACH_OBSERVER(Observer, observer_list_, WorkerCreated(host)); | |
91 } | |
92 | |
93 void WorkerDevToolsManager::WorkerRestarted(const WorkerId& id, | |
94 const AgentHostMap::iterator& it) { | |
95 WorkerDevToolsAgentHost* agent_host = it->second; | |
96 agent_host->WorkerRestarted(id); | |
97 workers_.erase(it); | |
98 workers_[id] = agent_host; | |
99 DevToolsManager::GetInstance()->AgentHostChanged(agent_host); | |
100 } | |
101 | |
102 void WorkerDevToolsManager::ResetForTesting() { | |
103 workers_.clear(); | |
104 } | |
105 | |
106 } // namespace content | |
OLD | NEW |