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

Side by Side Diff: net/socket_stream/socket_stream.cc

Issue 10548028: NetLogEventParameter to Callback refactoring 8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix includes Created 8 years, 6 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 | Annotate | Revision Log
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 // TODO(ukai): code is similar with http_network_transaction.cc. We should 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should
6 // think about ways to share code, if possible. 6 // think about ways to share code, if possible.
7 7
8 #include "net/socket_stream/socket_stream.h" 8 #include "net/socket_stream/socket_stream.h"
9 9
10 #include <set> 10 #include <set>
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 const URLRequestContext* prev_context = context_; 106 const URLRequestContext* prev_context = context_;
107 107
108 context_ = context; 108 context_ = context;
109 109
110 if (prev_context != context) { 110 if (prev_context != context) {
111 if (prev_context && pac_request_) { 111 if (prev_context && pac_request_) {
112 prev_context->proxy_service()->CancelPacRequest(pac_request_); 112 prev_context->proxy_service()->CancelPacRequest(pac_request_);
113 pac_request_ = NULL; 113 pac_request_ = NULL;
114 } 114 }
115 115
116 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); 116 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
117 net_log_ = BoundNetLog(); 117 net_log_ = BoundNetLog();
118 118
119 if (context) { 119 if (context) {
120 net_log_ = BoundNetLog::Make( 120 net_log_ = BoundNetLog::Make(
121 context->net_log(), 121 context->net_log(),
122 NetLog::SOURCE_SOCKET_STREAM); 122 NetLog::SOURCE_SOCKET_STREAM);
123 123
124 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); 124 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
125 } 125 }
126 } 126 }
127 127
128 if (context_) { 128 if (context_) {
129 host_resolver_ = context_->host_resolver(); 129 host_resolver_ = context_->host_resolver();
130 cert_verifier_ = context_->cert_verifier(); 130 cert_verifier_ = context_->cert_verifier();
131 server_bound_cert_service_ = context_->server_bound_cert_service(); 131 server_bound_cert_service_ = context_->server_bound_cert_service();
132 http_auth_handler_factory_ = context_->http_auth_handler_factory(); 132 http_auth_handler_factory_ = context_->http_auth_handler_factory();
133 } 133 }
134 } 134 }
135 135
136 void SocketStream::Connect() { 136 void SocketStream::Connect() {
137 DCHECK(MessageLoop::current()) << 137 DCHECK(MessageLoop::current()) <<
138 "The current MessageLoop must exist"; 138 "The current MessageLoop must exist";
139 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 139 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
140 "The current MessageLoop must be TYPE_IO"; 140 "The current MessageLoop must be TYPE_IO";
141 if (context_) { 141 if (context_) {
142 ssl_config_service()->GetSSLConfig(&server_ssl_config_); 142 ssl_config_service()->GetSSLConfig(&server_ssl_config_);
143 proxy_ssl_config_ = server_ssl_config_; 143 proxy_ssl_config_ = server_ssl_config_;
144 } 144 }
145 DCHECK_EQ(next_state_, STATE_NONE); 145 DCHECK_EQ(next_state_, STATE_NONE);
146 146
147 AddRef(); // Released in Finish() 147 AddRef(); // Released in Finish()
148 // Open a connection asynchronously, so that delegate won't be called 148 // Open a connection asynchronously, so that delegate won't be called
149 // back before returning Connect(). 149 // back before returning Connect().
150 next_state_ = STATE_BEFORE_CONNECT; 150 next_state_ = STATE_BEFORE_CONNECT;
151 net_log_.BeginEvent( 151 net_log_.BeginEvent(
152 NetLog::TYPE_SOCKET_STREAM_CONNECT, 152 NetLog::TYPE_SOCKET_STREAM_CONNECT,
153 make_scoped_refptr( 153 NetLog::StringCallback("url", &url_.possibly_invalid_spec()));
154 new NetLogStringParameter("url", url_.possibly_invalid_spec())));
155 MessageLoop::current()->PostTask( 154 MessageLoop::current()->PostTask(
156 FROM_HERE, 155 FROM_HERE,
157 base::Bind(&SocketStream::DoLoop, this, OK)); 156 base::Bind(&SocketStream::DoLoop, this, OK));
158 } 157 }
159 158
160 bool SocketStream::SendData(const char* data, int len) { 159 bool SocketStream::SendData(const char* data, int len) {
161 DCHECK(MessageLoop::current()) << 160 DCHECK(MessageLoop::current()) <<
162 "The current MessageLoop must exist"; 161 "The current MessageLoop must exist";
163 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 162 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
164 "The current MessageLoop must be TYPE_IO"; 163 "The current MessageLoop must be TYPE_IO";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 228
230 MessageLoop::current()->PostTask( 229 MessageLoop::current()->PostTask(
231 FROM_HERE, 230 FROM_HERE,
232 base::Bind(&SocketStream::DoRestartWithAuth, this)); 231 base::Bind(&SocketStream::DoRestartWithAuth, this));
233 } 232 }
234 233
235 void SocketStream::DetachDelegate() { 234 void SocketStream::DetachDelegate() {
236 if (!delegate_) 235 if (!delegate_)
237 return; 236 return;
238 delegate_ = NULL; 237 delegate_ = NULL;
239 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); 238 net_log_.AddEvent(NetLog::TYPE_CANCELLED);
240 // We don't need to send pending data when client detach the delegate. 239 // We don't need to send pending data when client detach the delegate.
241 pending_write_bufs_.clear(); 240 pending_write_bufs_.clear();
242 Close(); 241 Close();
243 } 242 }
244 243
245 const ProxyServer& SocketStream::proxy_server() const { 244 const ProxyServer& SocketStream::proxy_server() const {
246 return proxy_info_.proxy_server(); 245 return proxy_info_.proxy_server();
247 } 246 }
248 247
249 void SocketStream::SetClientSocketFactory( 248 void SocketStream::SetClientSocketFactory(
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 321 }
323 322
324 int SocketStream::DidEstablishConnection() { 323 int SocketStream::DidEstablishConnection() {
325 if (!socket_.get() || !socket_->IsConnected()) { 324 if (!socket_.get() || !socket_->IsConnected()) {
326 next_state_ = STATE_CLOSE; 325 next_state_ = STATE_CLOSE;
327 return ERR_CONNECTION_FAILED; 326 return ERR_CONNECTION_FAILED;
328 } 327 }
329 next_state_ = STATE_READ_WRITE; 328 next_state_ = STATE_READ_WRITE;
330 metrics_->OnConnected(); 329 metrics_->OnConnected();
331 330
332 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT, NULL); 331 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT);
333 if (delegate_) 332 if (delegate_)
334 delegate_->OnConnected(this, max_pending_send_allowed_); 333 delegate_->OnConnected(this, max_pending_send_allowed_);
335 334
336 return OK; 335 return OK;
337 } 336 }
338 337
339 int SocketStream::DidReceiveData(int result) { 338 int SocketStream::DidReceiveData(int result) {
340 DCHECK(read_buf_); 339 DCHECK(read_buf_);
341 DCHECK_GT(result, 0); 340 DCHECK_GT(result, 0);
342 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_RECEIVED, NULL); 341 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_RECEIVED);
343 int len = result; 342 int len = result;
344 metrics_->OnRead(len); 343 metrics_->OnRead(len);
345 if (delegate_) { 344 if (delegate_) {
346 // Notify recevied data to delegate. 345 // Notify recevied data to delegate.
347 delegate_->OnReceivedData(this, read_buf_->data(), len); 346 delegate_->OnReceivedData(this, read_buf_->data(), len);
348 } 347 }
349 read_buf_ = NULL; 348 read_buf_ = NULL;
350 return OK; 349 return OK;
351 } 350 }
352 351
353 int SocketStream::DidSendData(int result) { 352 int SocketStream::DidSendData(int result) {
354 DCHECK_GT(result, 0); 353 DCHECK_GT(result, 0);
355 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_SENT, NULL); 354 net_log_.AddEvent(NetLog::TYPE_SOCKET_STREAM_SENT);
356 int len = result; 355 int len = result;
357 metrics_->OnWrite(len); 356 metrics_->OnWrite(len);
358 current_write_buf_ = NULL; 357 current_write_buf_ = NULL;
359 if (delegate_) 358 if (delegate_)
360 delegate_->OnSentData(this, len); 359 delegate_->OnSentData(this, len);
361 360
362 int remaining_size = write_buf_size_ - write_buf_offset_ - len; 361 int remaining_size = write_buf_size_ - write_buf_offset_ - len;
363 if (remaining_size == 0) { 362 if (remaining_size == 0) {
364 if (!pending_write_bufs_.empty()) { 363 if (!pending_write_bufs_.empty()) {
365 write_buf_size_ = pending_write_bufs_.front()->size(); 364 write_buf_size_ = pending_write_bufs_.front()->size();
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 1287
1289 SSLConfigService* SocketStream::ssl_config_service() const { 1288 SSLConfigService* SocketStream::ssl_config_service() const {
1290 return context_->ssl_config_service(); 1289 return context_->ssl_config_service();
1291 } 1290 }
1292 1291
1293 ProxyService* SocketStream::proxy_service() const { 1292 ProxyService* SocketStream::proxy_service() const {
1294 return context_->proxy_service(); 1293 return context_->proxy_service();
1295 } 1294 }
1296 1295
1297 } // namespace net 1296 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698