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

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

Issue 10541046: Adds NetworkDelegate::NotifyBeforeSocketStreamConnect() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comments 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
« no previous file with comments | « net/socket_stream/socket_stream.h ('k') | net/socket_stream/socket_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_RESOLVE_PROXY; 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 make_scoped_refptr(
154 new NetLogStringParameter("url", url_.possibly_invalid_spec()))); 154 new NetLogStringParameter("url", url_.possibly_invalid_spec())));
155 MessageLoop::current()->PostTask( 155 MessageLoop::current()->PostTask(
156 FROM_HERE, 156 FROM_HERE,
157 base::Bind(&SocketStream::DoLoop, this, OK)); 157 base::Bind(&SocketStream::DoLoop, this, OK));
158 } 158 }
159 159
160 bool SocketStream::SendData(const char* data, int len) { 160 bool SocketStream::SendData(const char* data, int len) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (!context_) 403 if (!context_)
404 next_state_ = STATE_CLOSE; 404 next_state_ = STATE_CLOSE;
405 405
406 if (next_state_ == STATE_NONE) 406 if (next_state_ == STATE_NONE)
407 return; 407 return;
408 408
409 do { 409 do {
410 State state = next_state_; 410 State state = next_state_;
411 next_state_ = STATE_NONE; 411 next_state_ = STATE_NONE;
412 switch (state) { 412 switch (state) {
413 case STATE_BEFORE_CONNECT:
414 DCHECK_EQ(OK, result);
415 result = DoBeforeConnect();
416 break;
417 case STATE_BEFORE_CONNECT_COMPLETE:
418 result = DoBeforeConnectComplete(result);
419 break;
413 case STATE_RESOLVE_PROXY: 420 case STATE_RESOLVE_PROXY:
414 DCHECK_EQ(OK, result); 421 DCHECK_EQ(OK, result);
415 result = DoResolveProxy(); 422 result = DoResolveProxy();
416 break; 423 break;
417 case STATE_RESOLVE_PROXY_COMPLETE: 424 case STATE_RESOLVE_PROXY_COMPLETE:
418 result = DoResolveProxyComplete(result); 425 result = DoResolveProxyComplete(result);
419 break; 426 break;
420 case STATE_RESOLVE_HOST: 427 case STATE_RESOLVE_HOST:
421 DCHECK_EQ(OK, result); 428 DCHECK_EQ(OK, result);
422 result = DoResolveHost(); 429 result = DoResolveHost();
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 continue; 511 continue;
505 // If the connection is not established yet and had actual errors, 512 // If the connection is not established yet and had actual errors,
506 // record the error. In next iteration, it will close the connection. 513 // record the error. In next iteration, it will close the connection.
507 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { 514 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) {
508 net_log_.EndEventWithNetErrorCode( 515 net_log_.EndEventWithNetErrorCode(
509 NetLog::TYPE_SOCKET_STREAM_CONNECT, result); 516 NetLog::TYPE_SOCKET_STREAM_CONNECT, result);
510 } 517 }
511 } while (result != ERR_IO_PENDING); 518 } while (result != ERR_IO_PENDING);
512 } 519 }
513 520
521 int SocketStream::DoBeforeConnect() {
522 next_state_ = STATE_BEFORE_CONNECT_COMPLETE;
523 if (!context_ || !context_->network_delegate())
524 return OK;
525
526 int result = context_->network_delegate()->NotifyBeforeSocketStreamConnect(
527 this, io_callback_);
528 if (result != OK && result != ERR_IO_PENDING)
529 next_state_ = STATE_CLOSE;
530
531 return result;
532 }
533
534 int SocketStream::DoBeforeConnectComplete(int result) {
535 DCHECK_NE(ERR_IO_PENDING, result);
536
537 if (result == OK)
538 next_state_ = STATE_RESOLVE_PROXY;
539 else
540 next_state_ = STATE_CLOSE;
541
542 return result;
543 }
544
514 int SocketStream::DoResolveProxy() { 545 int SocketStream::DoResolveProxy() {
515 DCHECK(!pac_request_); 546 DCHECK(!pac_request_);
516 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; 547 next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
517 548
518 if (!proxy_url_.is_valid()) { 549 if (!proxy_url_.is_valid()) {
519 next_state_ = STATE_CLOSE; 550 next_state_ = STATE_CLOSE;
520 return ERR_INVALID_ARGUMENT; 551 return ERR_INVALID_ARGUMENT;
521 } 552 }
522 553
523 // TODO(toyoshim): Check server advertisement of SPDY through the HTTP 554 // TODO(toyoshim): Check server advertisement of SPDY through the HTTP
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 1287
1257 SSLConfigService* SocketStream::ssl_config_service() const { 1288 SSLConfigService* SocketStream::ssl_config_service() const {
1258 return context_->ssl_config_service(); 1289 return context_->ssl_config_service();
1259 } 1290 }
1260 1291
1261 ProxyService* SocketStream::proxy_service() const { 1292 ProxyService* SocketStream::proxy_service() const {
1262 return context_->proxy_service(); 1293 return context_->proxy_service();
1263 } 1294 }
1264 1295
1265 } // namespace net 1296 } // namespace net
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream.h ('k') | net/socket_stream/socket_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698