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

Unified Diff: content/browser/devtools/devtools_agent_host_impl.cc

Issue 12319114: Extract debugger target enumeration into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@debugger
Patch Set: Addressed comments Created 7 years, 9 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/browser/devtools/devtools_agent_host_impl.cc
diff --git a/content/browser/devtools/devtools_agent_host_impl.cc b/content/browser/devtools/devtools_agent_host_impl.cc
index 0474103a4232e1c39c790fda2d4acd26b2442466..7e520539452f4c491af3122470ca7fef3b962645 100644
--- a/content/browser/devtools/devtools_agent_host_impl.cc
+++ b/content/browser/devtools/devtools_agent_host_impl.cc
@@ -5,7 +5,12 @@
#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "base/basictypes.h"
+#include "base/memory/singleton.h"
+#include "base/stringprintf.h"
#include "content/common/devtools_messages.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
namespace content {
@@ -15,7 +20,7 @@ static int g_next_agent_host_id = 0;
DevToolsAgentHostImpl::DevToolsAgentHostImpl()
: close_listener_(NULL),
- id_(++g_next_agent_host_id) {
+ id_(base::StringPrintf("%d", ++g_next_agent_host_id)) {
}
void DevToolsAgentHostImpl::Attach() {
@@ -66,4 +71,84 @@ void DevToolsAgentHostImpl::NotifyCloseListener() {
}
}
+namespace {
+ class DevToolsTargetList {
jam 2013/03/06 17:41:52 nit: no tabbing inside a namespace. also usually t
+ public:
+
+ static DevToolsTargetList* GetInstance() {
+ return Singleton<DevToolsTargetList>::get();
+ }
+
+ DevToolsAgentHost* GetRetained(const std::string& id) {
+ GarbageCollect();
+ AgentsMap::iterator it = agents_map_.find(id);
+ if (it != agents_map_.end())
+ return it->second;
+ return NULL;
+ }
+
+ void RetainFor(std::vector<RenderViewHost*> rvh_list) {
+ GarbageCollect();
+ for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin();
+ it != rvh_list.end(); it++) {
+ scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor(*it));
+ agents_map_[agent->GetId()] = agent;
+ }
+ }
+
+ private:
+ typedef std::map<std::string, scoped_refptr<DevToolsAgentHost> > AgentsMap;
+
+ AgentsMap agents_map_;
+
+ void GarbageCollect() {
+ AgentsMap::iterator it = agents_map_.begin();
+ while (it != agents_map_.end()) {
+ if (!it->second->GetRenderViewHost())
+ agents_map_.erase(it++);
+ else
+ ++it;
+ }
+ }
+ };
+} // namespace
+
+//static
+std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
+ std::vector<RenderViewHost*> result;
+ 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));
+ result.push_back(rvh);
+ }
+ }
+ return result;
+}
+
+//static
+void DevToolsAgentHost::RetainFor(std::vector<RenderViewHost*> rvh_list) {
+ DevToolsTargetList::GetInstance()->RetainFor(rvh_list);
+}
+
+// static
+DevToolsAgentHost* DevToolsAgentHost::GetRetained(const std::string& id) {
+ return DevToolsTargetList::GetInstance()->GetRetained(id);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698