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

Unified Diff: net/http/bidirectional_stream_create_helper.cc

Issue 1326503003: Added a net::BidirectionalStream to expose a bidirectional streaming interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid inlining Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: net/http/bidirectional_stream_create_helper.cc
diff --git a/net/http/bidirectional_stream_create_helper.cc b/net/http/bidirectional_stream_create_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f6f0ef87d6f09aeb47990378eaf68e9d54930f61
--- /dev/null
+++ b/net/http/bidirectional_stream_create_helper.cc
@@ -0,0 +1,124 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http/bidirectional_stream_create_helper.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_errors.h"
+#include "net/http/bidirectional_stream.h"
+#include "net/http/http_request_info.h"
+#include "net/http/http_stream.h"
+#include "net/http/http_transaction_factory.h"
+#include "net/ssl/ssl_cert_request_info.h"
+#include "net/url_request/url_request_context.h"
+#include "url/gurl.h"
+
+namespace net {
+
+BidirectionalStreamCreateHelper::BidirectionalStreamCreateHelper(
+ const HttpRequestInfo* request_info,
+ RequestPriority priority,
+ const URLRequestContext* context,
+ Delegate* delegate)
+ : request_info_(request_info),
+ priority_(priority),
+ delegate_(delegate),
+ net_log_(BoundNetLog::Make(context->net_log(),
+ NetLog::SOURCE_BIDIRECTIONAL_STREAM)) {
mmenke 2015/10/21 22:40:16 Hrm...this log is going to look a little weird. N
xunjieli 2015/10/22 20:01:41 Should we make the embedder (who presumably will o
mmenke 2015/10/22 20:13:36 That wouldn't - the way things elsewhere is that t
xunjieli 2015/10/23 17:51:23 Done. Thanks for the detailed explanation! I think
+ HttpTransactionFactory* factory = context->http_transaction_factory();
+ session_ = factory->GetSession();
+
+ session_->ssl_config_service()->GetSSLConfig(&server_ssl_config_);
+ proxy_ssl_config_ = server_ssl_config_;
+}
+
+BidirectionalStreamCreateHelper::~BidirectionalStreamCreateHelper() {
+ if (stream_)
+ stream_->Cancel();
+}
+
+void BidirectionalStreamCreateHelper::CreateBidirectionalStream() {
+ if (!request_info_->url.SchemeIs("https")) {
+ delegate_->OnStreamFailed(ERR_DISALLOWED_URL_SCHEME);
mmenke 2015/10/21 22:40:16 Do we want to invoke callbacks synchronously, or g
xunjieli 2015/10/22 20:01:41 Done. Probably the latter to be more consistent?
mmenke 2015/10/22 20:13:36 I think async is indeed the way to go - avoids re-
+ return;
+ }
+ stream_request_.reset(
+ session_->http_stream_factory()->RequestBidirectionalStream(
+ *request_info_, priority_, server_ssl_config_, proxy_ssl_config_,
+ this, net_log_));
+}
+
+void BidirectionalStreamCreateHelper::OnStreamReady(
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpStream* stream) {
+ NOTREACHED();
+}
+
+void BidirectionalStreamCreateHelper::OnBidirectionalStreamReady(
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ BidirectionalStream* stream) {
+ stream_.reset(stream);
+ delegate_->OnStreamCreated();
mmenke 2015/10/21 22:40:16 Should we pass in the stream here (wrapped in a sc
xunjieli 2015/10/22 20:01:41 Done.
+}
+
+void BidirectionalStreamCreateHelper::OnWebSocketHandshakeStreamReady(
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ WebSocketHandshakeStreamBase* stream) {
+ NOTREACHED();
+}
+
+void BidirectionalStreamCreateHelper::OnStreamFailed(
+ int result,
+ const SSLConfig& used_ssl_config,
+ SSLFailureState ssl_failure_state) {
+ DCHECK_NE(OK, result);
mmenke 2015/10/21 22:40:16 If we want to DCHECK the result, think we really w
xunjieli 2015/10/22 20:01:41 Done.
+ DCHECK(stream_request_.get());
mmenke 2015/10/21 22:40:16 nit: .get() isn't needed in any of these.
xunjieli 2015/10/22 20:01:41 Done.
+ DCHECK(!stream_);
+
+ delegate_->OnStreamFailed(result);
+}
+
+void BidirectionalStreamCreateHelper::OnCertificateError(
+ int result,
+ const SSLConfig& used_ssl_config,
+ const SSLInfo& ssl_info) {
+ DCHECK_NE(OK, result);
+ DCHECK(stream_request_.get());
+ DCHECK(!stream_);
+
+ delegate_->OnStreamFailed(result);
+}
+
+void BidirectionalStreamCreateHelper::OnNeedsProxyAuth(
+ const HttpResponseInfo& proxy_response,
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpAuthController* auth_controller) {
+ DCHECK(stream_request_.get());
+ DCHECK(!stream_);
+
+ delegate_->OnStreamFailed(ERR_PROXY_AUTH_REQUESTED);
+}
+
+void BidirectionalStreamCreateHelper::OnNeedsClientAuth(
+ const SSLConfig& used_ssl_config,
+ SSLCertRequestInfo* cert_info) {
+ DCHECK(stream_request_.get());
+ DCHECK(!stream_);
+
+ delegate_->OnStreamFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED);
+}
+
+void BidirectionalStreamCreateHelper::OnHttpsProxyTunnelResponse(
+ const HttpResponseInfo& response_info,
+ const SSLConfig& used_ssl_config,
+ const ProxyInfo& used_proxy_info,
+ HttpStream* stream) {
+ NOTREACHED();
mmenke 2015/10/21 22:40:16 nit: include base/logging.h
xunjieli 2015/10/22 20:01:41 Done.
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698