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

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

Issue 291343004: Move work done in CreateAndConnectStreamWithCreateHelper into StreamRequestImpl's ctor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 private: 60 private:
61 StreamRequestImpl* owner_; 61 StreamRequestImpl* owner_;
62 HandshakeResult result_; 62 HandshakeResult result_;
63 }; 63 };
64 64
65 class StreamRequestImpl : public WebSocketStreamRequest { 65 class StreamRequestImpl : public WebSocketStreamRequest {
66 public: 66 public:
67 StreamRequestImpl( 67 StreamRequestImpl(
68 const GURL& url, 68 const GURL& url,
69 const URLRequestContext* context, 69 const URLRequestContext* context,
70 const url::Origin& origin,
70 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate, 71 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate,
71 WebSocketHandshakeStreamCreateHelper* create_helper) 72 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper)
72 : delegate_(new Delegate(this)), 73 : delegate_(new Delegate(this)),
73 url_request_(url, DEFAULT_PRIORITY, delegate_.get(), context), 74 url_request_(url, DEFAULT_PRIORITY, delegate_.get(), context),
74 connect_delegate_(connect_delegate.Pass()), 75 connect_delegate_(connect_delegate.Pass()),
75 create_helper_(create_helper) {} 76 create_helper_(create_helper.release()) {
77 HttpRequestHeaders headers;
78 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
79 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
80 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string());
81 headers.SetHeader(websockets::kSecWebSocketVersion,
82 websockets::kSupportedVersion);
83 url_request_.SetExtraRequestHeaders(headers);
84
85 // This passes the ownership of |create_helper_| to |url_request_|.
86 url_request_.SetUserData(
87 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
88 create_helper_);
89 url_request_.SetLoadFlags(LOAD_DISABLE_CACHE |
90 LOAD_BYPASS_CACHE |
91 LOAD_DO_NOT_PROMPT_FOR_LOGIN);
92 }
76 93
77 // Destroying this object destroys the URLRequest, which cancels the request 94 // Destroying this object destroys the URLRequest, which cancels the request
78 // and so terminates the handshake if it is incomplete. 95 // and so terminates the handshake if it is incomplete.
79 virtual ~StreamRequestImpl() {} 96 virtual ~StreamRequestImpl() {}
80 97
81 URLRequest* url_request() { return &url_request_; } 98 void Start() {
99 url_request_.Start();
100 }
82 101
83 void PerformUpgrade() { 102 void PerformUpgrade() {
84 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); 103 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade());
85 } 104 }
86 105
87 void ReportFailure() { 106 void ReportFailure() {
88 std::string failure_message; 107 std::string failure_message;
89 if (create_helper_->stream()) { 108 if (create_helper_->stream()) {
90 failure_message = create_helper_->stream()->GetFailureMessage(); 109 failure_message = create_helper_->stream()->GetFailureMessage();
91 } else { 110 } else {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void Delegate::OnSSLCertificateError(URLRequest* request, 170 void Delegate::OnSSLCertificateError(URLRequest* request,
152 const SSLInfo& ssl_info, 171 const SSLInfo& ssl_info,
153 bool fatal) { 172 bool fatal) {
154 request->Cancel(); 173 request->Cancel();
155 } 174 }
156 175
157 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { 176 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) {
158 NOTREACHED(); 177 NOTREACHED();
159 } 178 }
160 179
161 // Internal implementation of CreateAndConnectStream and
162 // CreateAndConnectStreamForTesting.
163 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper(
164 const GURL& socket_url,
165 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
166 const url::Origin& origin,
167 URLRequestContext* url_request_context,
168 const BoundNetLog& net_log,
169 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
170 scoped_ptr<StreamRequestImpl> request(
171 new StreamRequestImpl(socket_url,
172 url_request_context,
173 connect_delegate.Pass(),
174 create_helper.get()));
175 HttpRequestHeaders headers;
176 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
177 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
178 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string());
179 headers.SetHeader(websockets::kSecWebSocketVersion,
180 websockets::kSupportedVersion);
181 request->url_request()->SetExtraRequestHeaders(headers);
182 request->url_request()->SetUserData(
183 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
184 create_helper.release());
185 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE |
186 LOAD_BYPASS_CACHE |
187 LOAD_DO_NOT_PROMPT_FOR_LOGIN);
188 request->url_request()->Start();
189 return request.PassAs<WebSocketStreamRequest>();
190 }
191
192 } // namespace 180 } // namespace
193 181
194 WebSocketStreamRequest::~WebSocketStreamRequest() {} 182 WebSocketStreamRequest::~WebSocketStreamRequest() {}
195 183
196 WebSocketStream::WebSocketStream() {} 184 WebSocketStream::WebSocketStream() {}
197 WebSocketStream::~WebSocketStream() {} 185 WebSocketStream::~WebSocketStream() {}
198 186
199 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} 187 WebSocketStream::ConnectDelegate::~ConnectDelegate() {}
200 188
201 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( 189 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream(
202 const GURL& socket_url, 190 const GURL& socket_url,
203 const std::vector<std::string>& requested_subprotocols, 191 const std::vector<std::string>& requested_subprotocols,
204 const url::Origin& origin, 192 const url::Origin& origin,
205 URLRequestContext* url_request_context, 193 URLRequestContext* url_request_context,
206 const BoundNetLog& net_log, 194 const BoundNetLog& net_log,
207 scoped_ptr<ConnectDelegate> connect_delegate) { 195 scoped_ptr<ConnectDelegate> connect_delegate) {
208 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( 196 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper(
209 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), 197 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(),
210 requested_subprotocols)); 198 requested_subprotocols));
211 return CreateAndConnectStreamWithCreateHelper(socket_url, 199 scoped_ptr<StreamRequestImpl> request(
212 create_helper.Pass(), 200 new StreamRequestImpl(socket_url,
213 origin, 201 url_request_context,
214 url_request_context, 202 origin,
215 net_log, 203 connect_delegate.Pass(),
216 connect_delegate.Pass()); 204 create_helper.Pass()));
205 request->Start();
206 return request.PassAs<WebSocketStreamRequest>();
217 } 207 }
218 208
219 // This is declared in websocket_test_util.h. 209 // This is declared in websocket_test_util.h.
220 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( 210 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting(
221 const GURL& socket_url, 211 const GURL& socket_url,
222 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, 212 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
223 const url::Origin& origin, 213 const url::Origin& origin,
224 URLRequestContext* url_request_context, 214 URLRequestContext* url_request_context,
225 const BoundNetLog& net_log, 215 const BoundNetLog& net_log,
226 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 216 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
227 return CreateAndConnectStreamWithCreateHelper(socket_url, 217 scoped_ptr<StreamRequestImpl> request(
228 create_helper.Pass(), 218 new StreamRequestImpl(socket_url,
229 origin, 219 url_request_context,
230 url_request_context, 220 origin,
231 net_log, 221 connect_delegate.Pass(),
232 connect_delegate.Pass()); 222 create_helper.Pass()));
223 request->Start();
224 return request.PassAs<WebSocketStreamRequest>();
233 } 225 }
234 226
235 } // namespace net 227 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698