Chromium Code Reviews| 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 |