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

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: 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/http/http_request_headers.h" 10 #include "net/http/http_request_headers.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 private: 59 private:
60 StreamRequestImpl* owner_; 60 StreamRequestImpl* owner_;
61 HandshakeResult result_; 61 HandshakeResult result_;
62 }; 62 };
63 63
64 class StreamRequestImpl : public WebSocketStreamRequest { 64 class StreamRequestImpl : public WebSocketStreamRequest {
65 public: 65 public:
66 StreamRequestImpl( 66 StreamRequestImpl(
67 const GURL& url, 67 const GURL& url,
68 const URLRequestContext* context, 68 const URLRequestContext* context,
69 const url::Origin& origin,
69 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate, 70 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate,
70 WebSocketHandshakeStreamCreateHelper* create_helper) 71 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper)
71 : delegate_(new Delegate(this)), 72 : delegate_(new Delegate(this)),
72 url_request_(url, DEFAULT_PRIORITY, delegate_.get(), context), 73 url_request_(url, DEFAULT_PRIORITY, delegate_.get(), context),
73 connect_delegate_(connect_delegate.Pass()), 74 connect_delegate_(connect_delegate.Pass()),
74 create_helper_(create_helper) {} 75 create_helper_(create_helper.get()) {
Adam Rice 2014/05/22 08:36:14 Suggestion: use .release() here and then use creat
tyoshino (SeeGerritForStatus) 2014/05/22 09:11:00 Done.
76 HttpRequestHeaders headers;
77 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
78 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
79 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string());
80 headers.SetHeader(websockets::kSecWebSocketVersion,
81 websockets::kSupportedVersion);
82 url_request_.SetExtraRequestHeaders(headers);
83
84 url_request_.SetUserData(
85 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
86 create_helper.release());
87 url_request_.SetLoadFlags(LOAD_DISABLE_CACHE |
88 LOAD_BYPASS_CACHE |
89 LOAD_DO_NOT_PROMPT_FOR_LOGIN);
90 url_request_.Start();
Adam Rice 2014/05/22 08:36:14 I am not sure about this. On the one hand, it viol
tyoshino (SeeGerritForStatus) 2014/05/22 09:11:00 I was also wondering if Start() should be run outs
Adam Rice 2014/05/22 09:22:02 Agreed.
91 }
75 92
76 // Destroying this object destroys the URLRequest, which cancels the request 93 // Destroying this object destroys the URLRequest, which cancels the request
77 // and so terminates the handshake if it is incomplete. 94 // and so terminates the handshake if it is incomplete.
78 virtual ~StreamRequestImpl() {} 95 virtual ~StreamRequestImpl() {}
79 96
80 URLRequest* url_request() { return &url_request_; }
81
82 void PerformUpgrade() { 97 void PerformUpgrade() {
83 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade()); 98 connect_delegate_->OnSuccess(create_helper_->stream()->Upgrade());
84 } 99 }
85 100
86 void ReportFailure() { 101 void ReportFailure() {
87 std::string failure_message; 102 std::string failure_message;
88 if (create_helper_->stream()) { 103 if (create_helper_->stream()) {
89 failure_message = create_helper_->stream()->GetFailureMessage(); 104 failure_message = create_helper_->stream()->GetFailureMessage();
90 } else { 105 } else {
91 switch (url_request_.status().status()) { 106 switch (url_request_.status().status()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void Delegate::OnSSLCertificateError(URLRequest* request, 165 void Delegate::OnSSLCertificateError(URLRequest* request,
151 const SSLInfo& ssl_info, 166 const SSLInfo& ssl_info,
152 bool fatal) { 167 bool fatal) {
153 request->Cancel(); 168 request->Cancel();
154 } 169 }
155 170
156 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { 171 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) {
157 NOTREACHED(); 172 NOTREACHED();
158 } 173 }
159 174
160 // Internal implementation of CreateAndConnectStream and
161 // CreateAndConnectStreamForTesting.
162 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper(
163 const GURL& socket_url,
164 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
165 const url::Origin& origin,
166 URLRequestContext* url_request_context,
167 const BoundNetLog& net_log,
168 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
169 scoped_ptr<StreamRequestImpl> request(
170 new StreamRequestImpl(socket_url,
171 url_request_context,
172 connect_delegate.Pass(),
173 create_helper.get()));
174 HttpRequestHeaders headers;
175 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
176 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
177 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string());
178 headers.SetHeader(websockets::kSecWebSocketVersion,
179 websockets::kSupportedVersion);
180 request->url_request()->SetExtraRequestHeaders(headers);
181 request->url_request()->SetUserData(
182 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
183 create_helper.release());
184 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE |
185 LOAD_BYPASS_CACHE |
186 LOAD_DO_NOT_PROMPT_FOR_LOGIN);
187 request->url_request()->Start();
188 return request.PassAs<WebSocketStreamRequest>();
189 }
190
191 } // namespace 175 } // namespace
192 176
193 WebSocketStreamRequest::~WebSocketStreamRequest() {} 177 WebSocketStreamRequest::~WebSocketStreamRequest() {}
194 178
195 WebSocketStream::WebSocketStream() {} 179 WebSocketStream::WebSocketStream() {}
196 WebSocketStream::~WebSocketStream() {} 180 WebSocketStream::~WebSocketStream() {}
197 181
198 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} 182 WebSocketStream::ConnectDelegate::~ConnectDelegate() {}
199 183
200 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( 184 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream(
201 const GURL& socket_url, 185 const GURL& socket_url,
202 const std::vector<std::string>& requested_subprotocols, 186 const std::vector<std::string>& requested_subprotocols,
203 const url::Origin& origin, 187 const url::Origin& origin,
204 URLRequestContext* url_request_context, 188 URLRequestContext* url_request_context,
205 const BoundNetLog& net_log, 189 const BoundNetLog& net_log,
206 scoped_ptr<ConnectDelegate> connect_delegate) { 190 scoped_ptr<ConnectDelegate> connect_delegate) {
207 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( 191 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper(
208 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), 192 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(),
209 requested_subprotocols)); 193 requested_subprotocols));
210 return CreateAndConnectStreamWithCreateHelper(socket_url, 194 scoped_ptr<WebSocketStreamRequest> request(
211 create_helper.Pass(), 195 new StreamRequestImpl(socket_url,
212 origin, 196 url_request_context,
213 url_request_context, 197 origin,
214 net_log, 198 connect_delegate.Pass(),
215 connect_delegate.Pass()); 199 create_helper.Pass()));
200 return request.PassAs<WebSocketStreamRequest>();
Adam Rice 2014/05/22 08:36:14 You don't need PassAs<>() here. Plain Pass() shoul
tyoshino (SeeGerritForStatus) 2014/05/22 09:11:00 Oh, right! As I separated Start() call on URLReque
Adam Rice 2014/05/22 09:22:02 I did have the evil idea of having Start() return
216 } 201 }
217 202
218 // This is declared in websocket_test_util.h. 203 // This is declared in websocket_test_util.h.
219 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( 204 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting(
220 const GURL& socket_url, 205 const GURL& socket_url,
221 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, 206 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
222 const url::Origin& origin, 207 const url::Origin& origin,
223 URLRequestContext* url_request_context, 208 URLRequestContext* url_request_context,
224 const BoundNetLog& net_log, 209 const BoundNetLog& net_log,
225 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
226 return CreateAndConnectStreamWithCreateHelper(socket_url, 211 scoped_ptr<WebSocketStreamRequest> request(
227 create_helper.Pass(), 212 new StreamRequestImpl(socket_url,
228 origin, 213 url_request_context,
229 url_request_context, 214 origin,
230 net_log, 215 connect_delegate.Pass(),
231 connect_delegate.Pass()); 216 create_helper.Pass()));
217 return request.PassAs<WebSocketStreamRequest>();
232 } 218 }
233 219
234 } // namespace net 220 } // 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