OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ | |
6 #define NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "net/base/request_priority.h" | |
11 #include "net/http/bidirectional_stream.h" | |
12 #include "net/http/http_stream_factory.h" | |
13 #include "net/ssl/ssl_config.h" | |
14 | |
15 namespace net { | |
16 | |
17 class BoundNetLog; | |
18 class HttpAuthController; | |
19 class HttpNetworkSession; | |
20 class HttpStream; | |
21 class HttpStreamRequest; | |
22 class IOBuffer; | |
23 class ProxyInfo; | |
24 struct HttpRequestInfo; | |
25 | |
26 // A helper class to create and manipulate a BidirectionalStream. The | |
27 // 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.
| |
28 class NET_EXPORT BidirectionalStreamHelper | |
29 : public HttpStreamRequest::Delegate { | |
30 public: | |
31 // Delegate interface to get notified of success of failure. Callbacks will be | |
32 // invoked asynchronously. | |
33 class NET_EXPORT Delegate { | |
34 public: | |
35 Delegate() {} | |
36 | |
37 // Called when BidirectionalStream is successfully created. | |
38 virtual void OnStreamReady() = 0; | |
39 | |
40 // Called when an error occurs. |error| is a net error. | |
41 virtual void OnStreamFailed(int error) = 0; | |
42 | |
43 protected: | |
44 virtual ~Delegate() {} | |
45 | |
46 private: | |
47 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
48 }; | |
49 | |
50 // Parts of |request_info| are ignored (e.g. |upload_data_stream| and most | |
51 // load flags). | |
52 BidirectionalStreamHelper(const HttpRequestInfo& request_info, | |
53 RequestPriority priority, | |
54 HttpNetworkSession* session, | |
55 Delegate* delegate); | |
56 | |
57 // 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.
| |
58 ~BidirectionalStreamHelper() override; | |
59 | |
60 // Proxy methods to the underlying BidirectionalStream: | |
61 | |
62 // Calls the BidirectionalStream method with the same name. | |
63 void Start(BidirectionalStream::Delegate* delegate); | |
64 | |
65 // Calls the BidirectionalStream method with the same name. | |
66 int ReadData(IOBuffer* buf, int buf_len); | |
67 | |
68 // Calls the BidirectionalStream method with the same name. | |
69 void SendData(IOBuffer* data, int length, bool end_stream); | |
70 | |
71 // Calls the BidirectionalStream method with the same name. | |
72 void Cancel(); | |
73 | |
74 // HttpStreamRequest::Delegate methods: | |
75 | |
76 void OnStreamReady(const SSLConfig& used_ssl_config, | |
77 const ProxyInfo& used_proxy_info, | |
78 HttpStream* stream) override; | |
79 void OnBidirectionalStreamReady(const SSLConfig& used_ssl_config, | |
80 const ProxyInfo& used_proxy_info, | |
81 BidirectionalStream* stream) override; | |
82 void OnWebSocketHandshakeStreamReady( | |
83 const SSLConfig& used_ssl_config, | |
84 const ProxyInfo& used_proxy_info, | |
85 WebSocketHandshakeStreamBase* stream) override; | |
86 void OnStreamFailed(int status, | |
87 const SSLConfig& used_ssl_config, | |
88 SSLFailureState ssl_failure_state) override; | |
89 void OnCertificateError(int status, | |
90 const SSLConfig& used_ssl_config, | |
91 const SSLInfo& ssl_info) override; | |
92 void OnNeedsProxyAuth(const HttpResponseInfo& response_info, | |
93 const SSLConfig& used_ssl_config, | |
94 const ProxyInfo& used_proxy_info, | |
95 HttpAuthController* auth_controller) override; | |
96 void OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
97 SSLCertRequestInfo* cert_info) override; | |
98 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, | |
99 const SSLConfig& used_ssl_config, | |
100 const ProxyInfo& used_proxy_info, | |
101 HttpStream* stream) override; | |
102 | |
103 private: | |
104 const HttpRequestInfo request_info_; | |
105 RequestPriority priority_; | |
106 BoundNetLog net_log_; | |
107 | |
108 Delegate* delegate_; | |
109 | |
110 scoped_ptr<HttpStreamRequest> stream_request_; | |
111 scoped_ptr<BidirectionalStream> stream_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamHelper); | |
114 }; | |
115 | |
116 } // namespace net | |
117 | |
118 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_HELPER_H_ | |
OLD | NEW |