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

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

Issue 1437283003: [DevTools] filter any messages from previous session in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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
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 27 matching lines...) Expand all
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);
dgozman 2015/11/20 20:25:07 seesion_id_
kozy 2015/11/21 00:49:00 Done.
164 }
165
156 void DevToolsAgentHostImpl::HostClosed() { 166 void DevToolsAgentHostImpl::HostClosed() {
157 if (!client_) 167 if (!client_)
158 return; 168 return;
159 169
160 scoped_refptr<DevToolsAgentHostImpl> protect(this); 170 scoped_refptr<DevToolsAgentHostImpl> protect(this);
161 // Clear |client_| before notifying it. 171 // Clear |client_| before notifying it.
162 DevToolsAgentHostClient* client = client_; 172 DevToolsAgentHostClient* client = client_;
163 client_ = NULL; 173 client_ = NULL;
164 client->AgentHostClosed(this, false); 174 client->AgentHostClosed(this, false);
165 } 175 }
166 176
167 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { 177 void DevToolsAgentHostImpl::SendMessageToClient(int session_id,
178 const std::string& message) {
168 if (!client_) 179 if (!client_)
169 return; 180 return;
181 // Filter any messages from previous sessions.
182 if (session_id != session_id_)
183 return;
170 client_->DispatchProtocolMessage(this, message); 184 client_->DispatchProtocolMessage(this, message);
171 } 185 }
172 186
173 // static 187 // static
174 void DevToolsAgentHost::DetachAllClients() { 188 void DevToolsAgentHost::DetachAllClients() {
175 if (g_instances == NULL) 189 if (g_instances == NULL)
176 return; 190 return;
177 191
178 // Make a copy, since detaching may lead to agent destruction, which 192 // Make a copy, since detaching may lead to agent destruction, which
179 // removes it from the instances. 193 // removes it from the instances.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 256
243 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent( 257 void DevToolsMessageChunkProcessor::ProcessChunkedMessageFromAgent(
244 const DevToolsMessageChunk& chunk) { 258 const DevToolsMessageChunk& chunk) {
245 if (chunk.is_last && !chunk.post_state.empty()) 259 if (chunk.is_last && !chunk.post_state.empty())
246 state_cookie_ = chunk.post_state; 260 state_cookie_ = chunk.post_state;
247 if (chunk.is_last) 261 if (chunk.is_last)
248 last_call_id_ = chunk.call_id; 262 last_call_id_ = chunk.call_id;
249 263
250 if (chunk.is_first && chunk.is_last) { 264 if (chunk.is_first && chunk.is_last) {
251 CHECK(message_buffer_size_ == 0); 265 CHECK(message_buffer_size_ == 0);
252 callback_.Run(chunk.data); 266 callback_.Run(chunk.session_id, chunk.data);
253 return; 267 return;
254 } 268 }
255 269
256 if (chunk.is_first) { 270 if (chunk.is_first) {
257 message_buffer_ = std::string(); 271 message_buffer_ = std::string();
258 message_buffer_.reserve(chunk.message_size); 272 message_buffer_.reserve(chunk.message_size);
259 message_buffer_size_ = chunk.message_size; 273 message_buffer_size_ = chunk.message_size;
260 } 274 }
261 275
262 CHECK(message_buffer_.size() + chunk.data.size() <= 276 CHECK(message_buffer_.size() + chunk.data.size() <=
263 message_buffer_size_); 277 message_buffer_size_);
264 message_buffer_.append(chunk.data); 278 message_buffer_.append(chunk.data);
265 279
266 if (chunk.is_last) { 280 if (chunk.is_last) {
267 CHECK(message_buffer_.size() == message_buffer_size_); 281 CHECK(message_buffer_.size() == message_buffer_size_);
268 callback_.Run(message_buffer_); 282 callback_.Run(chunk.session_id, message_buffer_);
269 message_buffer_ = std::string(); 283 message_buffer_ = std::string();
270 message_buffer_size_ = 0; 284 message_buffer_size_ = 0;
271 } 285 }
272 } 286 }
273 287
274 } // namespace content 288 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698