| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 UserDataMap::const_iterator found = user_data_.find(key); | 89 UserDataMap::const_iterator found = user_data_.find(key); |
| 90 if (found != user_data_.end()) | 90 if (found != user_data_.end()) |
| 91 return found->second.get(); | 91 return found->second.get(); |
| 92 return NULL; | 92 return NULL; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SocketStream::SetUserData(const void* key, UserData* data) { | 95 void SocketStream::SetUserData(const void* key, UserData* data) { |
| 96 user_data_[key] = linked_ptr<UserData>(data); | 96 user_data_[key] = linked_ptr<UserData>(data); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void SocketStream::set_context(net::URLRequestContext* context) { | 99 void SocketStream::set_context(URLRequestContext* context) { |
| 100 scoped_refptr<net::URLRequestContext> prev_context = context_; | 100 scoped_refptr<URLRequestContext> prev_context = context_; |
| 101 | 101 |
| 102 context_ = context; | 102 context_ = context; |
| 103 | 103 |
| 104 if (prev_context != context) { | 104 if (prev_context != context) { |
| 105 if (prev_context && pac_request_) { | 105 if (prev_context && pac_request_) { |
| 106 prev_context->proxy_service()->CancelPacRequest(pac_request_); | 106 prev_context->proxy_service()->CancelPacRequest(pac_request_); |
| 107 pac_request_ = NULL; | 107 pac_request_ = NULL; |
| 108 } | 108 } |
| 109 | 109 |
| 110 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); | 110 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 void SocketStream::Finish(int result) { | 258 void SocketStream::Finish(int result) { |
| 259 DCHECK(MessageLoop::current()) << | 259 DCHECK(MessageLoop::current()) << |
| 260 "The current MessageLoop must exist"; | 260 "The current MessageLoop must exist"; |
| 261 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 261 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| 262 "The current MessageLoop must be TYPE_IO"; | 262 "The current MessageLoop must be TYPE_IO"; |
| 263 DCHECK_LE(result, OK); | 263 DCHECK_LE(result, OK); |
| 264 if (result == OK) | 264 if (result == OK) |
| 265 result = ERR_CONNECTION_CLOSED; | 265 result = ERR_CONNECTION_CLOSED; |
| 266 DCHECK_EQ(next_state_, STATE_NONE); | 266 DCHECK_EQ(next_state_, STATE_NONE); |
| 267 DVLOG(1) << "Finish result=" << net::ErrorToString(result); | 267 DVLOG(1) << "Finish result=" << ErrorToString(result); |
| 268 if (delegate_) | 268 if (delegate_) |
| 269 delegate_->OnError(this, result); | 269 delegate_->OnError(this, result); |
| 270 | 270 |
| 271 metrics_->OnClose(); | 271 metrics_->OnClose(); |
| 272 Delegate* delegate = delegate_; | 272 Delegate* delegate = delegate_; |
| 273 delegate_ = NULL; | 273 delegate_ = NULL; |
| 274 if (delegate) { | 274 if (delegate) { |
| 275 delegate->OnClose(this); | 275 delegate->OnClose(this); |
| 276 } | 276 } |
| 277 Release(); | 277 Release(); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 DCHECK(host_resolver_); | 528 DCHECK(host_resolver_); |
| 529 resolver_.reset(new SingleRequestHostResolver(host_resolver_)); | 529 resolver_.reset(new SingleRequestHostResolver(host_resolver_)); |
| 530 return resolver_->Resolve(resolve_info, &addresses_, &io_callback_, | 530 return resolver_->Resolve(resolve_info, &addresses_, &io_callback_, |
| 531 net_log_); | 531 net_log_); |
| 532 } | 532 } |
| 533 | 533 |
| 534 int SocketStream::DoResolveHostComplete(int result) { | 534 int SocketStream::DoResolveHostComplete(int result) { |
| 535 if (result == OK && delegate_) { | 535 if (result == OK && delegate_) { |
| 536 next_state_ = STATE_TCP_CONNECT; | 536 next_state_ = STATE_TCP_CONNECT; |
| 537 result = delegate_->OnStartOpenConnection(this, &io_callback_); | 537 result = delegate_->OnStartOpenConnection(this, &io_callback_); |
| 538 if (result == net::ERR_IO_PENDING) | 538 if (result == ERR_IO_PENDING) |
| 539 metrics_->OnWaitConnection(); | 539 metrics_->OnWaitConnection(); |
| 540 } else { | 540 } else { |
| 541 next_state_ = STATE_CLOSE; | 541 next_state_ = STATE_CLOSE; |
| 542 } | 542 } |
| 543 // TODO(ukai): if error occured, reconsider proxy after error. | 543 // TODO(ukai): if error occured, reconsider proxy after error. |
| 544 return result; | 544 return result; |
| 545 } | 545 } |
| 546 | 546 |
| 547 int SocketStream::DoTcpConnect(int result) { | 547 int SocketStream::DoTcpConnect(int result) { |
| 548 if (result != OK) { | 548 if (result != OK) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 } else { | 979 } else { |
| 980 auth_identity_.invalid = false; | 980 auth_identity_.invalid = false; |
| 981 } | 981 } |
| 982 return ERR_TUNNEL_CONNECTION_FAILED; | 982 return ERR_TUNNEL_CONNECTION_FAILED; |
| 983 } | 983 } |
| 984 | 984 |
| 985 void SocketStream::DoAuthRequired() { | 985 void SocketStream::DoAuthRequired() { |
| 986 if (delegate_ && auth_info_.get()) | 986 if (delegate_ && auth_info_.get()) |
| 987 delegate_->OnAuthRequired(this, auth_info_.get()); | 987 delegate_->OnAuthRequired(this, auth_info_.get()); |
| 988 else | 988 else |
| 989 DoLoop(net::ERR_UNEXPECTED); | 989 DoLoop(ERR_UNEXPECTED); |
| 990 } | 990 } |
| 991 | 991 |
| 992 void SocketStream::DoRestartWithAuth() { | 992 void SocketStream::DoRestartWithAuth() { |
| 993 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); | 993 DCHECK_EQ(next_state_, STATE_AUTH_REQUIRED); |
| 994 auth_cache_.Add(ProxyAuthOrigin(), | 994 auth_cache_.Add(ProxyAuthOrigin(), |
| 995 auth_handler_->realm(), | 995 auth_handler_->realm(), |
| 996 auth_handler_->auth_scheme(), | 996 auth_handler_->auth_scheme(), |
| 997 auth_handler_->challenge(), | 997 auth_handler_->challenge(), |
| 998 auth_identity_.username, | 998 auth_identity_.username, |
| 999 auth_identity_.password, | 999 auth_identity_.password, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1029 | 1029 |
| 1030 SSLConfigService* SocketStream::ssl_config_service() const { | 1030 SSLConfigService* SocketStream::ssl_config_service() const { |
| 1031 return context_->ssl_config_service(); | 1031 return context_->ssl_config_service(); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 ProxyService* SocketStream::proxy_service() const { | 1034 ProxyService* SocketStream::proxy_service() const { |
| 1035 return context_->proxy_service(); | 1035 return context_->proxy_service(); |
| 1036 } | 1036 } |
| 1037 | 1037 |
| 1038 } // namespace net | 1038 } // namespace net |
| OLD | NEW |