OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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/public/browser/devtools_target_list.h" | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "base/stringprintf.h" | |
9 #include "base/values.h" | |
10 #include "content/public/browser/devtools_agent_host.h" | |
11 #include "content/public/browser/render_process_host.h" | |
12 #include "content/public/browser/render_view_host.h" | |
13 | |
14 namespace content { | |
15 | |
16 DevToolsTargetList* DevToolsTargetList::GetInstance() { | |
17 return Singleton<DevToolsTargetList>::get(); | |
18 } | |
19 | |
20 DevToolsTargetList::AgentsMap& DevToolsTargetList::GetAgentsMap() { | |
21 GarbageCollect(); | |
22 | |
23 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); | |
24 !it.IsAtEnd(); it.Advance()) { | |
25 RenderProcessHost* render_process_host = it.GetCurrentValue(); | |
26 DCHECK(render_process_host); | |
27 | |
28 // Ignore processes that don't have a connection, such as crashed contents. | |
29 if (!render_process_host->HasConnection()) | |
30 continue; | |
31 | |
32 RenderProcessHost::RenderWidgetHostsIterator rwit( | |
33 render_process_host->GetRenderWidgetHostsIterator()); | |
34 for (; !rwit.IsAtEnd(); rwit.Advance()) { | |
35 const RenderWidgetHost* widget = rwit.GetCurrentValue(); | |
36 DCHECK(widget); | |
37 if (!widget || !widget->IsRenderView()) | |
38 continue; | |
39 | |
40 RenderViewHost* rvh = | |
41 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); | |
42 BindDevToolsAgentHost(DevToolsAgentHost::GetFor(rvh)); | |
43 } | |
44 } | |
45 return agents_map_; | |
46 } | |
47 | |
48 std::string DevToolsTargetList::GetIdentifier(DevToolsAgentHost* agent_host) { | |
49 GarbageCollect(); | |
50 return BindDevToolsAgentHost(agent_host); | |
51 } | |
52 | |
53 DevToolsAgentHost* DevToolsTargetList::ForIdentifier(const std::string& id) { | |
54 GarbageCollect(); | |
55 AgentsMap::iterator it = agents_map_.find(id); | |
56 if (it != agents_map_.end()) | |
57 return it->second; | |
58 return NULL; | |
59 } | |
60 | |
61 std::string DevToolsTargetList::BindDevToolsAgentHost( | |
62 DevToolsAgentHost* agent_host) { | |
63 std::string id = base::StringPrintf("%d", agent_host->id()); | |
pfeldman
2013/03/01 14:28:17
Lets stick to either int or string in both: DevToo
Vladislav Kaznacheev
2013/03/01 16:16:38
Changed to string everywhere.
On 2013/03/01 14:28:
| |
64 agents_map_[id] = agent_host; | |
65 return id; | |
66 } | |
67 | |
68 void DevToolsTargetList::GarbageCollect() { | |
69 AgentsMap::iterator it = agents_map_.begin(); | |
70 while (it != agents_map_.end()) { | |
71 if (!it->second->GetRenderViewHost()) | |
72 agents_map_.erase(it++); | |
73 else | |
74 ++it; | |
75 } | |
76 } | |
77 | |
78 } // namespace content | |
OLD | NEW |