OLD | NEW |
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 19 matching lines...) Expand all Loading... |
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 DevToolsClientHost* DevToolsManagerImpl::GetDevToolsClientHostFor( |
40 DevToolsAgentHost* agent_host) { | 40 DevToolsAgentHostImpl* agent_host_impl) { |
41 DevToolsAgentHostImpl* agent_host_impl = | |
42 static_cast<DevToolsAgentHostImpl*>(agent_host); | |
43 AgentToClientHostMap::iterator it = | 41 AgentToClientHostMap::iterator it = |
44 agent_to_client_host_.find(agent_host_impl); | 42 agent_to_client_host_.find(agent_host_impl); |
45 if (it != agent_to_client_host_.end()) | 43 if (it != agent_to_client_host_.end()) |
46 return it->second; | 44 return it->second; |
47 return NULL; | 45 return NULL; |
48 } | 46 } |
49 | 47 |
50 DevToolsAgentHost* DevToolsManagerImpl::GetDevToolsAgentHostFor( | 48 DevToolsAgentHost* DevToolsManagerImpl::GetDevToolsAgentHostFor( |
51 DevToolsClientHost* client_host) { | 49 DevToolsClientHost* client_host) { |
52 ClientToAgentHostMap::iterator it = client_to_agent_host_.find(client_host); | 50 ClientToAgentHostMap::iterator it = client_to_agent_host_.find(client_host); |
53 if (it != client_to_agent_host_.end()) | 51 if (it != client_to_agent_host_.end()) |
54 return it->second; | 52 return it->second; |
55 return NULL; | 53 return NULL; |
56 } | 54 } |
57 | 55 |
58 void DevToolsManagerImpl::RegisterDevToolsClientHostFor( | 56 void DevToolsManagerImpl::RegisterDevToolsClientHostFor( |
59 DevToolsAgentHost* agent_host, | 57 DevToolsAgentHost* agent_host, |
60 DevToolsClientHost* client_host) { | 58 DevToolsClientHost* client_host) { |
61 DevToolsAgentHostImpl* agent_host_impl = | 59 DevToolsAgentHostImpl* agent_host_impl = |
62 static_cast<DevToolsAgentHostImpl*>(agent_host); | 60 static_cast<DevToolsAgentHostImpl*>(agent_host); |
| 61 DevToolsClientHost* old_client_host = |
| 62 GetDevToolsClientHostFor(agent_host_impl); |
| 63 if (old_client_host) { |
| 64 old_client_host->ReplacedWithAnotherClient(); |
| 65 UnregisterDevToolsClientHostFor(agent_host_impl); |
| 66 } |
63 BindClientHost(agent_host_impl, client_host); | 67 BindClientHost(agent_host_impl, client_host); |
64 agent_host_impl->Attach(); | 68 agent_host_impl->Attach(); |
65 } | 69 } |
66 | 70 |
67 bool DevToolsManagerImpl::DispatchOnInspectorBackend( | 71 bool DevToolsManagerImpl::DispatchOnInspectorBackend( |
68 DevToolsClientHost* from, | 72 DevToolsClientHost* from, |
69 const std::string& message) { | 73 const std::string& message) { |
70 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(from); | 74 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(from); |
71 if (!agent_host) | 75 if (!agent_host) |
72 return false; | 76 return false; |
73 DevToolsAgentHostImpl* agent_host_impl = | 77 DevToolsAgentHostImpl* agent_host_impl = |
74 static_cast<DevToolsAgentHostImpl*>(agent_host); | 78 static_cast<DevToolsAgentHostImpl*>(agent_host); |
75 agent_host_impl->DispatchOnInspectorBackend(message); | 79 agent_host_impl->DispatchOnInspectorBackend(message); |
76 return true; | 80 return true; |
77 } | 81 } |
78 | 82 |
79 void DevToolsManagerImpl::DispatchOnInspectorFrontend( | 83 void DevToolsManagerImpl::DispatchOnInspectorFrontend( |
80 DevToolsAgentHost* agent_host, | 84 DevToolsAgentHost* agent_host, |
81 const std::string& message) { | 85 const std::string& message) { |
82 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); | 86 DevToolsAgentHostImpl* agent_host_impl = |
| 87 static_cast<DevToolsAgentHostImpl*>(agent_host); |
| 88 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host_impl); |
83 if (!client_host) { | 89 if (!client_host) { |
84 // Client window was closed while there were messages | 90 // Client window was closed while there were messages |
85 // being sent to it. | 91 // being sent to it. |
86 return; | 92 return; |
87 } | 93 } |
88 client_host->DispatchOnInspectorFrontend(message); | 94 client_host->DispatchOnInspectorFrontend(message); |
89 } | 95 } |
90 | 96 |
91 void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) { | 97 void DevToolsManagerImpl::ClientHostClosing(DevToolsClientHost* client_host) { |
92 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host); | 98 DevToolsAgentHost* agent_host = GetDevToolsAgentHostFor(client_host); |
93 if (!agent_host) | 99 if (!agent_host) |
94 return; | 100 return; |
95 DevToolsAgentHostImpl* agent_host_impl = | 101 DevToolsAgentHostImpl* agent_host_impl = |
96 static_cast<DevToolsAgentHostImpl*>(agent_host); | 102 static_cast<DevToolsAgentHostImpl*>(agent_host); |
97 UnbindClientHost(agent_host_impl, client_host); | 103 UnbindClientHost(agent_host_impl, client_host); |
98 } | 104 } |
99 | 105 |
100 void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHostImpl* agent_host) { | 106 void DevToolsManagerImpl::AgentHostClosing(DevToolsAgentHostImpl* agent_host) { |
101 UnregisterDevToolsClientHostFor(agent_host); | 107 UnregisterDevToolsClientHostFor(agent_host); |
102 } | 108 } |
103 | 109 |
104 void DevToolsManagerImpl::UnregisterDevToolsClientHostFor( | 110 void DevToolsManagerImpl::UnregisterDevToolsClientHostFor( |
105 DevToolsAgentHost* agent_host) { | 111 DevToolsAgentHostImpl* agent_host_impl) { |
106 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host); | 112 DevToolsClientHost* client_host = GetDevToolsClientHostFor(agent_host_impl); |
107 if (!client_host) | 113 if (!client_host) |
108 return; | 114 return; |
109 DevToolsAgentHostImpl* agent_host_impl = | |
110 static_cast<DevToolsAgentHostImpl*>(agent_host); | |
111 UnbindClientHost(agent_host_impl, client_host); | 115 UnbindClientHost(agent_host_impl, client_host); |
112 client_host->InspectedContentsClosing(); | 116 client_host->InspectedContentsClosing(); |
113 } | 117 } |
114 | 118 |
115 void DevToolsManagerImpl::BindClientHost( | 119 void DevToolsManagerImpl::BindClientHost( |
116 DevToolsAgentHostImpl* agent_host, | 120 DevToolsAgentHostImpl* agent_host, |
117 DevToolsClientHost* client_host) { | 121 DevToolsClientHost* client_host) { |
118 DCHECK(agent_to_client_host_.find(agent_host) == | 122 DCHECK(agent_to_client_host_.find(agent_host) == |
119 agent_to_client_host_.end()); | 123 agent_to_client_host_.end()); |
120 DCHECK(client_to_agent_host_.find(client_host) == | 124 DCHECK(client_to_agent_host_.find(client_host) == |
(...skipping 28 matching lines...) Expand all Loading... |
149 BrowserThread::IO, | 153 BrowserThread::IO, |
150 FROM_HERE, | 154 FROM_HERE, |
151 base::Bind(&DevToolsNetLogObserver::Detach)); | 155 base::Bind(&DevToolsNetLogObserver::Detach)); |
152 } | 156 } |
153 // Lazy agent hosts can be deleted from within detach. | 157 // Lazy agent hosts can be deleted from within detach. |
154 // Do not access agent_host below this line. | 158 // Do not access agent_host below this line. |
155 agent_host->Detach(); | 159 agent_host->Detach(); |
156 } | 160 } |
157 | 161 |
158 void DevToolsManagerImpl::CloseAllClientHosts() { | 162 void DevToolsManagerImpl::CloseAllClientHosts() { |
159 std::vector<DevToolsAgentHost*> agents; | 163 std::vector<DevToolsAgentHostImpl*> agents; |
160 for (AgentToClientHostMap::iterator it = | 164 for (AgentToClientHostMap::iterator it = |
161 agent_to_client_host_.begin(); | 165 agent_to_client_host_.begin(); |
162 it != agent_to_client_host_.end(); ++it) { | 166 it != agent_to_client_host_.end(); ++it) { |
163 agents.push_back(it->first); | 167 agents.push_back(it->first); |
164 } | 168 } |
165 for (std::vector<DevToolsAgentHost*>::iterator it = agents.begin(); | 169 for (std::vector<DevToolsAgentHostImpl*>::iterator it = agents.begin(); |
166 it != agents.end(); ++it) { | 170 it != agents.end(); ++it) { |
167 UnregisterDevToolsClientHostFor(*it); | 171 UnregisterDevToolsClientHostFor(*it); |
168 } | 172 } |
169 } | 173 } |
170 | 174 |
171 } // namespace content | 175 } // namespace content |
OLD | NEW |