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

Side by Side Diff: net/websockets/websocket_stream.cc

Issue 2842263003: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: Created 3 years, 8 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/url_request/url_request_unittest.cc ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "net/websockets/websocket_stream.h" 5 #include "net/websockets/websocket_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const URLRequestContext* context, 86 const URLRequestContext* context,
87 const url::Origin& origin, 87 const url::Origin& origin,
88 const GURL& first_party_for_cookies, 88 const GURL& first_party_for_cookies,
89 const std::string& additional_headers, 89 const std::string& additional_headers,
90 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate, 90 std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate,
91 std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper) 91 std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper)
92 : delegate_(new Delegate(this)), 92 : delegate_(new Delegate(this)),
93 url_request_( 93 url_request_(
94 context->CreateRequest(url, DEFAULT_PRIORITY, delegate_.get())), 94 context->CreateRequest(url, DEFAULT_PRIORITY, delegate_.get())),
95 connect_delegate_(std::move(connect_delegate)), 95 connect_delegate_(std::move(connect_delegate)),
96 handshake_stream_create_helper_(create_helper.release()), 96 handshake_stream_create_helper_(create_helper.release()),
mattm 2017/04/27 04:58:11 would be cleaner to use create_helper.get() here a
Avi (use Gerrit) 2017/04/27 05:05:44 Why is handshake_stream_create_helper_ even a memb
mattm 2017/04/27 05:15:27 Good point. (I'm not familiar with the history of
97 handshake_stream_(nullptr) { 97 handshake_stream_(nullptr) {
98 handshake_stream_create_helper_->set_stream_request(this); 98 handshake_stream_create_helper_->set_stream_request(this);
99 HttpRequestHeaders headers; 99 HttpRequestHeaders headers;
100 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); 100 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
101 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); 101 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
102 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.Serialize()); 102 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.Serialize());
103 headers.SetHeader(websockets::kSecWebSocketVersion, 103 headers.SetHeader(websockets::kSecWebSocketVersion,
104 websockets::kSupportedVersion); 104 websockets::kSupportedVersion);
105 105
106 headers.AddHeadersFromString(additional_headers); 106 headers.AddHeadersFromString(additional_headers);
107 107
108 url_request_->SetExtraRequestHeaders(headers); 108 url_request_->SetExtraRequestHeaders(headers);
109 url_request_->set_initiator(origin); 109 url_request_->set_initiator(origin);
110 url_request_->set_first_party_for_cookies(first_party_for_cookies); 110 url_request_->set_first_party_for_cookies(first_party_for_cookies);
111 111
112 // This passes the ownership of |handshake_stream_create_helper_| to 112 // This passes the ownership of |handshake_stream_create_helper_| to
113 // |url_request_|. 113 // |url_request_|.
114 url_request_->SetUserData( 114 url_request_->SetUserData(
115 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), 115 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
116 handshake_stream_create_helper_); 116 base::WrapUnique(handshake_stream_create_helper_));
117 url_request_->SetLoadFlags(LOAD_DISABLE_CACHE | LOAD_BYPASS_CACHE); 117 url_request_->SetLoadFlags(LOAD_DISABLE_CACHE | LOAD_BYPASS_CACHE);
118 connect_delegate_->OnCreateRequest(url_request_.get()); 118 connect_delegate_->OnCreateRequest(url_request_.get());
119 } 119 }
120 120
121 // Destroying this object destroys the URLRequest, which cancels the request 121 // Destroying this object destroys the URLRequest, which cancels the request
122 // and so terminates the handshake if it is incomplete. 122 // and so terminates the handshake if it is incomplete.
123 ~WebSocketStreamRequestImpl() override {} 123 ~WebSocketStreamRequestImpl() override {}
124 124
125 void OnHandshakeStreamCreated( 125 void OnHandshakeStreamCreated(
126 WebSocketHandshakeStreamBase* handshake_stream) override { 126 WebSocketHandshakeStreamBase* handshake_stream) override {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 DCHECK(connect_delegate); 407 DCHECK(connect_delegate);
408 if (headers.get()) { 408 if (headers.get()) {
409 connect_delegate->OnFinishOpeningHandshake( 409 connect_delegate->OnFinishOpeningHandshake(
410 base::MakeUnique<WebSocketHandshakeResponseInfo>( 410 base::MakeUnique<WebSocketHandshakeResponseInfo>(
411 url, headers->response_code(), headers->GetStatusText(), headers, 411 url, headers->response_code(), headers->GetStatusText(), headers,
412 response_time)); 412 response_time));
413 } 413 }
414 } 414 }
415 415
416 } // namespace net 416 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698