diff options
author | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-26 23:44:16 +0000 |
---|---|---|
committer | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-26 23:44:16 +0000 |
commit | 490e38f45013f65061db7380c99219995c246914 (patch) | |
tree | a544ce2b7c8762b23cfd46562ad73de3a7effb5d /net/websockets | |
parent | 1d930a61f966c184b365341cee6b9d30bd637080 (diff) | |
download | chromium_src-490e38f45013f65061db7380c99219995c246914.zip chromium_src-490e38f45013f65061db7380c99219995c246914.tar.gz chromium_src-490e38f45013f65061db7380c99219995c246914.tar.bz2 |
Move work done in CreateAndConnectStreamWithCreateHelper into StreamRequestImpl's ctor
BUG=none
Review URL: https://codereview.chromium.org/291343004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r-- | net/websockets/websocket_stream.cc | 84 |
1 files changed, 38 insertions, 46 deletions
diff --git a/net/websockets/websocket_stream.cc b/net/websockets/websocket_stream.cc index 8766316..546e01b 100644 --- a/net/websockets/websocket_stream.cc +++ b/net/websockets/websocket_stream.cc @@ -67,18 +67,37 @@ class StreamRequestImpl : public WebSocketStreamRequest { StreamRequestImpl( const GURL& url, const URLRequestContext* context, + const url::Origin& origin, scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate, - WebSocketHandshakeStreamCreateHelper* create_helper) + scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper) : delegate_(new Delegate(this)), url_request_(url, DEFAULT_PRIORITY, delegate_.get(), context), connect_delegate_(connect_delegate.Pass()), - create_helper_(create_helper) {} + create_helper_(create_helper.release()) { + HttpRequestHeaders headers; + headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); + headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); + headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string()); + headers.SetHeader(websockets::kSecWebSocketVersion, + websockets::kSupportedVersion); + url_request_.SetExtraRequestHeaders(headers); + + // This passes the ownership of |create_helper_| to |url_request_|. + url_request_.SetUserData( + WebSocketHandshakeStreamBase::CreateHelper::DataKey(), + create_helper_); + url_request_.SetLoadFlags(LOAD_DISABLE_CACHE | + LOAD_BYPASS_CACHE | + LOAD_DO_NOT_PROMPT_FOR_LOGIN); + } // Destroying this object destroys the URLRequest, which cancels the request // and so terminates the handshake if it is incomplete. virtual ~StreamRequestImpl() {} - URLRequest* url_request() { return &url_request_; } + void Start() { + url_request_.Start(); + } void PerformUpgrade() { connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); @@ -158,37 +177,6 @@ void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { NOTREACHED(); } -// Internal implementation of CreateAndConnectStream and -// CreateAndConnectStreamForTesting. -scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( - const GURL& socket_url, - scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, - const url::Origin& origin, - URLRequestContext* url_request_context, - const BoundNetLog& net_log, - scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { - scoped_ptr<StreamRequestImpl> request( - new StreamRequestImpl(socket_url, - url_request_context, - connect_delegate.Pass(), - create_helper.get())); - HttpRequestHeaders headers; - headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); - headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); - headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string()); - headers.SetHeader(websockets::kSecWebSocketVersion, - websockets::kSupportedVersion); - request->url_request()->SetExtraRequestHeaders(headers); - request->url_request()->SetUserData( - WebSocketHandshakeStreamBase::CreateHelper::DataKey(), - create_helper.release()); - request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | - LOAD_BYPASS_CACHE | - LOAD_DO_NOT_PROMPT_FOR_LOGIN); - request->url_request()->Start(); - return request.PassAs<WebSocketStreamRequest>(); -} - } // namespace WebSocketStreamRequest::~WebSocketStreamRequest() {} @@ -208,12 +196,14 @@ scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), requested_subprotocols)); - return CreateAndConnectStreamWithCreateHelper(socket_url, - create_helper.Pass(), - origin, - url_request_context, - net_log, - connect_delegate.Pass()); + scoped_ptr<StreamRequestImpl> request( + new StreamRequestImpl(socket_url, + url_request_context, + origin, + connect_delegate.Pass(), + create_helper.Pass())); + request->Start(); + return request.PassAs<WebSocketStreamRequest>(); } // This is declared in websocket_test_util.h. @@ -224,12 +214,14 @@ scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( URLRequestContext* url_request_context, const BoundNetLog& net_log, scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { - return CreateAndConnectStreamWithCreateHelper(socket_url, - create_helper.Pass(), - origin, - url_request_context, - net_log, - connect_delegate.Pass()); + scoped_ptr<StreamRequestImpl> request( + new StreamRequestImpl(socket_url, + url_request_context, + origin, + connect_delegate.Pass(), + create_helper.Pass())); + request->Start(); + return request.PassAs<WebSocketStreamRequest>(); } } // namespace net |