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

Side by Side Diff: content/public/browser/devtools_target_list.cc

Issue 12319114: Extract debugger target enumeration into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@debugger
Patch Set: Cleaner version ready for review 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 unified diff | Download patch
OLDNEW
(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/stringprintf.h"
9 #include "base/values.h"
10 #include "content/public/browser/devtools_agent_host.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13
14 namespace content {
15
16 DevToolsTargetList* DevToolsTargetList::GetInstance() {
17 return Singleton<DevToolsTargetList>::get();
18 }
19
20 DevToolsTargetList::AgentsMap& DevToolsTargetList::GetAgentsMap() {
21 GarbageCollect();
22
23 for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
24 !it.IsAtEnd(); it.Advance()) {
25 RenderProcessHost* render_process_host = it.GetCurrentValue();
26 DCHECK(render_process_host);
27
28 // Ignore processes that don't have a connection, such as crashed contents.
29 if (!render_process_host->HasConnection())
30 continue;
31
32 RenderProcessHost::RenderWidgetHostsIterator rwit(
33 render_process_host->GetRenderWidgetHostsIterator());
34 for (; !rwit.IsAtEnd(); rwit.Advance()) {
35 const RenderWidgetHost* widget = rwit.GetCurrentValue();
36 DCHECK(widget);
37 if (!widget || !widget->IsRenderView())
38 continue;
39
40 RenderViewHost* rvh =
41 RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
42 UpdateMap(DevToolsAgentHost::GetFor(rvh));
43 }
44 }
45 return agents_map_;
46 }
47
48 std::string DevToolsTargetList::GetIdentifier(DevToolsAgentHost* agent_host) {
49 GarbageCollect();
50 return UpdateMap(agent_host);
51 }
52
53 DevToolsAgentHost* DevToolsTargetList::ForIdentifier(const std::string& id) {
54 GarbageCollect();
55 AgentsMap::iterator it = agents_map_.find(id);
56 if (it != agents_map_.end())
57 return it->second;
58 return NULL;
59 }
60
61 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.
62 std::string id = base::StringPrintf("%d", agent_host->id());
63 agents_map_[id] = agent_host;
64 return id;
65 }
66
67 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.
68 AgentsMap::iterator it = agents_map_.begin();
69 while (it != agents_map_.end()) {
70 if (!it->second->GetRenderViewHost())
71 agents_map_.erase(it++);
72 else
73 ++it;
74 }
75 }
76
77 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698