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

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

Issue 2863623003: [DevTools] Support multiple sessions in content/ domain handlers (Closed)
Patch Set: addressed review comments Created 3 years, 7 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
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/bind.h" 10 #include "base/bind.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 SharedWorkerDevToolsManager::GetInstance() 111 SharedWorkerDevToolsManager::GetInstance()
112 ->GetDevToolsAgentHostForWorker(worker_process_id, 112 ->GetDevToolsAgentHostForWorker(worker_process_id,
113 worker_route_id)) { 113 worker_route_id)) {
114 return host; 114 return host;
115 } 115 }
116 return ServiceWorkerDevToolsManager::GetInstance() 116 return ServiceWorkerDevToolsManager::GetInstance()
117 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); 117 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id);
118 } 118 }
119 119
120 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) 120 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
121 : id_(id), 121 : id_(id), last_session_id_(0), session_(nullptr) {
122 last_session_id_(0) {
123 DCHECK_CURRENTLY_ON(BrowserThread::UI); 122 DCHECK_CURRENTLY_ON(BrowserThread::UI);
124 } 123 }
125 124
126 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 125 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
128 NotifyDestroyed(); 127 NotifyDestroyed();
129 } 128 }
130 129
131 // static 130 // static
132 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( 131 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId(
(...skipping 17 matching lines...) Expand all
150 } 149 }
151 150
152 bool DevToolsAgentHostImpl::InnerAttachClient(DevToolsAgentHostClient* client, 151 bool DevToolsAgentHostImpl::InnerAttachClient(DevToolsAgentHostClient* client,
153 bool force) { 152 bool force) {
154 if (session_ && !force) 153 if (session_ && !force)
155 return false; 154 return false;
156 155
157 scoped_refptr<DevToolsAgentHostImpl> protect(this); 156 scoped_refptr<DevToolsAgentHostImpl> protect(this);
158 if (session_) 157 if (session_)
159 ForceDetach(true); 158 ForceDetach(true);
160 session_.reset(new DevToolsSession(this, client, ++last_session_id_)); 159 DCHECK(!session_);
161 AttachSession(session_.get()); 160 session_ = new DevToolsSession(this, client, ++last_session_id_);
161 sessions_.insert(std::unique_ptr<DevToolsSession>(session_));
162 AttachSession(session_);
162 NotifyAttached(); 163 NotifyAttached();
163 return true; 164 return true;
164 } 165 }
165 166
166 bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { 167 bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) {
167 return InnerAttachClient(client, false); 168 return InnerAttachClient(client, false);
168 } 169 }
169 170
170 void DevToolsAgentHostImpl::ForceAttachClient(DevToolsAgentHostClient* client) { 171 void DevToolsAgentHostImpl::ForceAttachClient(DevToolsAgentHostClient* client) {
171 InnerAttachClient(client, true); 172 InnerAttachClient(client, true);
172 } 173 }
173 174
174 bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) { 175 bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) {
175 if (!session_ || session_->client() != client) 176 if (!session_ || session_->client() != client)
176 return false; 177 return false;
177 178
178 scoped_refptr<DevToolsAgentHostImpl> protect(this); 179 scoped_refptr<DevToolsAgentHostImpl> protect(this);
179 InnerDetachClient(); 180 InnerDetachClient();
180 return true; 181 return true;
181 } 182 }
182 183
183 bool DevToolsAgentHostImpl::DispatchProtocolMessage( 184 bool DevToolsAgentHostImpl::DispatchProtocolMessage(
184 DevToolsAgentHostClient* client, 185 DevToolsAgentHostClient* client,
185 const std::string& message) { 186 const std::string& message) {
186 if (!session_ || session_->client() != client) 187 if (!session_ || session_->client() != client)
187 return false; 188 return false;
188 return DispatchProtocolMessage(session_.get(), message); 189 return DispatchProtocolMessage(session_, message);
189 } 190 }
190 191
191 void DevToolsAgentHostImpl::InnerDetachClient() { 192 void DevToolsAgentHostImpl::InnerDetachClient() {
192 int session_id = session_->session_id(); 193 int session_id = session_->session_id();
193 session_.reset(); 194 session_ = nullptr;
195 sessions_.clear();
194 DetachSession(session_id); 196 DetachSession(session_id);
195 io_context_.DiscardAllStreams(); 197 io_context_.DiscardAllStreams();
196 NotifyDetached(); 198 NotifyDetached();
197 } 199 }
198 200
199 bool DevToolsAgentHostImpl::IsAttached() { 201 bool DevToolsAgentHostImpl::IsAttached() {
200 return !!session_; 202 return !!session_;
201 } 203 }
202 204
203 void DevToolsAgentHostImpl::InspectElement( 205 void DevToolsAgentHostImpl::InspectElement(
204 DevToolsAgentHostClient* client, 206 DevToolsAgentHostClient* client,
205 int x, 207 int x,
206 int y) { 208 int y) {
207 if (!session_ || session_->client() != client) 209 if (!session_ || session_->client() != client)
208 return; 210 return;
209 InspectElement(session_.get(), x, y); 211 InspectElement(session_, x, y);
210 } 212 }
211 213
212 std::string DevToolsAgentHostImpl::GetId() { 214 std::string DevToolsAgentHostImpl::GetId() {
213 return id_; 215 return id_;
214 } 216 }
215 217
216 std::string DevToolsAgentHostImpl::GetParentId() { 218 std::string DevToolsAgentHostImpl::GetParentId() {
217 return ""; 219 return "";
218 } 220 }
219 221
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (message_buffer_.size() != message_buffer_size_) 404 if (message_buffer_.size() != message_buffer_size_)
403 return false; 405 return false;
404 callback_.Run(chunk.session_id, message_buffer_); 406 callback_.Run(chunk.session_id, message_buffer_);
405 message_buffer_ = std::string(); 407 message_buffer_ = std::string();
406 message_buffer_size_ = 0; 408 message_buffer_size_ = 0;
407 } 409 }
408 return true; 410 return true;
409 } 411 }
410 412
411 } // namespace content 413 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/devtools_io_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698