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_agent_host_impl.h" | 5 #include "content/browser/devtools/devtools_agent_host_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 SharedWorkerDevToolsManager::GetInstance() | 69 SharedWorkerDevToolsManager::GetInstance() |
70 ->GetDevToolsAgentHostForWorker(worker_process_id, | 70 ->GetDevToolsAgentHostForWorker(worker_process_id, |
71 worker_route_id)) { | 71 worker_route_id)) { |
72 return host; | 72 return host; |
73 } | 73 } |
74 return ServiceWorkerDevToolsManager::GetInstance() | 74 return ServiceWorkerDevToolsManager::GetInstance() |
75 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 75 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
76 } | 76 } |
77 | 77 |
78 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 78 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
79 : id_(base::GenerateGUID()), session_id_(0), client_(NULL) { | 79 : id_(base::GenerateGUID()), |
| 80 client_(NULL) { |
80 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
81 g_instances.Get()[id_] = this; | 82 g_instances.Get()[id_] = this; |
82 } | 83 } |
83 | 84 |
84 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 85 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
85 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
86 g_instances.Get().erase(g_instances.Get().find(id_)); | 87 g_instances.Get().erase(g_instances.Get().find(id_)); |
87 } | 88 } |
88 | 89 |
89 // static | 90 // static |
90 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 91 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
91 const std::string& id) { | 92 const std::string& id) { |
92 if (g_instances == NULL) | 93 if (g_instances == NULL) |
93 return NULL; | 94 return NULL; |
94 Instances::iterator it = g_instances.Get().find(id); | 95 Instances::iterator it = g_instances.Get().find(id); |
95 if (it == g_instances.Get().end()) | 96 if (it == g_instances.Get().end()) |
96 return NULL; | 97 return NULL; |
97 return it->second; | 98 return it->second; |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( | 102 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( |
102 DevToolsExternalAgentProxyDelegate* delegate) { | 103 DevToolsExternalAgentProxyDelegate* delegate) { |
103 return new ForwardingAgentHost(delegate); | 104 return new ForwardingAgentHost(delegate); |
104 } | 105 } |
105 | 106 |
106 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { | 107 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { |
107 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 108 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
108 ++session_id_; | |
109 if (client_) { | 109 if (client_) { |
110 client_->AgentHostClosed(this, true); | 110 client_->AgentHostClosed(this, true); |
111 InnerDetach(); | 111 InnerDetach(); |
112 } | 112 } |
113 client_ = client; | 113 client_ = client; |
114 Attach(); | 114 Attach(); |
115 } | 115 } |
116 | 116 |
117 void DevToolsAgentHostImpl::DetachClient() { | 117 void DevToolsAgentHostImpl::DetachClient() { |
118 if (!client_) | 118 if (!client_) |
(...skipping 27 matching lines...) Expand all Loading... |
146 WebContents* DevToolsAgentHostImpl::GetWebContents() { | 146 WebContents* DevToolsAgentHostImpl::GetWebContents() { |
147 return NULL; | 147 return NULL; |
148 } | 148 } |
149 | 149 |
150 void DevToolsAgentHostImpl::DisconnectWebContents() { | 150 void DevToolsAgentHostImpl::DisconnectWebContents() { |
151 } | 151 } |
152 | 152 |
153 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { | 153 void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { |
154 } | 154 } |
155 | 155 |
156 void DevToolsAgentHostImpl::SendProtocolResponse(int session_id, | |
157 const std::string& message) { | |
158 SendMessageToClient(session_id, message); | |
159 } | |
160 | |
161 void DevToolsAgentHostImpl::SendProtocolNotification( | |
162 const std::string& message) { | |
163 SendMessageToClient(session_id(), message); | |
164 } | |
165 | |
166 void DevToolsAgentHostImpl::HostClosed() { | 156 void DevToolsAgentHostImpl::HostClosed() { |
167 if (!client_) | 157 if (!client_) |
168 return; | 158 return; |
169 | 159 |
170 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 160 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
171 // Clear |client_| before notifying it. | 161 // Clear |client_| before notifying it. |
172 DevToolsAgentHostClient* client = client_; | 162 DevToolsAgentHostClient* client = client_; |
173 client_ = NULL; | 163 client_ = NULL; |
174 client->AgentHostClosed(this, false); | 164 client->AgentHostClosed(this, false); |
175 } | 165 } |
176 | 166 |
177 void DevToolsAgentHostImpl::SendMessageToClient(int session_id, | 167 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { |
178 const std::string& message) { | |
179 if (!client_) | 168 if (!client_) |
180 return; | 169 return; |
181 // Filter any messages from previous sessions. | |
182 if (session_id != session_id_) | |
183 return; | |
184 client_->DispatchProtocolMessage(this, message); | 170 client_->DispatchProtocolMessage(this, message); |
185 } | 171 } |
186 | 172 |
187 // static | 173 // static |
188 void DevToolsAgentHost::DetachAllClients() { | 174 void DevToolsAgentHost::DetachAllClients() { |
189 if (g_instances == NULL) | 175 if (g_instances == NULL) |
190 return; | 176 return; |
191 | 177 |
192 // Make a copy, since detaching may lead to agent destruction, which | 178 // Make a copy, since detaching may lead to agent destruction, which |
193 // removes it from the instances. | 179 // removes it from the instances. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 242 |
257 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent( | 243 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent( |
258 const DevToolsMessageChunk& chunk) { | 244 const DevToolsMessageChunk& chunk) { |
259 if (chunk.is_last && !chunk.post_state.empty()) | 245 if (chunk.is_last && !chunk.post_state.empty()) |
260 state_cookie_ = chunk.post_state; | 246 state_cookie_ = chunk.post_state; |
261 if (chunk.is_last) | 247 if (chunk.is_last) |
262 last_call_id_ = chunk.call_id; | 248 last_call_id_ = chunk.call_id; |
263 | 249 |
264 if (chunk.is_first && chunk.is_last) { | 250 if (chunk.is_first && chunk.is_last) { |
265 CHECK(message_buffer_size_ == 0); | 251 CHECK(message_buffer_size_ == 0); |
266 callback_.Run(chunk.session_id, chunk.data); | 252 callback_.Run(chunk.data); |
267 return; | 253 return; |
268 } | 254 } |
269 | 255 |
270 if (chunk.is_first) { | 256 if (chunk.is_first) { |
271 message_buffer_ = std::string(); | 257 message_buffer_ = std::string(); |
272 message_buffer_.reserve(chunk.message_size); | 258 message_buffer_.reserve(chunk.message_size); |
273 message_buffer_size_ = chunk.message_size; | 259 message_buffer_size_ = chunk.message_size; |
274 } | 260 } |
275 | 261 |
276 CHECK(message_buffer_.size() + chunk.data.size() <= | 262 CHECK(message_buffer_.size() + chunk.data.size() <= |
277 message_buffer_size_); | 263 message_buffer_size_); |
278 message_buffer_.append(chunk.data); | 264 message_buffer_.append(chunk.data); |
279 | 265 |
280 if (chunk.is_last) { | 266 if (chunk.is_last) { |
281 CHECK(message_buffer_.size() == message_buffer_size_); | 267 CHECK(message_buffer_.size() == message_buffer_size_); |
282 callback_.Run(chunk.session_id, message_buffer_); | 268 callback_.Run(message_buffer_); |
283 message_buffer_ = std::string(); | 269 message_buffer_ = std::string(); |
284 message_buffer_size_ = 0; | 270 message_buffer_size_ = 0; |
285 } | 271 } |
286 } | 272 } |
287 | 273 |
288 } // namespace content | 274 } // namespace content |
OLD | NEW |