OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/public/browser/devtools_target_list.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "base/values.h" |
| 9 #include "content/public/browser/devtools_agent_host.h" |
| 10 #include "content/public/browser/render_process_host.h" |
| 11 #include "content/public/browser/render_view_host.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 DevToolsTargetList* DevToolsTargetList::GetInstance() { |
| 16 return Singleton<DevToolsTargetList>::get(); |
| 17 } |
| 18 |
| 19 void DevToolsTargetList::Refresh() { |
| 20 GarbageCollect(); |
| 21 |
| 22 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); |
| 23 !it.IsAtEnd(); it.Advance()) { |
| 24 RenderProcessHost* render_process_host = it.GetCurrentValue(); |
| 25 DCHECK(render_process_host); |
| 26 |
| 27 // Ignore processes that don't have a connection, such as crashed contents. |
| 28 if (!render_process_host->HasConnection()) |
| 29 continue; |
| 30 |
| 31 RenderProcessHost::RenderWidgetHostsIterator rwit( |
| 32 render_process_host->GetRenderWidgetHostsIterator()); |
| 33 for (; !rwit.IsAtEnd(); rwit.Advance()) { |
| 34 const RenderWidgetHost* widget = rwit.GetCurrentValue(); |
| 35 DCHECK(widget); |
| 36 if (!widget || !widget->IsRenderView()) |
| 37 continue; |
| 38 |
| 39 RenderViewHost* rvh = |
| 40 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); |
| 41 scoped_refptr<DevToolsAgentHost> agent(DevToolsAgentHost::GetFor(rvh)); |
| 42 agents_map_[agent->id()] = agent; |
| 43 } |
| 44 } |
| 45 } |
| 46 |
| 47 void DevToolsTargetList::Register(DevToolsAgentHost* agent_host) { |
| 48 GarbageCollect(); |
| 49 agents_map_[agent_host->id()] = agent_host; |
| 50 } |
| 51 |
| 52 DevToolsAgentHost* DevToolsTargetList::Lookup(const std::string& id) { |
| 53 GarbageCollect(); |
| 54 AgentsMap::iterator it = agents_map_.find(id); |
| 55 if (it != agents_map_.end()) |
| 56 return it->second; |
| 57 return NULL; |
| 58 } |
| 59 |
| 60 void DevToolsTargetList::GarbageCollect() { |
| 61 AgentsMap::iterator it = agents_map_.begin(); |
| 62 while (it != agents_map_.end()) { |
| 63 if (!it->second->GetRenderViewHost()) |
| 64 agents_map_.erase(it++); |
| 65 else |
| 66 ++it; |
| 67 } |
| 68 } |
| 69 |
| 70 } // namespace content |
OLD | NEW |