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()), | 79 : id_(base::GenerateGUID()), session_id_(0), client_(NULL) { |
80 client_(NULL) { | |
81 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 80 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
82 g_instances.Get()[id_] = this; | 81 g_instances.Get()[id_] = this; |
83 } | 82 } |
84 | 83 |
85 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 84 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
87 g_instances.Get().erase(g_instances.Get().find(id_)); | 86 g_instances.Get().erase(g_instances.Get().find(id_)); |
88 } | 87 } |
89 | 88 |
90 // static | 89 // static |
91 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 90 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
92 const std::string& id) { | 91 const std::string& id) { |
93 if (g_instances == NULL) | 92 if (g_instances == NULL) |
94 return NULL; | 93 return NULL; |
95 Instances::iterator it = g_instances.Get().find(id); | 94 Instances::iterator it = g_instances.Get().find(id); |
96 if (it == g_instances.Get().end()) | 95 if (it == g_instances.Get().end()) |
97 return NULL; | 96 return NULL; |
98 return it->second; | 97 return it->second; |
99 } | 98 } |
100 | 99 |
101 // static | 100 // static |
102 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( | 101 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( |
103 DevToolsExternalAgentProxyDelegate* delegate) { | 102 DevToolsExternalAgentProxyDelegate* delegate) { |
104 return new ForwardingAgentHost(delegate); | 103 return new ForwardingAgentHost(delegate); |
105 } | 104 } |
106 | 105 |
107 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { | 106 void DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { |
108 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 107 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 if (!client_) | 157 if (!client_) |
158 return; | 158 return; |
159 | 159 |
160 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 160 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
161 // Clear |client_| before notifying it. | 161 // Clear |client_| before notifying it. |
162 DevToolsAgentHostClient* client = client_; | 162 DevToolsAgentHostClient* client = client_; |
163 client_ = NULL; | 163 client_ = NULL; |
164 client->AgentHostClosed(this, false); | 164 client->AgentHostClosed(this, false); |
165 } | 165 } |
166 | 166 |
167 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { | 167 void DevToolsAgentHostImpl::SendMessageToClient(int session_id, |
168 const std::string& message) { | |
168 if (!client_) | 169 if (!client_) |
169 return; | 170 return; |
171 // Filter answer for message that was sent before reattach. | |
dgozman
2015/11/06 22:57:27
Filter any messages from previous sessions.
kozy
2015/11/07 01:54:43
Done.
| |
172 if (session_id && session_id != session_id_) | |
dgozman
2015/11/06 22:57:27
Would be great to kill "zero is always valid" case
kozy
2015/11/07 01:54:43
Done.
| |
173 return; | |
170 client_->DispatchProtocolMessage(this, message); | 174 client_->DispatchProtocolMessage(this, message); |
171 } | 175 } |
172 | 176 |
173 // static | 177 // static |
174 void DevToolsAgentHost::DetachAllClients() { | 178 void DevToolsAgentHost::DetachAllClients() { |
175 if (g_instances == NULL) | 179 if (g_instances == NULL) |
176 return; | 180 return; |
177 | 181 |
178 // Make a copy, since detaching may lead to agent destruction, which | 182 // Make a copy, since detaching may lead to agent destruction, which |
179 // removes it from the instances. | 183 // removes it from the instances. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 246 |
243 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent( | 247 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent( |
244 const DevToolsMessageChunk& chunk) { | 248 const DevToolsMessageChunk& chunk) { |
245 if (chunk.is_last && !chunk.post_state.empty()) | 249 if (chunk.is_last && !chunk.post_state.empty()) |
246 state_cookie_ = chunk.post_state; | 250 state_cookie_ = chunk.post_state; |
247 if (chunk.is_last) | 251 if (chunk.is_last) |
248 last_call_id_ = chunk.call_id; | 252 last_call_id_ = chunk.call_id; |
249 | 253 |
250 if (chunk.is_first && chunk.is_last) { | 254 if (chunk.is_first && chunk.is_last) { |
251 CHECK(message_buffer_size_ == 0); | 255 CHECK(message_buffer_size_ == 0); |
252 callback_.Run(chunk.data); | 256 callback_.Run(chunk.session_id, chunk.data); |
253 return; | 257 return; |
254 } | 258 } |
255 | 259 |
256 if (chunk.is_first) { | 260 if (chunk.is_first) { |
257 message_buffer_ = std::string(); | 261 message_buffer_ = std::string(); |
258 message_buffer_.reserve(chunk.message_size); | 262 message_buffer_.reserve(chunk.message_size); |
259 message_buffer_size_ = chunk.message_size; | 263 message_buffer_size_ = chunk.message_size; |
260 } | 264 } |
261 | 265 |
262 CHECK(message_buffer_.size() + chunk.data.size() <= | 266 CHECK(message_buffer_.size() + chunk.data.size() <= |
263 message_buffer_size_); | 267 message_buffer_size_); |
264 message_buffer_.append(chunk.data); | 268 message_buffer_.append(chunk.data); |
265 | 269 |
266 if (chunk.is_last) { | 270 if (chunk.is_last) { |
267 CHECK(message_buffer_.size() == message_buffer_size_); | 271 CHECK(message_buffer_.size() == message_buffer_size_); |
268 callback_.Run(message_buffer_); | 272 callback_.Run(chunk.session_id, message_buffer_); |
269 message_buffer_ = std::string(); | 273 message_buffer_ = std::string(); |
270 message_buffer_size_ = 0; | 274 message_buffer_size_ = 0; |
271 } | 275 } |
272 } | 276 } |
273 | 277 |
274 } // namespace content | 278 } // namespace content |
OLD | NEW |