Index: content/public/browser/devtools_target_list.cc |
diff --git a/content/public/browser/devtools_target_list.cc b/content/public/browser/devtools_target_list.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..411c61ab425893420f592e63596ef57ba6b0cf9f |
--- /dev/null |
+++ b/content/public/browser/devtools_target_list.cc |
@@ -0,0 +1,78 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/public/browser/devtools_target_list.h" |
+ |
+#include "base/memory/singleton.h" |
+#include "base/stringprintf.h" |
+#include "base/values.h" |
+#include "content/public/browser/devtools_agent_host.h" |
+#include "content/public/browser/render_process_host.h" |
+#include "content/public/browser/render_view_host.h" |
+ |
+namespace content { |
+ |
+DevToolsTargetList* DevToolsTargetList::GetInstance() { |
+ return Singleton<DevToolsTargetList>::get(); |
+} |
+ |
+DevToolsTargetList::AgentsMap& DevToolsTargetList::GetAgentsMap() { |
+ GarbageCollect(); |
+ |
+ for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
+ !it.IsAtEnd(); it.Advance()) { |
+ RenderProcessHost* render_process_host = it.GetCurrentValue(); |
+ DCHECK(render_process_host); |
+ |
+ // Ignore processes that don't have a connection, such as crashed contents. |
+ if (!render_process_host->HasConnection()) |
+ continue; |
+ |
+ RenderProcessHost::RenderWidgetHostsIterator rwit( |
+ render_process_host->GetRenderWidgetHostsIterator()); |
+ for (; !rwit.IsAtEnd(); rwit.Advance()) { |
+ const RenderWidgetHost* widget = rwit.GetCurrentValue(); |
+ DCHECK(widget); |
+ if (!widget || !widget->IsRenderView()) |
+ continue; |
+ |
+ RenderViewHost* rvh = |
+ RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); |
+ BindDevToolsAgentHost(DevToolsAgentHost::GetFor(rvh)); |
+ } |
+ } |
+ return agents_map_; |
+} |
+ |
+std::string DevToolsTargetList::GetIdentifier(DevToolsAgentHost* agent_host) { |
+ GarbageCollect(); |
+ return BindDevToolsAgentHost(agent_host); |
+} |
+ |
+DevToolsAgentHost* DevToolsTargetList::ForIdentifier(const std::string& id) { |
+ GarbageCollect(); |
+ AgentsMap::iterator it = agents_map_.find(id); |
+ if (it != agents_map_.end()) |
+ return it->second; |
+ return NULL; |
+} |
+ |
+std::string DevToolsTargetList::BindDevToolsAgentHost( |
+ DevToolsAgentHost* agent_host) { |
+ 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:
|
+ agents_map_[id] = agent_host; |
+ return id; |
+} |
+ |
+void DevToolsTargetList::GarbageCollect() { |
+ AgentsMap::iterator it = agents_map_.begin(); |
+ while (it != agents_map_.end()) { |
+ if (!it->second->GetRenderViewHost()) |
+ agents_map_.erase(it++); |
+ else |
+ ++it; |
+ } |
+} |
+ |
+} // namespace content |