Index: net/http/bidirectional_stream_helper.h |
diff --git a/net/http/bidirectional_stream_helper.h b/net/http/bidirectional_stream_helper.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a6501dd22d7a399e002d516fa93600f60a1f72c2 |
--- /dev/null |
+++ b/net/http/bidirectional_stream_helper.h |
@@ -0,0 +1,118 @@ |
+// 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. |
+ |
+#ifndef NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ |
+#define NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ |
+ |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "net/base/request_priority.h" |
+#include "net/http/bidirectional_stream.h" |
+#include "net/http/http_stream_factory.h" |
+#include "net/ssl/ssl_config.h" |
+ |
+namespace net { |
+ |
+class BoundNetLog; |
+class HttpAuthController; |
+class HttpNetworkSession; |
+class HttpStream; |
+class HttpStreamRequest; |
+class IOBuffer; |
+class ProxyInfo; |
+struct HttpRequestInfo; |
+ |
+// A helper class to create and manipulate a BidirectionalStream. The |
+// BidirectionalStreamHelper must be torn down before the HttpNetworkSession. |
mmenke
2015/11/03 20:32:13
Should probably make this the only externally visi
xunjieli
2015/11/05 23:17:13
Done.
|
+class NET_EXPORT BidirectionalStreamHelper |
+ : public HttpStreamRequest::Delegate { |
+ public: |
+ // Delegate interface to get notified of success of failure. Callbacks will be |
+ // invoked asynchronously. |
+ class NET_EXPORT Delegate { |
+ public: |
+ Delegate() {} |
+ |
+ // Called when BidirectionalStream is successfully created. |
+ virtual void OnStreamReady() = 0; |
+ |
+ // Called when an error occurs. |error| is a net error. |
+ virtual void OnStreamFailed(int error) = 0; |
+ |
+ protected: |
+ virtual ~Delegate() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(Delegate); |
+ }; |
+ |
+ // Parts of |request_info| are ignored (e.g. |upload_data_stream| and most |
+ // load flags). |
+ BidirectionalStreamHelper(const HttpRequestInfo& request_info, |
+ RequestPriority priority, |
+ HttpNetworkSession* session, |
+ Delegate* delegate); |
+ |
+ // Destroys the helper also cancels any pending request: |
mef
2015/11/02 18:00:42
nit: also -> and
xunjieli
2015/11/05 23:17:13
Done.
|
+ ~BidirectionalStreamHelper() override; |
+ |
+ // Proxy methods to the underlying BidirectionalStream: |
+ |
+ // Calls the BidirectionalStream method with the same name. |
+ void Start(BidirectionalStream::Delegate* delegate); |
+ |
+ // Calls the BidirectionalStream method with the same name. |
+ int ReadData(IOBuffer* buf, int buf_len); |
+ |
+ // Calls the BidirectionalStream method with the same name. |
+ void SendData(IOBuffer* data, int length, bool end_stream); |
+ |
+ // Calls the BidirectionalStream method with the same name. |
+ void Cancel(); |
+ |
+ // HttpStreamRequest::Delegate methods: |
+ |
+ void OnStreamReady(const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) override; |
+ void OnBidirectionalStreamReady(const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ BidirectionalStream* stream) override; |
+ void OnWebSocketHandshakeStreamReady( |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ WebSocketHandshakeStreamBase* stream) override; |
+ void OnStreamFailed(int status, |
+ const SSLConfig& used_ssl_config, |
+ SSLFailureState ssl_failure_state) override; |
+ void OnCertificateError(int status, |
+ const SSLConfig& used_ssl_config, |
+ const SSLInfo& ssl_info) override; |
+ void OnNeedsProxyAuth(const HttpResponseInfo& response_info, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpAuthController* auth_controller) override; |
+ void OnNeedsClientAuth(const SSLConfig& used_ssl_config, |
+ SSLCertRequestInfo* cert_info) override; |
+ void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, |
+ const SSLConfig& used_ssl_config, |
+ const ProxyInfo& used_proxy_info, |
+ HttpStream* stream) override; |
+ |
+ private: |
+ const HttpRequestInfo request_info_; |
+ RequestPriority priority_; |
+ BoundNetLog net_log_; |
+ |
+ Delegate* delegate_; |
+ |
+ scoped_ptr<HttpStreamRequest> stream_request_; |
+ scoped_ptr<BidirectionalStream> stream_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamHelper); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ |