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

Side by Side Diff: net/http/http_stream_factory_impl_request.h

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address nits Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "net/base/net_export.h"
12 #include "net/http/http_stream_factory_impl.h" 13 #include "net/http/http_stream_factory_impl.h"
13 #include "net/log/net_log.h" 14 #include "net/log/net_log.h"
14 #include "net/socket/connection_attempts.h" 15 #include "net/socket/connection_attempts.h"
15 #include "net/socket/ssl_client_socket.h" 16 #include "net/socket/ssl_client_socket.h"
16 #include "net/spdy/spdy_session_key.h" 17 #include "net/spdy/spdy_session_key.h"
17 #include "net/ssl/ssl_failure_state.h" 18 #include "net/ssl/ssl_failure_state.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace net { 21 namespace net {
21 22
22 class BidirectionalStreamImpl; 23 class BidirectionalStreamImpl;
23 class ClientSocketHandle; 24 class ClientSocketHandle;
24 class HttpStream; 25 class HttpStream;
25 class SpdySession; 26 class SpdySession;
26 27
27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { 28 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
28 public: 29 public:
30 class NET_EXPORT_PRIVATE Helper {
31 public:
32 virtual ~Helper() {}
33
34 // Returns the LoadState for Request.
35 virtual LoadState GetLoadState() const = 0;
36
37 // Called when Request is destructed.
38 virtual void OnRequestComplete() = 0;
39
40 // Called to resume the HttpStream creation process when necessary
41 // Proxy authentication credentials are collected.
42 virtual int RestartTunnelWithProxyAuth(
43 const AuthCredentials& credentials) = 0;
44
45 // Called when the priority of transaction changes.
46 virtual void SetPriority(RequestPriority priority) = 0;
47 };
48
49 // Request will notify |job_controller| when it's destructed.
50 // Thus |job_controller| is valid for the lifetime of the |this| Request.
29 Request(const GURL& url, 51 Request(const GURL& url,
30 HttpStreamFactoryImpl* factory, 52 Helper* helper,
31 HttpStreamRequest::Delegate* delegate, 53 HttpStreamRequest::Delegate* delegate,
32 WebSocketHandshakeStreamBase::CreateHelper* 54 WebSocketHandshakeStreamBase::CreateHelper*
33 websocket_handshake_stream_create_helper, 55 websocket_handshake_stream_create_helper,
34 const BoundNetLog& net_log, 56 const BoundNetLog& net_log,
35 StreamType stream_type); 57 StreamType stream_type);
36 58
37 ~Request() override; 59 ~Request() override;
38 60
39 // The GURL from the HttpRequestInfo the started the Request. 61 // The GURL from the HttpRequestInfo the started the Request.
40 const GURL& url() const { return url_; } 62 const GURL& url() const { return url_; }
41 63
42 const BoundNetLog& net_log() const { return net_log_; } 64 const BoundNetLog& net_log() const { return net_log_; }
43 65
44 // Called when the Job determines the appropriate |spdy_session_key| for the 66 // Called when the |helper_| determines the appropriate |spdy_session_key|
45 // Request. Note that this does not mean that SPDY is necessarily supported 67 // for the Request. Note that this does not mean that SPDY is necessarily
46 // for this SpdySessionKey, since we may need to wait for NPN to complete 68 // supported for this SpdySessionKey, since we may need to wait for NPN to
47 // before knowing if SPDY is available. 69 // complete before knowing if SPDY is available.
48 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); 70 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
49 bool HasSpdySessionKey() const; 71 bool HasSpdySessionKey() const;
50 72
51 // Attaches |job| to this request. Does not mean that Request will use |job|,
52 // but Request will own |job|.
53 void AttachJob(HttpStreamFactoryImpl::Job* job);
54
55 // Marks completion of the request. Must be called before OnStreamReady(). 73 // Marks completion of the request. Must be called before OnStreamReady().
56 void Complete(bool was_npn_negotiated, 74 void Complete(bool was_npn_negotiated,
57 NextProto protocol_negotiated, 75 NextProto protocol_negotiated,
58 bool using_spdy); 76 bool using_spdy);
59 77
60 // If this Request has a |spdy_session_key_|, remove this session from the 78 void ResetSpdySessionKey();
61 // SpdySessionRequestMap.
62 void RemoveRequestFromSpdySessionRequestMap();
63 79
64 // Called by an attached Job if it sets up a SpdySession. 80 // Called by |helper_| to record connection attempts made by the socket
65 // |stream| is null when |stream_type| is HttpStreamRequest::HTTP_STREAM. 81 // layer in an attached Job for this stream request.
66 // |bidirectional_stream_spdy_impl| is null when |stream_type| is
67 // HttpStreamRequest::BIDIRECTIONAL_STREAM.
68 void OnNewSpdySessionReady(
69 Job* job,
70 std::unique_ptr<HttpStream> stream,
71 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_spdy_impl,
72 const base::WeakPtr<SpdySession>& spdy_session,
73 bool direct);
74
75 // Called by an attached Job to record connection attempts made by the socket
76 // layer for this stream request.
77 void AddConnectionAttempts(const ConnectionAttempts& attempts); 82 void AddConnectionAttempts(const ConnectionAttempts& attempts);
78 83
79 WebSocketHandshakeStreamBase::CreateHelper* 84 WebSocketHandshakeStreamBase::CreateHelper*
80 websocket_handshake_stream_create_helper() { 85 websocket_handshake_stream_create_helper() {
81 return websocket_handshake_stream_create_helper_; 86 return websocket_handshake_stream_create_helper_;
82 } 87 }
83 88
84 // HttpStreamRequest::Delegate methods which we implement. Note we don't 89 // HttpStreamRequest::Delegate methods which we implement. Note we don't
85 // actually subclass HttpStreamRequest::Delegate. 90 // actually subclass HttpStreamRequest::Delegate.
86 91
87 void OnStreamReady(Job* job, 92 void OnStreamReady(const SSLConfig& used_ssl_config,
88 const SSLConfig& used_ssl_config,
89 const ProxyInfo& used_proxy_info, 93 const ProxyInfo& used_proxy_info,
90 HttpStream* stream); 94 HttpStream* stream);
91 void OnBidirectionalStreamImplReady(Job* job, 95 void OnBidirectionalStreamImplReady(const SSLConfig& used_ssl_config,
92 const SSLConfig& used_ssl_config,
93 const ProxyInfo& used_proxy_info, 96 const ProxyInfo& used_proxy_info,
94 BidirectionalStreamImpl* stream); 97 BidirectionalStreamImpl* stream);
95 98
96 void OnWebSocketHandshakeStreamReady(Job* job, 99 void OnWebSocketHandshakeStreamReady(const SSLConfig& used_ssl_config,
97 const SSLConfig& used_ssl_config,
98 const ProxyInfo& used_proxy_info, 100 const ProxyInfo& used_proxy_info,
99 WebSocketHandshakeStreamBase* stream); 101 WebSocketHandshakeStreamBase* stream);
100 void OnStreamFailed(Job* job, 102 void OnStreamFailed(int status,
101 int status,
102 const SSLConfig& used_ssl_config, 103 const SSLConfig& used_ssl_config,
103 SSLFailureState ssl_failure_state); 104 SSLFailureState ssl_failure_state);
104 void OnCertificateError(Job* job, 105 void OnCertificateError(int status,
105 int status,
106 const SSLConfig& used_ssl_config, 106 const SSLConfig& used_ssl_config,
107 const SSLInfo& ssl_info); 107 const SSLInfo& ssl_info);
108 void OnNeedsProxyAuth(Job* job, 108 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
109 const HttpResponseInfo& proxy_response,
110 const SSLConfig& used_ssl_config, 109 const SSLConfig& used_ssl_config,
111 const ProxyInfo& used_proxy_info, 110 const ProxyInfo& used_proxy_info,
112 HttpAuthController* auth_controller); 111 HttpAuthController* auth_controller);
113 void OnNeedsClientAuth(Job* job, 112 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
114 const SSLConfig& used_ssl_config,
115 SSLCertRequestInfo* cert_info); 113 SSLCertRequestInfo* cert_info);
116 void OnHttpsProxyTunnelResponse( 114 void OnHttpsProxyTunnelResponse(
117 Job *job,
118 const HttpResponseInfo& response_info, 115 const HttpResponseInfo& response_info,
119 const SSLConfig& used_ssl_config, 116 const SSLConfig& used_ssl_config,
120 const ProxyInfo& used_proxy_info, 117 const ProxyInfo& used_proxy_info,
121 HttpStream* stream); 118 HttpStream* stream);
122 119
123 // HttpStreamRequest methods. 120 // HttpStreamRequest methods.
124 121
125 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; 122 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override;
126 void SetPriority(RequestPriority priority) override; 123 void SetPriority(RequestPriority priority) override;
127 LoadState GetLoadState() const override; 124 LoadState GetLoadState() const override;
128 bool was_npn_negotiated() const override; 125 bool was_npn_negotiated() const override;
129 NextProto protocol_negotiated() const override; 126 NextProto protocol_negotiated() const override;
130 bool using_spdy() const override; 127 bool using_spdy() const override;
131 const ConnectionAttempts& connection_attempts() const override; 128 const ConnectionAttempts& connection_attempts() const override;
132 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 129 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
130 const SpdySessionKey* spdy_session_key() const {
131 return spdy_session_key_.get();
132 }
133 133
134 private: 134 private:
135 // Used to bind |job| to the request and orphan all other jobs in |jobs_|. 135 const GURL url_;
136 void BindJob(Job* job);
137 136
138 // Used to orphan all jobs in |jobs_|. 137 // Unowned. The helper must outlive this request.
139 void OrphanJobs(); 138 Helper* helper_;
140 139
141 // Used to cancel all jobs in |jobs_|.
142 void CancelJobs();
143
144 // Called when a Job succeeds.
145 void OnJobSucceeded(Job* job);
146
147 const GURL url_;
148 HttpStreamFactoryImpl* const factory_;
149 WebSocketHandshakeStreamBase::CreateHelper* const 140 WebSocketHandshakeStreamBase::CreateHelper* const
150 websocket_handshake_stream_create_helper_; 141 websocket_handshake_stream_create_helper_;
151 HttpStreamRequest::Delegate* const delegate_; 142 HttpStreamRequest::Delegate* const delegate_;
152 const BoundNetLog net_log_; 143 const BoundNetLog net_log_;
153 144
154 // At the point where Job is irrevocably tied to the Request, we set this.
155 std::unique_ptr<Job> bound_job_;
156 std::set<HttpStreamFactoryImpl::Job*> jobs_;
157 std::unique_ptr<const SpdySessionKey> spdy_session_key_; 145 std::unique_ptr<const SpdySessionKey> spdy_session_key_;
158 146
159 bool completed_; 147 bool completed_;
160 bool was_npn_negotiated_; 148 bool was_npn_negotiated_;
161 // Protocol negotiated with the server. 149 // Protocol negotiated with the server.
162 NextProto protocol_negotiated_; 150 NextProto protocol_negotiated_;
163 bool using_spdy_; 151 bool using_spdy_;
164 ConnectionAttempts connection_attempts_; 152 ConnectionAttempts connection_attempts_;
165 153
166 const HttpStreamRequest::StreamType stream_type_; 154 const HttpStreamRequest::StreamType stream_type_;
167 DISALLOW_COPY_AND_ASSIGN(Request); 155 DISALLOW_COPY_AND_ASSIGN(Request);
168 }; 156 };
169 157
170 } // namespace net 158 } // namespace net
171 159
172 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 160 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller_unittest.cc ('k') | net/http/http_stream_factory_impl_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698