#include "base/strings/utf_string_conversions.h"
#include "net/base/auth.h"
#include "net/base/io_buffer.h"
+#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/dns/host_resolver.h"
SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; }
-SocketStream::SocketStream(const GURL& url, Delegate* delegate)
+SocketStream::SocketStream(const GURL& url, Delegate* delegate,
+ URLRequestContext* context,
+ CookieStore* cookie_store)
: delegate_(delegate),
url_(url),
max_pending_send_allowed_(kMaxPendingSendAllowed),
- context_(NULL),
+ context_(context),
next_state_(STATE_NONE),
factory_(ClientSocketFactory::GetDefaultFactory()),
proxy_mode_(kDirectConnection),
proxy_url_(url),
pac_request_(NULL),
connection_(new ClientSocketHandle),
- privacy_mode_(kPrivacyModeDisabled),
+ privacy_mode_(PRIVACY_MODE_DISABLED),
// Unretained() is required; without it, Bind() creates a circular
// dependency and the SocketStream object will not be freed.
io_callback_(base::Bind(&SocketStream::OnIOCompleted,
waiting_for_write_completion_(false),
closing_(false),
server_closed_(false),
- metrics_(new SocketStreamMetrics(url)) {
+ metrics_(new SocketStreamMetrics(url)),
+ cookie_store_(cookie_store) {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
DCHECK(delegate_);
+
+ if (context_) {
+ if (!cookie_store_.get())
+ cookie_store_ = context_->cookie_store();
+
+ net_log_ = BoundNetLog::Make(
+ context->net_log(),
+ NetLog::SOURCE_SOCKET_STREAM);
+
+ net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
+ }
}
SocketStream::UserData* SocketStream::GetUserData(
return url_.SchemeIs("wss");
}
-void SocketStream::set_context(URLRequestContext* context) {
- const URLRequestContext* prev_context = context_;
-
- context_ = context;
-
- if (prev_context != context) {
- if (prev_context && pac_request_) {
- prev_context->proxy_service()->CancelPacRequest(pac_request_);
- pac_request_ = NULL;
- }
+void SocketStream::DetachContext() {
+ if (!context_)
+ return;
- net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
- net_log_ = BoundNetLog();
+ if (pac_request_) {
+ context_->proxy_service()->CancelPacRequest(pac_request_);
+ pac_request_ = NULL;
+ }
- if (context) {
- net_log_ = BoundNetLog::Make(
- context->net_log(),
- NetLog::SOURCE_SOCKET_STREAM);
+ net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE);
+ net_log_ = BoundNetLog();
- net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE);
- }
- }
+ context_ = NULL;
+ cookie_store_ = NULL;
}
void SocketStream::CheckPrivacyMode() {
if (context_ && context_->network_delegate()) {
bool enable = context_->network_delegate()->CanEnablePrivacyMode(url_,
url_);
- privacy_mode_ = enable ? kPrivacyModeEnabled : kPrivacyModeDisabled;
+ privacy_mode_ = enable ? PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED;
// Disable Channel ID if privacy mode is enabled.
if (enable)
server_ssl_config_.channel_id_enabled = false;
void SocketStream::Connect() {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
if (context_) {
context_->ssl_config_service()->GetSSLConfig(&server_ssl_config_);
bool SocketStream::SendData(const char* data, int len) {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
DCHECK_GT(len, 0);
void SocketStream::Close() {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
// If next_state_ is STATE_NONE, the socket was not opened, or already
// closed. So, return immediately.
void SocketStream::RestartWithAuth(const AuthCredentials& credentials) {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
DCHECK(proxy_auth_controller_.get());
if (!connection_->socket()) {
}
SocketStream::~SocketStream() {
- set_context(NULL);
+ DetachContext();
DCHECK(!delegate_);
DCHECK(!pac_request_);
}
void SocketStream::DoClose() {
closing_ = true;
- // If next_state_ is STATE_TCP_CONNECT, it's waiting other socket
- // establishing connection. If next_state_ is STATE_AUTH_REQUIRED, it's
- // waiting for restarting. In these states, we'll close the SocketStream
- // now.
- if (next_state_ == STATE_TCP_CONNECT || next_state_ == STATE_AUTH_REQUIRED) {
+ // If next_state_ is:
+ // - STATE_TCP_CONNECT_COMPLETE, it's waiting other socket establishing
+ // connection.
+ // - STATE_AUTH_REQUIRED, it's waiting for restarting.
+ // - STATE_RESOLVE_PROTOCOL_COMPLETE, it's waiting for delegate_ to finish
+ // OnStartOpenConnection method call
+ // In these states, we'll close the SocketStream now.
+ if (next_state_ == STATE_TCP_CONNECT_COMPLETE ||
+ next_state_ == STATE_AUTH_REQUIRED ||
+ next_state_ == STATE_RESOLVE_PROTOCOL_COMPLETE) {
DoLoop(ERR_ABORTED);
return;
}
void SocketStream::Finish(int result) {
DCHECK(base::MessageLoop::current())
<< "The current base::MessageLoop must exist";
- DCHECK_EQ(base::MessageLoop::TYPE_IO, base::MessageLoop::current()->type())
+ DCHECK(base::MessageLoopForIO::IsCurrent())
<< "The current base::MessageLoop must be TYPE_IO";
DCHECK_LE(result, OK);
if (result == OK)
// Alternate-Protocol header here for ws:// or TLS NPN extension for wss:// .
return context_->proxy_service()->ResolveProxy(
- proxy_url_, &proxy_info_, io_callback_, &pac_request_, net_log_);
+ proxy_url_, net::LOAD_NORMAL, &proxy_info_, io_callback_, &pac_request_,
+ NULL, net_log_);
}
int SocketStream::DoResolveProxyComplete(int result) {
SSLClientSocketContext ssl_context;
ssl_context.cert_verifier = context_->cert_verifier();
ssl_context.transport_security_state = context_->transport_security_state();
- ssl_context.server_bound_cert_service = context_->server_bound_cert_service();
+ ssl_context.channel_id_service = context_->channel_id_service();
scoped_ptr<StreamSocket> socket(factory_->CreateSSLClientSocket(
connection_.Pass(),
proxy_info_.proxy_server().host_port_pair(),
SSLClientSocketContext ssl_context;
ssl_context.cert_verifier = context_->cert_verifier();
ssl_context.transport_security_state = context_->transport_security_state();
- ssl_context.server_bound_cert_service = context_->server_bound_cert_service();
+ ssl_context.channel_id_service = context_->channel_id_service();
scoped_ptr<StreamSocket> socket(
factory_->CreateSSLClientSocket(connection_.Pass(),
HostPortPair::FromURL(url_),
SSLInfo ssl_info;
ssl_socket->GetSSLInfo(&ssl_info);
- TransportSecurityState::DomainState domain_state;
- const bool fatal = context_->transport_security_state() &&
- context_->transport_security_state()->GetDomainState(url_.host(),
- SSLConfigService::IsSNIAvailable(context_->ssl_config_service()),
- &domain_state) &&
- domain_state.ShouldSSLErrorsBeFatal();
+ TransportSecurityState* state = context_->transport_security_state();
+ const bool fatal = state && state->ShouldSSLErrorsBeFatal(url_.host());
delegate_->OnSSLCertificateError(this, ssl_info, fatal);
return ERR_IO_PENDING;
}
+CookieStore* SocketStream::cookie_store() const {
+ return cookie_store_.get();
+}
+
} // namespace net