Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1865)

Unified Diff: content/public/browser/devtools_target_list.cc

Issue 12319114: Extract debugger target enumeration into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@debugger
Patch Set: Fixed compile Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..be65eaf385cfea5e486fc2336e25e4041ee43b00
--- /dev/null
+++ b/content/public/browser/devtools_target_list.cc
@@ -0,0 +1,70 @@
+// 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/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();
+}
+
+void DevToolsTargetList::Refresh() {
+ 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));
+ scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor(rvh));
+ agents_map_[agent->GetId()] = agent;
+ }
+ }
+}
+
+void DevToolsTargetList::Register(DevToolsAgentHost* agent_host) {
pfeldman 2013/03/05 12:06:41 You don't need this.
Vladislav Kaznacheev 2013/03/05 13:35:44 Renamed to Retain. On 2013/03/05 12:06:41, pfeldm
+ GarbageCollect();
+ agents_map_[agent_host->GetId()] = agent_host;
+}
+
+DevToolsAgentHost* DevToolsTargetList::Lookup(const std::string& id) {
+ GarbageCollect();
+ AgentsMap::iterator it = agents_map_.find(id);
+ if (it != agents_map_.end())
+ return it->second;
+ return NULL;
+}
+
+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

Powered by Google App Engine
This is Rietveld 408576698