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: comment/naming fix Created 4 years, 7 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/http/http_stream_factory_impl.h" 12 #include "net/http/http_stream_factory_impl.h"
13 #include "net/log/net_log.h" 13 #include "net/log/net_log.h"
14 #include "net/socket/connection_attempts.h" 14 #include "net/socket/connection_attempts.h"
15 #include "net/socket/ssl_client_socket.h" 15 #include "net/socket/ssl_client_socket.h"
16 #include "net/spdy/spdy_session_key.h" 16 #include "net/spdy/spdy_session_key.h"
17 #include "net/ssl/ssl_failure_state.h" 17 #include "net/ssl/ssl_failure_state.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 namespace net { 20 namespace net {
21 21
22 class BidirectionalStreamImpl; 22 class BidirectionalStreamImpl;
23 class ClientSocketHandle; 23 class ClientSocketHandle;
24 class HttpStream; 24 class HttpStream;
25 class SpdySession; 25 class SpdySession;
26 26
27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { 27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest {
28 public: 28 public:
29 // Request will notify |job_controller| when it's destructed.
30 // Thus |job_controller| is valid for the lifetime of the |this| Request.
29 Request(const GURL& url, 31 Request(const GURL& url,
30 HttpStreamFactoryImpl* factory, 32 JobController* job_controller,
31 HttpStreamRequest::Delegate* delegate, 33 HttpStreamRequest::Delegate* delegate,
32 WebSocketHandshakeStreamBase::CreateHelper* 34 WebSocketHandshakeStreamBase::CreateHelper*
33 websocket_handshake_stream_create_helper, 35 websocket_handshake_stream_create_helper,
34 const BoundNetLog& net_log, 36 const BoundNetLog& net_log,
35 StreamType stream_type); 37 StreamType stream_type);
36 38
37 ~Request() override; 39 ~Request() override;
38 40
39 // The GURL from the HttpRequestInfo the started the Request. 41 // The GURL from the HttpRequestInfo the started the Request.
40 const GURL& url() const { return url_; } 42 const GURL& url() const { return url_; }
41 43
42 const BoundNetLog& net_log() const { return net_log_; } 44 const BoundNetLog& net_log() const { return net_log_; }
43 45
44 // Called when the Job determines the appropriate |spdy_session_key| for the 46 // Called when the JobController determines the appropriate |spdy_session_key|
45 // Request. Note that this does not mean that SPDY is necessarily supported 47 // 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 48 // supported for this SpdySessionKey, since we may need to wait for NPN to
47 // before knowing if SPDY is available. 49 // complete before knowing if SPDY is available.
48 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); 50 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key);
49 bool HasSpdySessionKey() const; 51 bool HasSpdySessionKey() const;
50 52
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(). 53 // Marks completion of the request. Must be called before OnStreamReady().
56 void Complete(bool was_npn_negotiated, 54 void Complete(bool was_npn_negotiated,
57 NextProto protocol_negotiated, 55 NextProto protocol_negotiated,
58 bool using_spdy); 56 bool using_spdy);
59 57
60 // If this Request has a |spdy_session_key_|, remove this session from the 58 void ResetSpdySessionKey();
61 // SpdySessionRequestMap.
62 void RemoveRequestFromSpdySessionRequestMap();
63 59
64 // Called by an attached Job if it sets up a SpdySession. 60 // Called by JobController to record connection attempts made by the socket
65 // |stream| is null when |stream_type| is HttpStreamRequest::HTTP_STREAM. 61 // 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); 62 void AddConnectionAttempts(const ConnectionAttempts& attempts);
78 63
79 WebSocketHandshakeStreamBase::CreateHelper* 64 WebSocketHandshakeStreamBase::CreateHelper*
80 websocket_handshake_stream_create_helper() { 65 websocket_handshake_stream_create_helper() {
81 return websocket_handshake_stream_create_helper_; 66 return websocket_handshake_stream_create_helper_;
82 } 67 }
83 68
84 // HttpStreamRequest::Delegate methods which we implement. Note we don't 69 // HttpStreamRequest::Delegate methods which we implement. Note we don't
85 // actually subclass HttpStreamRequest::Delegate. 70 // actually subclass HttpStreamRequest::Delegate.
86 71
87 void OnStreamReady(Job* job, 72 void OnStreamReady(const SSLConfig& used_ssl_config,
88 const SSLConfig& used_ssl_config,
89 const ProxyInfo& used_proxy_info, 73 const ProxyInfo& used_proxy_info,
90 HttpStream* stream); 74 HttpStream* stream);
91 void OnBidirectionalStreamImplReady(Job* job, 75 void OnBidirectionalStreamImplReady(const SSLConfig& used_ssl_config,
92 const SSLConfig& used_ssl_config,
93 const ProxyInfo& used_proxy_info, 76 const ProxyInfo& used_proxy_info,
94 BidirectionalStreamImpl* stream); 77 BidirectionalStreamImpl* stream);
95 78
96 void OnWebSocketHandshakeStreamReady(Job* job, 79 void OnWebSocketHandshakeStreamReady(const SSLConfig& used_ssl_config,
97 const SSLConfig& used_ssl_config,
98 const ProxyInfo& used_proxy_info, 80 const ProxyInfo& used_proxy_info,
99 WebSocketHandshakeStreamBase* stream); 81 WebSocketHandshakeStreamBase* stream);
100 void OnStreamFailed(Job* job, 82 void OnStreamFailed(int status,
101 int status,
102 const SSLConfig& used_ssl_config, 83 const SSLConfig& used_ssl_config,
103 SSLFailureState ssl_failure_state); 84 SSLFailureState ssl_failure_state);
104 void OnCertificateError(Job* job, 85 void OnCertificateError(int status,
105 int status,
106 const SSLConfig& used_ssl_config, 86 const SSLConfig& used_ssl_config,
107 const SSLInfo& ssl_info); 87 const SSLInfo& ssl_info);
108 void OnNeedsProxyAuth(Job* job, 88 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
109 const HttpResponseInfo& proxy_response,
110 const SSLConfig& used_ssl_config, 89 const SSLConfig& used_ssl_config,
111 const ProxyInfo& used_proxy_info, 90 const ProxyInfo& used_proxy_info,
112 HttpAuthController* auth_controller); 91 HttpAuthController* auth_controller);
113 void OnNeedsClientAuth(Job* job, 92 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
114 const SSLConfig& used_ssl_config,
115 SSLCertRequestInfo* cert_info); 93 SSLCertRequestInfo* cert_info);
116 void OnHttpsProxyTunnelResponse( 94 void OnHttpsProxyTunnelResponse(
117 Job *job,
118 const HttpResponseInfo& response_info, 95 const HttpResponseInfo& response_info,
119 const SSLConfig& used_ssl_config, 96 const SSLConfig& used_ssl_config,
120 const ProxyInfo& used_proxy_info, 97 const ProxyInfo& used_proxy_info,
121 HttpStream* stream); 98 HttpStream* stream);
122 99
123 // HttpStreamRequest methods. 100 // HttpStreamRequest methods.
124 101
125 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; 102 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override;
126 void SetPriority(RequestPriority priority) override; 103 void SetPriority(RequestPriority priority) override;
127 LoadState GetLoadState() const override; 104 LoadState GetLoadState() const override;
128 bool was_npn_negotiated() const override; 105 bool was_npn_negotiated() const override;
129 NextProto protocol_negotiated() const override; 106 NextProto protocol_negotiated() const override;
130 bool using_spdy() const override; 107 bool using_spdy() const override;
131 const ConnectionAttempts& connection_attempts() const override; 108 const ConnectionAttempts& connection_attempts() const override;
132 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } 109 HttpStreamRequest::StreamType stream_type() const { return stream_type_; }
110 const SpdySessionKey* spdy_session_key() const {
111 return spdy_session_key_.get();
112 }
133 113
134 private: 114 private:
135 // Used to bind |job| to the request and orphan all other jobs in |jobs_|. 115 const GURL url_;
136 void BindJob(Job* job);
137 116
138 // Used to orphan all jobs in |jobs_|. 117 // Unowned.
139 void OrphanJobs(); 118 // Safe pointer as |this| Request doesn't outlive the |job_controller_|.
119 JobController* const job_controller_;
140 120
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 121 WebSocketHandshakeStreamBase::CreateHelper* const
150 websocket_handshake_stream_create_helper_; 122 websocket_handshake_stream_create_helper_;
151 HttpStreamRequest::Delegate* const delegate_; 123 HttpStreamRequest::Delegate* const delegate_;
152 const BoundNetLog net_log_; 124 const BoundNetLog net_log_;
153 125
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_; 126 std::unique_ptr<const SpdySessionKey> spdy_session_key_;
158 127
159 bool completed_; 128 bool completed_;
160 bool was_npn_negotiated_; 129 bool was_npn_negotiated_;
161 // Protocol negotiated with the server. 130 // Protocol negotiated with the server.
162 NextProto protocol_negotiated_; 131 NextProto protocol_negotiated_;
163 bool using_spdy_; 132 bool using_spdy_;
164 ConnectionAttempts connection_attempts_; 133 ConnectionAttempts connection_attempts_;
165 134
166 const HttpStreamRequest::StreamType stream_type_; 135 const HttpStreamRequest::StreamType stream_type_;
167 DISALLOW_COPY_AND_ASSIGN(Request); 136 DISALLOW_COPY_AND_ASSIGN(Request);
168 }; 137 };
169 138
170 } // namespace net 139 } // namespace net
171 140
172 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ 141 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698