| 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..a469d7de002a8b948b454e3de8eee434aa40a656
|
| --- /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->id()] = agent;
|
| + }
|
| + }
|
| +}
|
| +
|
| +void DevToolsTargetList::Register(DevToolsAgentHost* agent_host) {
|
| + GarbageCollect();
|
| + agents_map_[agent_host->id()] = 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
|
|
|