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

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

Issue 347026: Refactor SocketStream to report error to the delegate. (Closed)
Patch Set: add STATE_CLOSE Created 11 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
« no previous file with comments | « net/socket_stream/socket_stream.h ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 10 #include <string>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void SocketStream::set_context(URLRequestContext* context) { 82 void SocketStream::set_context(URLRequestContext* context) {
83 context_ = context; 83 context_ = context;
84 } 84 }
85 85
86 void SocketStream::Connect() { 86 void SocketStream::Connect() {
87 DCHECK(MessageLoop::current()) << 87 DCHECK(MessageLoop::current()) <<
88 "The current MessageLoop must exist"; 88 "The current MessageLoop must exist";
89 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 89 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
90 "The current MessageLoop must be TYPE_IO"; 90 "The current MessageLoop must be TYPE_IO";
91 ssl_config_service()->GetSSLConfig(&ssl_config_); 91 ssl_config_service()->GetSSLConfig(&ssl_config_);
92 DCHECK_EQ(next_state_, STATE_NONE);
92 93
93 AddRef(); // Released in Finish() 94 AddRef(); // Released in Finish()
94 // Open a connection asynchronously, so that delegate won't be called 95 // Open a connection asynchronously, so that delegate won't be called
95 // back before returning Connect(). 96 // back before returning Connect().
96 next_state_ = STATE_RESOLVE_PROXY; 97 next_state_ = STATE_RESOLVE_PROXY;
97 MessageLoop::current()->PostTask( 98 MessageLoop::current()->PostTask(
98 FROM_HERE, 99 FROM_HERE,
99 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); 100 NewRunnableMethod(this, &SocketStream::DoLoop, OK));
100 } 101 }
101 102
102 bool SocketStream::SendData(const char* data, int len) { 103 bool SocketStream::SendData(const char* data, int len) {
103 DCHECK(MessageLoop::current()) << 104 DCHECK(MessageLoop::current()) <<
104 "The current MessageLoop must exist"; 105 "The current MessageLoop must exist";
105 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 106 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
106 "The current MessageLoop must be TYPE_IO"; 107 "The current MessageLoop must be TYPE_IO";
107 if (!socket_.get() || !socket_->IsConnected()) 108 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE)
108 return false; 109 return false;
109 if (write_buf_) { 110 if (write_buf_) {
110 int current_amount_send = write_buf_size_ - write_buf_offset_; 111 int current_amount_send = write_buf_size_ - write_buf_offset_;
111 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin(); 112 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin();
112 iter != pending_write_bufs_.end(); 113 iter != pending_write_bufs_.end();
113 ++iter) 114 ++iter)
114 current_amount_send += (*iter)->size(); 115 current_amount_send += (*iter)->size();
115 116
116 current_amount_send += len; 117 current_amount_send += len;
117 if (current_amount_send > max_pending_send_allowed_) 118 if (current_amount_send > max_pending_send_allowed_)
(...skipping 14 matching lines...) Expand all
132 FROM_HERE, 133 FROM_HERE,
133 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); 134 NewRunnableMethod(this, &SocketStream::DoLoop, OK));
134 return true; 135 return true;
135 } 136 }
136 137
137 void SocketStream::Close() { 138 void SocketStream::Close() {
138 DCHECK(MessageLoop::current()) << 139 DCHECK(MessageLoop::current()) <<
139 "The current MessageLoop must exist"; 140 "The current MessageLoop must exist";
140 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 141 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
141 "The current MessageLoop must be TYPE_IO"; 142 "The current MessageLoop must be TYPE_IO";
142 if (!socket_.get()) 143 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE)
143 return; 144 return;
144 if (socket_->IsConnected()) 145 socket_->Disconnect();
145 socket_->Disconnect(); 146 next_state_ = STATE_CLOSE;
146 // Close asynchronously, so that delegate won't be called 147 // Close asynchronously, so that delegate won't be called
147 // back before returning Close(). 148 // back before returning Close().
148 MessageLoop::current()->PostTask( 149 MessageLoop::current()->PostTask(
149 FROM_HERE, 150 FROM_HERE,
150 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); 151 NewRunnableMethod(this, &SocketStream::DoLoop, OK));
151 } 152 }
152 153
153 void SocketStream::RestartWithAuth( 154 void SocketStream::RestartWithAuth(
154 const std::wstring& username, const std::wstring& password) { 155 const std::wstring& username, const std::wstring& password) {
155 DCHECK(MessageLoop::current()) << 156 DCHECK(MessageLoop::current()) <<
(...skipping 19 matching lines...) Expand all
175 NewRunnableMethod(this, &SocketStream::DoRestartWithAuth)); 176 NewRunnableMethod(this, &SocketStream::DoRestartWithAuth));
176 } 177 }
177 178
178 void SocketStream::DetachDelegate() { 179 void SocketStream::DetachDelegate() {
179 if (!delegate_) 180 if (!delegate_)
180 return; 181 return;
181 delegate_ = NULL; 182 delegate_ = NULL;
182 Close(); 183 Close();
183 } 184 }
184 185
185 void SocketStream::Finish() { 186 void SocketStream::Finish(int result) {
186 DCHECK(MessageLoop::current()) << 187 DCHECK(MessageLoop::current()) <<
187 "The current MessageLoop must exist"; 188 "The current MessageLoop must exist";
188 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << 189 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) <<
189 "The current MessageLoop must be TYPE_IO"; 190 "The current MessageLoop must be TYPE_IO";
191 DCHECK_LT(result, 0);
192 DCHECK_EQ(next_state_, STATE_NONE);
190 DLOG(INFO) << "Finish"; 193 DLOG(INFO) << "Finish";
194 if (delegate_)
195 delegate_->OnError(this, result);
196
191 Delegate* delegate = delegate_; 197 Delegate* delegate = delegate_;
192 delegate_ = NULL; 198 delegate_ = NULL;
193 if (delegate) { 199 if (delegate) {
194 delegate->OnClose(this); 200 delegate->OnClose(this);
195 Release();
196 } 201 }
202 Release();
197 } 203 }
198 204
199 void SocketStream::SetHostResolver(HostResolver* host_resolver) { 205 void SocketStream::SetHostResolver(HostResolver* host_resolver) {
200 DCHECK(host_resolver); 206 DCHECK(host_resolver);
201 host_resolver_ = host_resolver; 207 host_resolver_ = host_resolver;
202 } 208 }
203 209
204 void SocketStream::SetClientSocketFactory( 210 void SocketStream::SetClientSocketFactory(
205 ClientSocketFactory* factory) { 211 ClientSocketFactory* factory) {
206 DCHECK(factory); 212 DCHECK(factory);
207 factory_ = factory; 213 factory_ = factory;
208 } 214 }
209 215
210 void SocketStream::DidEstablishConnection() { 216 int SocketStream::DidEstablishConnection() {
211 if (!socket_.get() || !socket_->IsConnected()) { 217 if (!socket_.get() || !socket_->IsConnected()) {
212 Finish(); 218 return ERR_CONNECTION_FAILED;
213 return;
214 } 219 }
215 next_state_ = STATE_READ_WRITE; 220 next_state_ = STATE_READ_WRITE;
216 221
217 if (delegate_) 222 if (delegate_)
218 delegate_->OnConnected(this, max_pending_send_allowed_); 223 delegate_->OnConnected(this, max_pending_send_allowed_);
219 224
220 return; 225 return OK;
221 } 226 }
222 227
223 void SocketStream::DidReceiveData(int result) { 228 void SocketStream::DidReceiveData(int result) {
224 DCHECK(read_buf_); 229 DCHECK(read_buf_);
225 DCHECK_GT(result, 0); 230 DCHECK_GT(result, 0);
226 if (!delegate_) 231 if (!delegate_)
227 return; 232 return;
228 // Notify recevied data to delegate. 233 // Notify recevied data to delegate.
229 delegate_->OnReceivedData(this, read_buf_->data(), result); 234 delegate_->OnReceivedData(this, read_buf_->data(), result);
230 read_buf_ = NULL; 235 read_buf_ = NULL;
(...skipping 17 matching lines...) Expand all
248 write_buf_ = NULL; 253 write_buf_ = NULL;
249 } 254 }
250 write_buf_offset_ = 0; 255 write_buf_offset_ = 0;
251 } else { 256 } else {
252 write_buf_offset_ += result; 257 write_buf_offset_ += result;
253 } 258 }
254 } 259 }
255 260
256 void SocketStream::OnIOCompleted(int result) { 261 void SocketStream::OnIOCompleted(int result) {
257 DoLoop(result); 262 DoLoop(result);
258 // TODO(ukai): notify error.
259 } 263 }
260 264
261 void SocketStream::OnReadCompleted(int result) { 265 void SocketStream::OnReadCompleted(int result) {
262 // TODO(ukai): notify error.
263 if (result == 0) { 266 if (result == 0) {
264 // 0 indicates end-of-file, so socket was closed. 267 // 0 indicates end-of-file, so socket was closed.
265 next_state_ = STATE_NONE; 268 next_state_ = STATE_CLOSE;
266 } else if (result > 0 && read_buf_) { 269 } else if (result > 0 && read_buf_) {
267 DidReceiveData(result); 270 DidReceiveData(result);
268 result = OK; 271 result = OK;
269 } 272 }
270 DoLoop(result); 273 DoLoop(result);
271 } 274 }
272 275
273 void SocketStream::OnWriteCompleted(int result) { 276 void SocketStream::OnWriteCompleted(int result) {
274 // TODO(ukai): notify error.
275 if (result >= 0 && write_buf_) { 277 if (result >= 0 && write_buf_) {
276 DidSendData(result); 278 DidSendData(result);
277 result = OK; 279 result = OK;
278 } 280 }
279 DoLoop(result); 281 DoLoop(result);
280 } 282 }
281 283
282 int SocketStream::DoLoop(int result) { 284 void SocketStream::DoLoop(int result) {
283 if (next_state_ == STATE_NONE) { 285 if (next_state_ == STATE_NONE)
284 Finish(); 286 return;
285 return ERR_CONNECTION_CLOSED;
286 }
287 287
288 do { 288 do {
289 State state = next_state_; 289 State state = next_state_;
290 next_state_ = STATE_NONE; 290 next_state_ = STATE_NONE;
291 switch (state) { 291 switch (state) {
292 case STATE_RESOLVE_PROXY: 292 case STATE_RESOLVE_PROXY:
293 DCHECK_EQ(OK, result); 293 DCHECK_EQ(OK, result);
294 result = DoResolveProxy(); 294 result = DoResolveProxy();
295 break; 295 break;
296 case STATE_RESOLVE_PROXY_COMPLETE: 296 case STATE_RESOLVE_PROXY_COMPLETE:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 case STATE_SSL_CONNECT: 334 case STATE_SSL_CONNECT:
335 DCHECK_EQ(OK, result); 335 DCHECK_EQ(OK, result);
336 result = DoSSLConnect(); 336 result = DoSSLConnect();
337 break; 337 break;
338 case STATE_SSL_CONNECT_COMPLETE: 338 case STATE_SSL_CONNECT_COMPLETE:
339 result = DoSSLConnectComplete(result); 339 result = DoSSLConnectComplete(result);
340 break; 340 break;
341 case STATE_READ_WRITE: 341 case STATE_READ_WRITE:
342 result = DoReadWrite(result); 342 result = DoReadWrite(result);
343 break; 343 break;
344 case STATE_CLOSE:
345 DCHECK_LE(result, OK);
346 if (result == OK)
347 result = ERR_CONNECTION_CLOSED;
348 Finish(result);
349 return;
344 default: 350 default:
345 NOTREACHED() << "bad state"; 351 NOTREACHED() << "bad state";
346 result = ERR_UNEXPECTED; 352 result = ERR_UNEXPECTED;
347 break; 353 break;
348 } 354 }
349 } while (result != ERR_IO_PENDING && next_state_ != STATE_NONE); 355 } while (result != ERR_IO_PENDING);
350
351 if (result != ERR_IO_PENDING)
352 Finish();
353
354 return result;
355 } 356 }
356 357
357 int SocketStream::DoResolveProxy() { 358 int SocketStream::DoResolveProxy() {
358 DCHECK(!pac_request_); 359 DCHECK(!pac_request_);
359 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; 360 next_state_ = STATE_RESOLVE_PROXY_COMPLETE;
360 361
361 return proxy_service()->ResolveProxy( 362 return proxy_service()->ResolveProxy(
362 url_, &proxy_info_, &io_callback_, &pac_request_, NULL); 363 url_, &proxy_info_, &io_callback_, &pac_request_, NULL);
363 } 364 }
364 365
365 int SocketStream::DoResolveProxyComplete(int result) { 366 int SocketStream::DoResolveProxyComplete(int result) {
366 next_state_ = STATE_RESOLVE_HOST; 367 next_state_ = STATE_RESOLVE_HOST;
367 368
368 pac_request_ = NULL; 369 pac_request_ = NULL;
369 if (result != OK) { 370 if (result != OK) {
370 LOG(ERROR) << "Failed to resolve proxy: " << result; 371 LOG(ERROR) << "Failed to resolve proxy: " << result;
372 if (delegate_)
373 delegate_->OnError(this, result);
371 proxy_info_.UseDirect(); 374 proxy_info_.UseDirect();
372 } 375 }
373 376
374 return OK; 377 return OK;
375 } 378 }
376 379
377 int SocketStream::DoResolveHost() { 380 int SocketStream::DoResolveHost() {
378 next_state_ = STATE_RESOLVE_HOST_COMPLETE; 381 next_state_ = STATE_RESOLVE_HOST_COMPLETE;
379 382
380 if (proxy_info_.is_direct()) 383 if (proxy_info_.is_direct())
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 if (result != OK) 424 if (result != OK)
422 return result; 425 return result;
423 426
424 if (proxy_mode_ == kTunnelProxy) 427 if (proxy_mode_ == kTunnelProxy)
425 next_state_ = STATE_WRITE_TUNNEL_HEADERS; 428 next_state_ = STATE_WRITE_TUNNEL_HEADERS;
426 else if (proxy_mode_ == kSOCKSProxy) 429 else if (proxy_mode_ == kSOCKSProxy)
427 next_state_ = STATE_SOCKS_CONNECT; 430 next_state_ = STATE_SOCKS_CONNECT;
428 else if (is_secure()) { 431 else if (is_secure()) {
429 next_state_ = STATE_SSL_CONNECT; 432 next_state_ = STATE_SSL_CONNECT;
430 } else { 433 } else {
431 DidEstablishConnection(); 434 result = DidEstablishConnection();
432 } 435 }
433 return OK; 436 return result;
434 } 437 }
435 438
436 int SocketStream::DoWriteTunnelHeaders() { 439 int SocketStream::DoWriteTunnelHeaders() {
437 DCHECK_EQ(kTunnelProxy, proxy_mode_); 440 DCHECK_EQ(kTunnelProxy, proxy_mode_);
438 441
439 next_state_ = STATE_WRITE_TUNNEL_HEADERS_COMPLETE; 442 next_state_ = STATE_WRITE_TUNNEL_HEADERS_COMPLETE;
440 443
441 if (!tunnel_request_headers_.get()) { 444 if (!tunnel_request_headers_.get()) {
442 tunnel_request_headers_ = new RequestHeaders(); 445 tunnel_request_headers_ = new RequestHeaders();
443 tunnel_request_headers_bytes_sent_ = 0; 446 tunnel_request_headers_bytes_sent_ = 0;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 528 }
526 529
527 int SocketStream::DoReadTunnelHeadersComplete(int result) { 530 int SocketStream::DoReadTunnelHeadersComplete(int result) {
528 DCHECK_EQ(kTunnelProxy, proxy_mode_); 531 DCHECK_EQ(kTunnelProxy, proxy_mode_);
529 532
530 if (result < 0) 533 if (result < 0)
531 return result; 534 return result;
532 535
533 if (result == 0) { 536 if (result == 0) {
534 // 0 indicates end-of-file, so socket was closed. 537 // 0 indicates end-of-file, so socket was closed.
535 Finish(); 538 next_state_ = STATE_CLOSE;
536 return result; 539 return ERR_CONNECTION_CLOSED;
537 } 540 }
538 541
539 tunnel_response_headers_len_ += result; 542 tunnel_response_headers_len_ += result;
540 DCHECK(tunnel_response_headers_len_ <= tunnel_response_headers_capacity_); 543 DCHECK(tunnel_response_headers_len_ <= tunnel_response_headers_capacity_);
541 544
542 int eoh = HttpUtil::LocateEndOfHeaders( 545 int eoh = HttpUtil::LocateEndOfHeaders(
543 tunnel_response_headers_->headers(), tunnel_response_headers_len_, 0); 546 tunnel_response_headers_->headers(), tunnel_response_headers_len_, 0);
544 if (eoh == -1) { 547 if (eoh == -1) {
545 if (tunnel_response_headers_len_ >= kMaxTunnelResponseHeadersSize) 548 if (tunnel_response_headers_len_ >= kMaxTunnelResponseHeadersSize) {
549 next_state_ = STATE_CLOSE;
546 return ERR_RESPONSE_HEADERS_TOO_BIG; 550 return ERR_RESPONSE_HEADERS_TOO_BIG;
551 }
547 552
548 next_state_ = STATE_READ_TUNNEL_HEADERS; 553 next_state_ = STATE_READ_TUNNEL_HEADERS;
549 return OK; 554 return OK;
550 } 555 }
551 // DidReadResponseHeaders 556 // DidReadResponseHeaders
552 scoped_refptr<HttpResponseHeaders> headers; 557 scoped_refptr<HttpResponseHeaders> headers;
553 headers = new HttpResponseHeaders( 558 headers = new HttpResponseHeaders(
554 HttpUtil::AssembleRawHeaders(tunnel_response_headers_->headers(), eoh)); 559 HttpUtil::AssembleRawHeaders(tunnel_response_headers_->headers(), eoh));
555 if (headers->GetParsedHttpVersion() < HttpVersion(1, 0)) { 560 if (headers->GetParsedHttpVersion() < HttpVersion(1, 0)) {
556 // Require the "HTTP/1.x" status line. 561 // Require the "HTTP/1.x" status line.
562 next_state_ = STATE_CLOSE;
557 return ERR_TUNNEL_CONNECTION_FAILED; 563 return ERR_TUNNEL_CONNECTION_FAILED;
558 } 564 }
559 switch (headers->response_code()) { 565 switch (headers->response_code()) {
560 case 200: // OK 566 case 200: // OK
561 if (is_secure()) { 567 if (is_secure()) {
562 DCHECK_EQ(eoh, tunnel_response_headers_len_); 568 DCHECK_EQ(eoh, tunnel_response_headers_len_);
563 next_state_ = STATE_SSL_CONNECT; 569 next_state_ = STATE_SSL_CONNECT;
564 } else { 570 } else {
565 DidEstablishConnection(); 571 result = DidEstablishConnection();
572 if (result < 0) {
573 next_state_ = STATE_CLOSE;
574 return result;
575 }
566 if ((eoh < tunnel_response_headers_len_) && delegate_) 576 if ((eoh < tunnel_response_headers_len_) && delegate_)
567 delegate_->OnReceivedData( 577 delegate_->OnReceivedData(
568 this, tunnel_response_headers_->headers() + eoh, 578 this, tunnel_response_headers_->headers() + eoh,
569 tunnel_response_headers_len_ - eoh); 579 tunnel_response_headers_len_ - eoh);
570 } 580 }
571 return OK; 581 return OK;
572 case 407: // Proxy Authentication Required. 582 case 407: // Proxy Authentication Required.
573 result = HandleAuthChallenge(headers.get()); 583 result = HandleAuthChallenge(headers.get());
574 if (result == ERR_PROXY_AUTH_REQUESTED && 584 if (result == ERR_PROXY_AUTH_REQUESTED &&
575 auth_handler_.get() && delegate_) { 585 auth_handler_.get() && delegate_) {
576 auth_info_ = new AuthChallengeInfo; 586 auth_info_ = new AuthChallengeInfo;
577 auth_info_->is_proxy = true; 587 auth_info_->is_proxy = true;
578 auth_info_->host_and_port = 588 auth_info_->host_and_port =
579 ASCIIToWide(proxy_info_.proxy_server().host_and_port()); 589 ASCIIToWide(proxy_info_.proxy_server().host_and_port());
580 auth_info_->scheme = ASCIIToWide(auth_handler_->scheme()); 590 auth_info_->scheme = ASCIIToWide(auth_handler_->scheme());
581 auth_info_->realm = ASCIIToWide(auth_handler_->realm()); 591 auth_info_->realm = ASCIIToWide(auth_handler_->realm());
582 // Wait until RestartWithAuth or Close is called. 592 // Wait until RestartWithAuth or Close is called.
583 MessageLoop::current()->PostTask( 593 MessageLoop::current()->PostTask(
584 FROM_HERE, 594 FROM_HERE,
585 NewRunnableMethod(this, &SocketStream::DoAuthRequired)); 595 NewRunnableMethod(this, &SocketStream::DoAuthRequired));
596 next_state_ = STATE_AUTH_REQUIRED;
586 return ERR_IO_PENDING; 597 return ERR_IO_PENDING;
587 } 598 }
588 default: 599 default:
589 break; 600 break;
590 } 601 }
591 return ERR_TUNNEL_CONNECTION_FAILED; 602 return ERR_TUNNEL_CONNECTION_FAILED;
592 } 603 }
593 604
594 int SocketStream::DoSOCKSConnect() { 605 int SocketStream::DoSOCKSConnect() {
595 DCHECK_EQ(kSOCKSProxy, proxy_mode_); 606 DCHECK_EQ(kSOCKSProxy, proxy_mode_);
(...skipping 30 matching lines...) Expand all
626 socket_.release(), url_.HostNoBrackets(), ssl_config_)); 637 socket_.release(), url_.HostNoBrackets(), ssl_config_));
627 next_state_ = STATE_SSL_CONNECT_COMPLETE; 638 next_state_ = STATE_SSL_CONNECT_COMPLETE;
628 return socket_->Connect(&io_callback_); 639 return socket_->Connect(&io_callback_);
629 } 640 }
630 641
631 int SocketStream::DoSSLConnectComplete(int result) { 642 int SocketStream::DoSSLConnectComplete(int result) {
632 if (IsCertificateError(result)) 643 if (IsCertificateError(result))
633 result = HandleCertificateError(result); 644 result = HandleCertificateError(result);
634 645
635 if (result == OK) 646 if (result == OK)
636 DidEstablishConnection(); 647 result = DidEstablishConnection();
637 return result; 648 return result;
638 } 649 }
639 650
640 int SocketStream::DoReadWrite(int result) { 651 int SocketStream::DoReadWrite(int result) {
641 if (result < OK) { 652 if (result < OK) {
642 Finish();
643 return result; 653 return result;
644 } 654 }
645 if (!socket_.get() || !socket_->IsConnected()) { 655 if (!socket_.get() || !socket_->IsConnected()) {
646 Finish();
647 return ERR_CONNECTION_CLOSED; 656 return ERR_CONNECTION_CLOSED;
648 } 657 }
649 658
650 next_state_ = STATE_READ_WRITE; 659 next_state_ = STATE_READ_WRITE;
651 660
652 if (!read_buf_) { 661 if (!read_buf_) {
653 // No read pending. 662 // No read pending.
654 read_buf_ = new IOBuffer(kReadBufferSize); 663 read_buf_ = new IOBuffer(kReadBufferSize);
655 result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_); 664 result = socket_->Read(read_buf_, kReadBufferSize, &read_callback_);
656 if (result > 0) { 665 if (result > 0) {
657 DidReceiveData(result); 666 DidReceiveData(result);
658 return OK; 667 return OK;
659 } else if (result == 0) { 668 } else if (result == 0) {
660 // 0 indicates end-of-file, so socket was closed. 669 // 0 indicates end-of-file, so socket was closed.
661 Finish();
662 return ERR_CONNECTION_CLOSED; 670 return ERR_CONNECTION_CLOSED;
663 } 671 }
664 // If read is pending, try write as well. 672 // If read is pending, try write as well.
665 // Otherwise, return the result and do next loop. 673 // Otherwise, return the result and do next loop.
666 if (result != ERR_IO_PENDING) 674 if (result != ERR_IO_PENDING)
667 return result; 675 return result;
668 } 676 }
669 // Read is pending. 677 // Read is pending.
670 DCHECK(read_buf_); 678 DCHECK(read_buf_);
671 679
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 747 }
740 748
741 void SocketStream::DoAuthRequired() { 749 void SocketStream::DoAuthRequired() {
742 if (delegate_ && auth_info_.get()) 750 if (delegate_ && auth_info_.get())
743 delegate_->OnAuthRequired(this, auth_info_.get()); 751 delegate_->OnAuthRequired(this, auth_info_.get());
744 else 752 else
745 DoLoop(net::ERR_UNEXPECTED); 753 DoLoop(net::ERR_UNEXPECTED);
746 } 754 }
747 755
748 void SocketStream::DoRestartWithAuth() { 756 void SocketStream::DoRestartWithAuth() {
757 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED);
749 auth_cache_.Add(ProxyAuthOrigin(), auth_handler_, 758 auth_cache_.Add(ProxyAuthOrigin(), auth_handler_,
750 auth_identity_.username, auth_identity_.password, 759 auth_identity_.username, auth_identity_.password,
751 std::string()); 760 std::string());
752 761
753 tunnel_request_headers_ = NULL; 762 tunnel_request_headers_ = NULL;
754 tunnel_request_headers_bytes_sent_ = 0; 763 tunnel_request_headers_bytes_sent_ = 0;
755 tunnel_response_headers_ = NULL; 764 tunnel_response_headers_ = NULL;
756 tunnel_response_headers_capacity_ = 0; 765 tunnel_response_headers_capacity_ = 0;
757 tunnel_response_headers_len_ = 0; 766 tunnel_response_headers_len_ = 0;
758 767
(...skipping 21 matching lines...) Expand all
780 789
781 SSLConfigService* SocketStream::ssl_config_service() const { 790 SSLConfigService* SocketStream::ssl_config_service() const {
782 return context_->ssl_config_service(); 791 return context_->ssl_config_service();
783 } 792 }
784 793
785 ProxyService* SocketStream::proxy_service() const { 794 ProxyService* SocketStream::proxy_service() const {
786 return context_->proxy_service(); 795 return context_->proxy_service();
787 } 796 }
788 797
789 } // namespace net 798 } // namespace net
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698