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

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

Issue 1155703003: [DevTools] Inline IPCDevToolsAgentHost into subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return ServiceWorkerDevToolsManager::GetInstance() 75 return ServiceWorkerDevToolsManager::GetInstance()
76 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); 76 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id);
77 } 77 }
78 78
79 DevToolsAgentHostImpl::DevToolsAgentHostImpl() 79 DevToolsAgentHostImpl::DevToolsAgentHostImpl()
80 : protocol_handler_(new DevToolsProtocolHandler( 80 : protocol_handler_(new DevToolsProtocolHandler(
81 base::Bind(&DevToolsAgentHostImpl::SendMessageToClient, 81 base::Bind(&DevToolsAgentHostImpl::SendMessageToClient,
82 base::Unretained(this)))), 82 base::Unretained(this)))),
83 id_(base::GenerateGUID()), 83 id_(base::GenerateGUID()),
84 client_(NULL), 84 client_(NULL),
85 handle_all_commands_(false) { 85 handle_all_commands_(false),
86 message_buffer_size_(0) {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); 87 DCHECK_CURRENTLY_ON(BrowserThread::UI);
87 g_instances.Get()[id_] = this; 88 g_instances.Get()[id_] = this;
88 } 89 }
89 90
90 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 91 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
91 DCHECK_CURRENTLY_ON(BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
92 g_instances.Get().erase(g_instances.Get().find(id_)); 93 g_instances.Get().erase(g_instances.Get().find(id_));
93 } 94 }
94 95
95 // static 96 // static
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 client_ = NULL; 164 client_ = NULL;
164 client->AgentHostClosed(this, false); 165 client->AgentHostClosed(this, false);
165 } 166 }
166 167
167 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) { 168 void DevToolsAgentHostImpl::SendMessageToClient(const std::string& message) {
168 if (!client_) 169 if (!client_)
169 return; 170 return;
170 client_->DispatchProtocolMessage(this, message); 171 client_->DispatchProtocolMessage(this, message);
171 } 172 }
172 173
174 void DevToolsAgentHostImpl::ProcessChunkedMessageFromAgent(
175 const DevToolsMessageChunk& chunk) {
176 if (chunk.is_last && !chunk.post_state.empty())
177 state_cookie_ = chunk.post_state;
178
179 if (chunk.is_first && chunk.is_last) {
180 CHECK(message_buffer_size_ == 0);
181 SendMessageToClient(chunk.data);
182 return;
183 }
184
185 if (chunk.is_first) {
186 message_buffer_ = std::string();
187 message_buffer_.reserve(chunk.message_size);
188 message_buffer_size_ = chunk.message_size;
189 }
190
191 CHECK(message_buffer_.size() + chunk.data.size() <=
192 message_buffer_size_);
193 message_buffer_.append(chunk.data);
194
195 if (chunk.is_last) {
196 CHECK(message_buffer_.size() == message_buffer_size_);
197 SendMessageToClient(message_buffer_);
198 message_buffer_ = std::string();
199 message_buffer_size_ = 0;
200 }
201 }
202
173 // static 203 // static
174 void DevToolsAgentHost::DetachAllClients() { 204 void DevToolsAgentHost::DetachAllClients() {
175 if (g_instances == NULL) 205 if (g_instances == NULL)
176 return; 206 return;
177 207
178 // Make a copy, since detaching may lead to agent destruction, which 208 // Make a copy, since detaching may lead to agent destruction, which
179 // removes it from the instances. 209 // removes it from the instances.
180 Instances copy = g_instances.Get(); 210 Instances copy = g_instances.Get();
181 for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) { 211 for (Instances::iterator it(copy.begin()); it != copy.end(); ++it) {
182 DevToolsAgentHostImpl* agent_host = it->second; 212 DevToolsAgentHostImpl* agent_host = it->second;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 278 }
249 } 279 }
250 280
251 if (!handle_all_commands_) 281 if (!handle_all_commands_)
252 return protocol_handler_->HandleOptionalCommand(command.Pass()); 282 return protocol_handler_->HandleOptionalCommand(command.Pass());
253 protocol_handler_->HandleCommand(command.Pass()); 283 protocol_handler_->HandleCommand(command.Pass());
254 return true; 284 return true;
255 } 285 }
256 286
257 } // namespace content 287 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/ipc_devtools_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698