Chromium Code Reviews| 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..4f90548789112a3730ad349e5ba57851519d761f |
| --- /dev/null |
| +++ b/content/public/browser/devtools_target_list.cc |
| @@ -0,0 +1,77 @@ |
| +// 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)); |
| + UpdateMap(DevToolsAgentHost::GetFor(rvh)); |
| + } |
| + } |
| + return agents_map_; |
| +} |
| + |
| +std::string DevToolsTargetList::GetIdentifier(DevToolsAgentHost* agent_host) { |
| + GarbageCollect(); |
| + return UpdateMap(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::UpdateMap(DevToolsAgentHost* agent_host) { |
|
pfeldman
2013/03/01 08:49:30
Rename to ::BindDevToolsAgentHost ?
Vladislav Kaznacheev
2013/03/01 12:58:35
Done.
|
| + std::string id = base::StringPrintf("%d", agent_host->id()); |
| + agents_map_[id] = agent_host; |
| + return id; |
| +} |
| + |
| +void DevToolsTargetList::GarbageCollect() { |
|
pfeldman
2013/03/01 08:49:30
The order of definitions should match the order of
Vladislav Kaznacheev
2013/03/01 12:58:35
Done.
|
| + AgentsMap::iterator it = agents_map_.begin(); |
| + while (it != agents_map_.end()) { |
| + if (!it->second->GetRenderViewHost()) |
| + agents_map_.erase(it++); |
| + else |
| + ++it; |
| + } |
| +} |
| + |
| +} // namespace content |