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

Side by Side Diff: content/browser/devtools/devtools_manager_impl.cc

Issue 13305002: Remove redundant DevToolsManager methods and clean up its clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/devtools/devtools_manager_impl.h" 5 #include "content/browser/devtools/devtools_manager_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 DevToolsManagerImpl::DevToolsManagerImpl() { 31 DevToolsManagerImpl::DevToolsManagerImpl() {
32 } 32 }
33 33
34 DevToolsManagerImpl::~DevToolsManagerImpl() { 34 DevToolsManagerImpl::~DevToolsManagerImpl() {
35 DCHECK(agent_to_client_host_.empty()); 35 DCHECK(agent_to_client_host_.empty());
36 DCHECK(client_to_agent_host_.empty()); 36 DCHECK(client_to_agent_host_.empty());
37 } 37 }
38 38
39 DevToolsClientHost* DevToolsManagerImpl::GetDevToolsClientHostFor( 39 bool DevToolsManagerImpl::IsAttached(DevToolsAgentHost* agent_host) {
40 DevToolsAgentHost* agent_host) {
41 DevToolsAgentHostImpl* agent_host_impl = 40 DevToolsAgentHostImpl* agent_host_impl =
42 static_cast<DevToolsAgentHostImpl*>(agent_host); 41 static_cast<DevToolsAgentHostImpl*>(agent_host);
42 return !!GetDevToolsClientHostFor(agent_host_impl);
43 }
44
45 DevToolsClientHost* DevToolsManagerImpl::GetDevToolsClientHostFor(
46 DevToolsAgentHostImpl* agent_host_impl) {
43 AgentToClientHostMap::iterator it = 47 AgentToClientHostMap::iterator it =
44 agent_to_client_host_.find(agent_host_impl); 48 agent_to_client_host_.find(agent_host_impl);
45 if (it != agent_to_client_host_.end()) 49 if (it != agent_to_client_host_.end())
46 return it->second; 50 return it->second;
47 return NULL; 51 return NULL;
48 } 52 }
49 53
50 DevToolsAgentHost* DevToolsManagerImpl::GetDevToolsAgentHostFor( 54 DevToolsAgentHost* DevToolsManagerImpl::GetDevToolsAgentHostFor(
51 DevToolsClientHost* client_host) { 55 DevToolsClientHost* client_host) {
52 ClientToAgentHostMap::iterator it = client_to_agent_host_.find(client_host); 56 ClientToAgentHostMap::iterator it = client_to_agent_host_.find(client_host);
53 if (it != client_to_agent_host_.end()) 57 if (it != client_to_agent_host_.end())
54 return it->second; 58 return it->second;
55 return NULL; 59 return NULL;
56 } 60 }
57 61
58 void DevToolsManagerImpl::RegisterDevToolsClientHostFor( 62 void DevToolsManagerImpl::RegisterDevToolsClientHostFor(
59 DevToolsAgentHost* agent_host, 63 DevToolsAgentHost* agent_host,
60 DevToolsClientHost* client_host) { 64 DevToolsClientHost* client_host) {
61 DevToolsAgentHostImpl* agent_host_impl = 65 DevToolsAgentHostImpl* agent_host_impl =
62 static_cast<DevToolsAgentHostImpl*>(agent_host); 66 static_cast<DevToolsAgentHostImpl*>(agent_host);
67 DevToolsClientHost* old_client_host =
68 GetDevToolsClientHostFor(agent_host_impl);
69 if (old_client_host) {
70 old_client_host->ReplacedWithAnotherClient();
pfeldman 2013/03/29 14:59:23 Ok. Only DevToolsWindow is allowed to kick other c
Vladislav Kaznacheev 2013/03/29 15:15:35 It was doing it through a public API which anyone
71 UnregisterDevToolsClientHostFor(agent_host_impl);
72 }
63 BindClientHost(agent_host_impl, client_host); 73 BindClientHost(agent_host_impl, client_host);
64 agent_host_impl->Attach(); 74 agent_host_impl->Attach();
65 } 75 }
66 76
67 bool DevToolsManagerImpl::DispatchOnInspectorBackend( 77 bool DevToolsManagerImpl::DispatchOnInspectorBackend(
68 DevToolsClientHost* from, 78 DevToolsClientHost* from,
69 const std::string& message) { 79 const std::string& message) {
70 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(from); 80 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(from);
71 if (!agent_host) 81 if (!agent_host)
72 return false; 82 return false;
73 DevToolsAgentHostImpl* agent_host_impl = 83 DevToolsAgentHostImpl* agent_host_impl =
74 static_cast<DevToolsAgentHostImpl*>(agent_host); 84 static_cast<DevToolsAgentHostImpl*>(agent_host);
75 agent_host_impl->DispatchOnInspectorBackend(message); 85 agent_host_impl->DispatchOnInspectorBackend(message);
76 return true; 86 return true;
77 } 87 }
78 88
79 void DevToolsManagerImpl::DispatchOnInspectorFrontend( 89 void DevToolsManagerImpl::DispatchOnInspectorFrontend(
80 DevToolsAgentHost* agent_host, 90 DevToolsAgentHost* agent_host,
81 const std::string& message) { 91 const std::string& message) {
82 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); 92 DevToolsAgentHostImpl* agent_host_impl =
93 static_cast<DevToolsAgentHostImpl*>(agent_host);
94 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host_impl);
83 if (!client_host) { 95 if (!client_host) {
84 // Client window was closed while there were messages 96 // Client window was closed while there were messages
85 // being sent to it. 97 // being sent to it.
86 return; 98 return;
87 } 99 }
88 client_host->DispatchOnInspectorFrontend(message); 100 client_host->DispatchOnInspectorFrontend(message);
89 } 101 }
90 102
91 void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) { 103 void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) {
92 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host); 104 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host);
93 if (!agent_host) 105 if (!agent_host)
94 return; 106 return;
95 DevToolsAgentHostImpl* agent_host_impl = 107 DevToolsAgentHostImpl* agent_host_impl =
96 static_cast<DevToolsAgentHostImpl*>(agent_host); 108 static_cast<DevToolsAgentHostImpl*>(agent_host);
97 UnbindClientHost(agent_host_impl, client_host); 109 UnbindClientHost(agent_host_impl, client_host);
98 } 110 }
99 111
100 void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHostImpl* agent_host) { 112 void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHostImpl* agent_host) {
101 UnregisterDevToolsClientHostFor(agent_host); 113 UnregisterDevToolsClientHostFor(
114 static_cast<DevToolsAgentHostImpl*>(agent_host));
102 } 115 }
103 116
104 void DevToolsManagerImpl::UnregisterDevToolsClientHostFor( 117 void DevToolsManagerImpl::UnregisterDevToolsClientHostFor(
105 DevToolsAgentHost* agent_host) { 118 DevToolsAgentHostImpl* agent_host) {
106 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); 119 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host);
107 if (!client_host) 120 if (!client_host)
108 return; 121 return;
109 DevToolsAgentHostImpl* agent_host_impl = 122 UnbindClientHost(agent_host, client_host);
110 static_cast<DevToolsAgentHostImpl*>(agent_host);
111 UnbindClientHost(agent_host_impl, client_host);
112 client_host->InspectedContentsClosing(); 123 client_host->InspectedContentsClosing();
113 } 124 }
114 125
115 void DevToolsManagerImpl::BindClientHost( 126 void DevToolsManagerImpl::BindClientHost(
116 DevToolsAgentHostImpl* agent_host, 127 DevToolsAgentHostImpl* agent_host,
117 DevToolsClientHost* client_host) { 128 DevToolsClientHost* client_host) {
118 DCHECK(agent_to_client_host_.find(agent_host) == 129 DCHECK(agent_to_client_host_.find(agent_host) ==
119 agent_to_client_host_.end()); 130 agent_to_client_host_.end());
120 DCHECK(client_to_agent_host_.find(client_host) == 131 DCHECK(client_to_agent_host_.find(client_host) ==
121 client_to_agent_host_.end()); 132 client_to_agent_host_.end());
(...skipping 27 matching lines...) Expand all
149 BrowserThread::IO, 160 BrowserThread::IO,
150 FROM_HERE, 161 FROM_HERE,
151 base::Bind(&DevToolsNetLogObserver::Detach)); 162 base::Bind(&DevToolsNetLogObserver::Detach));
152 } 163 }
153 // Lazy agent hosts can be deleted from within detach. 164 // Lazy agent hosts can be deleted from within detach.
154 // Do not access agent_host below this line. 165 // Do not access agent_host below this line.
155 agent_host->Detach(); 166 agent_host->Detach();
156 } 167 }
157 168
158 void DevToolsManagerImpl::CloseAllClientHosts() { 169 void DevToolsManagerImpl::CloseAllClientHosts() {
159 std::vector<DevToolsAgentHost*> agents; 170 std::vector<DevToolsAgentHostImpl*> agents;
160 for (AgentToClientHostMap::iterator it = 171 for (AgentToClientHostMap::iterator it =
161 agent_to_client_host_.begin(); 172 agent_to_client_host_.begin();
162 it != agent_to_client_host_.end(); ++it) { 173 it != agent_to_client_host_.end(); ++it) {
163 agents.push_back(it->first); 174 agents.push_back(it->first);
164 } 175 }
165 for (std::vector<DevToolsAgentHost*>::iterator it = agents.begin(); 176 for (std::vector<DevToolsAgentHostImpl*>::iterator it = agents.begin();
166 it != agents.end(); ++it) { 177 it != agents.end(); ++it) {
167 UnregisterDevToolsClientHostFor(*it); 178 UnregisterDevToolsClientHostFor(*it);
168 } 179 }
169 } 180 }
170 181
171 } // namespace content 182 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698