Index: net/http/bidirectional_stream_helper.cc |
diff --git a/net/http/bidirectional_stream_helper.cc b/net/http/bidirectional_stream_helper.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1c42ceba0b330b4b9e4dfd9c7db4ffc7c03c5bb6 |
--- /dev/null |
+++ b/net/http/bidirectional_stream_helper.cc |
@@ -0,0 +1,150 @@ |
+// 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_helper.h" |
+ |
+#include "base/logging.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/thread_task_runner_handle.h" |
+#include "net/base/load_flags.h" |
+#include "net/base/net_errors.h" |
+#include "net/http/http_network_session.h" |
+#include "net/http/http_request_info.h" |
+#include "net/http/http_stream.h" |
+#include "net/log/net_log.h" |
+#include "net/ssl/ssl_cert_request_info.h" |
+#include "url/gurl.h" |
+ |
+namespace net { |
+ |
+BidirectionalStreamHelper::BidirectionalStreamHelper( |
+ const HttpRequestInfo& request_info, |
+ RequestPriority priority, |
+ HttpNetworkSession* session, |
+ Delegate* delegate) |
+ : request_info_(request_info), |
+ priority_(priority), |
+ net_log_(BoundNetLog::Make(session->net_log(), |
+ NetLog::SOURCE_BIDIRECTIONAL_STREAM)), |
+ delegate_(delegate) { |
+ DCHECK(!request_info.upload_data_stream); |
+ DCHECK_EQ(LOAD_NORMAL, request_info.load_flags); |
+ |
+ SSLConfig server_ssl_config; |
+ session->ssl_config_service()->GetSSLConfig(&server_ssl_config); |
+ |
+ if (!request_info.url.SchemeIs("https")) { |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&Delegate::OnStreamFailed, base::Unretained(delegate_), |
+ ERR_DISALLOWED_URL_SCHEME)); |
+ return; |
+ } |
+ |
+ stream_request_.reset( |
+ session->http_stream_factory()->RequestBidirectionalStream( |
+ request_info_, priority_, server_ssl_config, server_ssl_config, this, |
+ net_log_)); |
+} |
+ |
+BidirectionalStreamHelper::~BidirectionalStreamHelper() {} |
+ |
+void BidirectionalStreamHelper::Start(BidirectionalStream::Delegate* delegate) { |
mmenke
2015/11/03 20:32:13
Destroy the stream_request? Not so concerned abou
xunjieli
2015/11/05 23:17:13
Done.
|
+ DCHECK(stream_); |
+ |
+ stream_->Start(request_info_, priority_, net_log_, delegate); |
+} |
+ |
+int BidirectionalStreamHelper::ReadData(IOBuffer* buf, int buf_len) { |
+ DCHECK(stream_); |
+ |
+ return stream_->ReadData(buf, buf_len); |
+} |
+ |
+void BidirectionalStreamHelper::SendData(IOBuffer* data, |
+ int length, |
+ bool end_stream) { |
+ DCHECK(stream_); |
+ |
+ stream_->SendData(data, length, end_stream); |
+} |
+ |
+void BidirectionalStreamHelper::Cancel() { |
mmenke
2015/11/03 20:32:13
If we're still requesting a stream, should cancel
xunjieli
2015/11/05 23:17:13
Done.
|
+ DCHECK(stream_); |
+ |
+ stream_->Cancel(); |
+} |
+ |
+void BidirectionalStreamHelper::OnStreamReady(const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) { |
+ NOTREACHED(); |
+} |
+ |
+void BidirectionalStreamHelper::OnBidirectionalStreamReady( |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ BidirectionalStream* stream) { |
+ DCHECK(!stream_); |
+ |
+ stream_.reset(stream); |
+ delegate_->OnStreamReady(); |
+} |
+ |
+void BidirectionalStreamHelper::OnWebSocketHandshakeStreamReady( |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ WebSocketHandshakeStreamBase* stream) { |
+ NOTREACHED(); |
+} |
+ |
+void BidirectionalStreamHelper::OnStreamFailed( |
+ int result, |
+ const SSLConfig& used_ssl_config, |
+ SSLFailureState ssl_failure_state) { |
+ DCHECK_LT(result, 0); |
+ DCHECK_NE(result, ERR_IO_PENDING); |
+ DCHECK(stream_request_); |
+ |
+ delegate_->OnStreamFailed(result); |
+} |
+ |
+void BidirectionalStreamHelper::OnCertificateError( |
+ int result, |
+ const SSLConfig& used_ssl_config, |
+ const SSLInfo& ssl_info) { |
+ DCHECK_LT(result, 0); |
+ DCHECK_NE(result, ERR_IO_PENDING); |
+ DCHECK(stream_request_); |
+ |
+ delegate_->OnStreamFailed(result); |
+} |
+ |
+void BidirectionalStreamHelper::OnNeedsProxyAuth( |
+ const HttpResponseInfo& proxy_response, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpAuthController* auth_controller) { |
+ DCHECK(stream_request_); |
+ |
+ delegate_->OnStreamFailed(ERR_PROXY_AUTH_REQUESTED); |
+} |
+ |
+void BidirectionalStreamHelper::OnNeedsClientAuth( |
+ const SSLConfig& used_ssl_config, |
+ SSLCertRequestInfo* cert_info) { |
+ DCHECK(stream_request_); |
+ |
+ delegate_->OnStreamFailed(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
+} |
+ |
+void BidirectionalStreamHelper::OnHttpsProxyTunnelResponse( |
+ const HttpResponseInfo& response_info, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) { |
+ NOTREACHED(); |
+} |
+ |
+} // namespace net |