OLD | NEW |
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_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "net/base/auth.h" | 15 #include "net/base/auth.h" |
16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 #include "net/base/net_export.h" |
17 #include "net/cookies/cookie_store.h" | 18 #include "net/cookies/cookie_store.h" |
18 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
19 #include "net/url_request/url_request_job.h" | 20 #include "net/url_request/url_request_job.h" |
20 #include "net/url_request/url_request_throttler_entry_interface.h" | 21 #include "net/url_request/url_request_throttler_entry_interface.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 | 24 |
24 class HttpResponseHeaders; | 25 class HttpResponseHeaders; |
25 class HttpResponseInfo; | 26 class HttpResponseInfo; |
26 class HttpTransaction; | 27 class HttpTransaction; |
27 class HttpUserAgentSettings; | 28 class HttpUserAgentSettings; |
28 class UploadDataStream; | 29 class UploadDataStream; |
29 class URLRequestContext; | 30 class URLRequestContext; |
30 | 31 |
31 // A URLRequestJob subclass that is built on top of HttpTransaction. It | 32 // A URLRequestJob subclass that is built on top of HttpTransaction. It |
32 // provides an implementation for both HTTP and HTTPS. | 33 // provides an implementation for both HTTP and HTTPS. |
33 class URLRequestHttpJob : public URLRequestJob { | 34 class NET_EXPORT_PRIVATE URLRequestHttpJob : public URLRequestJob { |
34 public: | 35 public: |
35 static URLRequestJob* Factory(URLRequest* request, | 36 static URLRequestJob* Factory(URLRequest* request, |
36 NetworkDelegate* network_delegate, | 37 NetworkDelegate* network_delegate, |
37 const std::string& scheme); | 38 const std::string& scheme); |
38 | 39 |
39 protected: | 40 protected: |
40 URLRequestHttpJob(URLRequest* request, | 41 URLRequestHttpJob(URLRequest* request, |
41 NetworkDelegate* network_delegate, | 42 NetworkDelegate* network_delegate, |
42 const HttpUserAgentSettings* http_user_agent_settings); | 43 const HttpUserAgentSettings* http_user_agent_settings); |
43 | 44 |
| 45 virtual ~URLRequestHttpJob(); |
| 46 |
| 47 // Overridden from URLRequestJob: |
| 48 virtual void SetPriority(RequestPriority priority) OVERRIDE; |
| 49 virtual void Start() OVERRIDE; |
| 50 virtual void Kill() OVERRIDE; |
| 51 |
| 52 RequestPriority priority() const { |
| 53 return priority_; |
| 54 } |
| 55 |
| 56 private: |
| 57 enum CompletionCause { |
| 58 ABORTED, |
| 59 FINISHED |
| 60 }; |
| 61 |
| 62 typedef base::RefCountedData<bool> SharedBoolean; |
| 63 |
| 64 class HttpFilterContext; |
| 65 class HttpTransactionDelegateImpl; |
| 66 |
44 // Shadows URLRequestJob's version of this method so we can grab cookies. | 67 // Shadows URLRequestJob's version of this method so we can grab cookies. |
45 void NotifyHeadersComplete(); | 68 void NotifyHeadersComplete(); |
46 | 69 |
47 // Shadows URLRequestJob's method so we can record histograms. | 70 // Shadows URLRequestJob's method so we can record histograms. |
48 void NotifyDone(const URLRequestStatus& status); | 71 void NotifyDone(const URLRequestStatus& status); |
49 | 72 |
50 void DestroyTransaction(); | 73 void DestroyTransaction(); |
51 | 74 |
52 void AddExtraHeaders(); | 75 void AddExtraHeaders(); |
53 void AddCookieHeaderAndStart(); | 76 void AddCookieHeaderAndStart(); |
(...skipping 12 matching lines...) Expand all Loading... |
66 void OnStartCompleted(int result); | 89 void OnStartCompleted(int result); |
67 void OnReadCompleted(int result); | 90 void OnReadCompleted(int result); |
68 void NotifyBeforeSendHeadersCallback(int result); | 91 void NotifyBeforeSendHeadersCallback(int result); |
69 | 92 |
70 void RestartTransactionWithAuth(const AuthCredentials& credentials); | 93 void RestartTransactionWithAuth(const AuthCredentials& credentials); |
71 | 94 |
72 // Overridden from URLRequestJob: | 95 // Overridden from URLRequestJob: |
73 virtual void SetUpload(UploadDataStream* upload) OVERRIDE; | 96 virtual void SetUpload(UploadDataStream* upload) OVERRIDE; |
74 virtual void SetExtraRequestHeaders( | 97 virtual void SetExtraRequestHeaders( |
75 const HttpRequestHeaders& headers) OVERRIDE; | 98 const HttpRequestHeaders& headers) OVERRIDE; |
76 virtual void Start() OVERRIDE; | |
77 virtual void Kill() OVERRIDE; | |
78 virtual LoadState GetLoadState() const OVERRIDE; | 99 virtual LoadState GetLoadState() const OVERRIDE; |
79 virtual UploadProgress GetUploadProgress() const OVERRIDE; | 100 virtual UploadProgress GetUploadProgress() const OVERRIDE; |
80 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 101 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
81 virtual bool GetCharset(std::string* charset) OVERRIDE; | 102 virtual bool GetCharset(std::string* charset) OVERRIDE; |
82 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; | 103 virtual void GetResponseInfo(HttpResponseInfo* info) OVERRIDE; |
83 virtual void GetLoadTimingInfo( | 104 virtual void GetLoadTimingInfo( |
84 LoadTimingInfo* load_timing_info) const OVERRIDE; | 105 LoadTimingInfo* load_timing_info) const OVERRIDE; |
85 virtual bool GetResponseCookies(std::vector<std::string>* cookies) OVERRIDE; | 106 virtual bool GetResponseCookies(std::vector<std::string>* cookies) OVERRIDE; |
86 virtual int GetResponseCode() const OVERRIDE; | 107 virtual int GetResponseCode() const OVERRIDE; |
87 virtual Filter* SetupFilter() const OVERRIDE; | 108 virtual Filter* SetupFilter() const OVERRIDE; |
88 virtual bool IsSafeRedirect(const GURL& location) OVERRIDE; | 109 virtual bool IsSafeRedirect(const GURL& location) OVERRIDE; |
89 virtual bool NeedsAuth() OVERRIDE; | 110 virtual bool NeedsAuth() OVERRIDE; |
90 virtual void GetAuthChallengeInfo(scoped_refptr<AuthChallengeInfo>*) OVERRIDE; | 111 virtual void GetAuthChallengeInfo(scoped_refptr<AuthChallengeInfo>*) OVERRIDE; |
91 virtual void SetAuth(const AuthCredentials& credentials) OVERRIDE; | 112 virtual void SetAuth(const AuthCredentials& credentials) OVERRIDE; |
92 virtual void CancelAuth() OVERRIDE; | 113 virtual void CancelAuth() OVERRIDE; |
93 virtual void ContinueWithCertificate(X509Certificate* client_cert) OVERRIDE; | 114 virtual void ContinueWithCertificate(X509Certificate* client_cert) OVERRIDE; |
94 virtual void ContinueDespiteLastError() OVERRIDE; | 115 virtual void ContinueDespiteLastError() OVERRIDE; |
95 virtual bool ReadRawData(IOBuffer* buf, int buf_size, | 116 virtual bool ReadRawData(IOBuffer* buf, int buf_size, |
96 int* bytes_read) OVERRIDE; | 117 int* bytes_read) OVERRIDE; |
97 virtual void StopCaching() OVERRIDE; | 118 virtual void StopCaching() OVERRIDE; |
98 virtual void DoneReading() OVERRIDE; | 119 virtual void DoneReading() OVERRIDE; |
99 virtual HostPortPair GetSocketAddress() const OVERRIDE; | 120 virtual HostPortPair GetSocketAddress() const OVERRIDE; |
100 virtual void NotifyURLRequestDestroyed() OVERRIDE; | 121 virtual void NotifyURLRequestDestroyed() OVERRIDE; |
101 | 122 |
102 HttpRequestInfo request_info_; | |
103 const HttpResponseInfo* response_info_; | |
104 | |
105 std::vector<std::string> response_cookies_; | |
106 size_t response_cookies_save_index_; | |
107 base::Time response_date_; | |
108 | |
109 // Auth states for proxy and origin server. | |
110 AuthState proxy_auth_state_; | |
111 AuthState server_auth_state_; | |
112 AuthCredentials auth_credentials_; | |
113 | |
114 CompletionCallback start_callback_; | |
115 CompletionCallback notify_before_headers_sent_callback_; | |
116 | |
117 bool read_in_progress_; | |
118 | |
119 // An URL for an SDCH dictionary as suggested in a Get-Dictionary HTTP header. | |
120 GURL sdch_dictionary_url_; | |
121 | |
122 scoped_ptr<HttpTransaction> transaction_; | |
123 | |
124 // This is used to supervise traffic and enforce exponential | |
125 // back-off. May be NULL. | |
126 scoped_refptr<URLRequestThrottlerEntryInterface> throttling_entry_; | |
127 | |
128 // Indicated if an SDCH dictionary was advertised, and hence an SDCH | |
129 // compressed response is expected. We use this to help detect (accidental?) | |
130 // proxy corruption of a response, which sometimes marks SDCH content as | |
131 // having no content encoding <oops>. | |
132 bool sdch_dictionary_advertised_; | |
133 | |
134 // For SDCH latency experiments, when we are able to do SDCH, we may enable | |
135 // either an SDCH latency test xor a pass through test. The following bools | |
136 // indicate what we decided on for this instance. | |
137 bool sdch_test_activated_; // Advertising a dictionary for sdch. | |
138 bool sdch_test_control_; // Not even accepting-content sdch. | |
139 | |
140 // For recording of stats, we need to remember if this is cached content. | |
141 bool is_cached_content_; | |
142 | |
143 private: | |
144 enum CompletionCause { | |
145 ABORTED, | |
146 FINISHED | |
147 }; | |
148 | |
149 typedef base::RefCountedData<bool> SharedBoolean; | |
150 | |
151 class HttpFilterContext; | |
152 class HttpTransactionDelegateImpl; | |
153 | |
154 virtual ~URLRequestHttpJob(); | |
155 | |
156 void RecordTimer(); | 123 void RecordTimer(); |
157 void ResetTimer(); | 124 void ResetTimer(); |
158 | 125 |
159 virtual void UpdatePacketReadTimes() OVERRIDE; | 126 virtual void UpdatePacketReadTimes() OVERRIDE; |
160 void RecordPacketStats(FilterContext::StatisticSelector statistic) const; | 127 void RecordPacketStats(FilterContext::StatisticSelector statistic) const; |
161 | 128 |
162 void RecordCompressionHistograms(); | 129 void RecordCompressionHistograms(); |
163 bool IsCompressibleContent() const; | 130 bool IsCompressibleContent() const; |
164 | 131 |
165 // Starts the transaction if extensions using the webrequest API do not | 132 // Starts the transaction if extensions using the webrequest API do not |
(...skipping 26 matching lines...) Expand all Loading... |
192 // of bytes read or, if negative, an error code. | 159 // of bytes read or, if negative, an error code. |
193 bool ShouldFixMismatchedContentLength(int rv) const; | 160 bool ShouldFixMismatchedContentLength(int rv) const; |
194 | 161 |
195 // Returns the effective response headers, considering that they may be | 162 // Returns the effective response headers, considering that they may be |
196 // overridden by |override_response_headers_|. | 163 // overridden by |override_response_headers_|. |
197 HttpResponseHeaders* GetResponseHeaders() const; | 164 HttpResponseHeaders* GetResponseHeaders() const; |
198 | 165 |
199 // Override of the private interface of URLRequestJob. | 166 // Override of the private interface of URLRequestJob. |
200 virtual void OnDetachRequest() OVERRIDE; | 167 virtual void OnDetachRequest() OVERRIDE; |
201 | 168 |
| 169 RequestPriority priority_; |
| 170 |
| 171 HttpRequestInfo request_info_; |
| 172 const HttpResponseInfo* response_info_; |
| 173 |
| 174 std::vector<std::string> response_cookies_; |
| 175 size_t response_cookies_save_index_; |
| 176 base::Time response_date_; |
| 177 |
| 178 // Auth states for proxy and origin server. |
| 179 AuthState proxy_auth_state_; |
| 180 AuthState server_auth_state_; |
| 181 AuthCredentials auth_credentials_; |
| 182 |
| 183 CompletionCallback start_callback_; |
| 184 CompletionCallback notify_before_headers_sent_callback_; |
| 185 |
| 186 bool read_in_progress_; |
| 187 |
| 188 // An URL for an SDCH dictionary as suggested in a Get-Dictionary HTTP header. |
| 189 GURL sdch_dictionary_url_; |
| 190 |
| 191 scoped_ptr<HttpTransaction> transaction_; |
| 192 |
| 193 // This is used to supervise traffic and enforce exponential |
| 194 // back-off. May be NULL. |
| 195 scoped_refptr<URLRequestThrottlerEntryInterface> throttling_entry_; |
| 196 |
| 197 // Indicated if an SDCH dictionary was advertised, and hence an SDCH |
| 198 // compressed response is expected. We use this to help detect (accidental?) |
| 199 // proxy corruption of a response, which sometimes marks SDCH content as |
| 200 // having no content encoding <oops>. |
| 201 bool sdch_dictionary_advertised_; |
| 202 |
| 203 // For SDCH latency experiments, when we are able to do SDCH, we may enable |
| 204 // either an SDCH latency test xor a pass through test. The following bools |
| 205 // indicate what we decided on for this instance. |
| 206 bool sdch_test_activated_; // Advertising a dictionary for sdch. |
| 207 bool sdch_test_control_; // Not even accepting-content sdch. |
| 208 |
| 209 // For recording of stats, we need to remember if this is cached content. |
| 210 bool is_cached_content_; |
| 211 |
202 base::Time request_creation_time_; | 212 base::Time request_creation_time_; |
203 | 213 |
204 // Data used for statistics gathering. This data is only used for histograms | 214 // Data used for statistics gathering. This data is only used for histograms |
205 // and is not required. It is only gathered if packet_timing_enabled_ == true. | 215 // and is not required. It is only gathered if packet_timing_enabled_ == true. |
206 // | 216 // |
207 // TODO(jar): improve the quality of the gathered info by gathering most times | 217 // TODO(jar): improve the quality of the gathered info by gathering most times |
208 // at a lower point in the network stack, assuring we have actual packet | 218 // at a lower point in the network stack, assuring we have actual packet |
209 // boundaries, rather than approximations. Also note that input byte count | 219 // boundaries, rather than approximations. Also note that input byte count |
210 // as gathered here is post-SSL, and post-cache-fetch, and does not reflect | 220 // as gathered here is post-SSL, and post-cache-fetch, and does not reflect |
211 // true packet arrival times in such cases. | 221 // true packet arrival times in such cases. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 scoped_ptr<HttpTransactionDelegateImpl> http_transaction_delegate_; | 259 scoped_ptr<HttpTransactionDelegateImpl> http_transaction_delegate_; |
250 | 260 |
251 const HttpUserAgentSettings* http_user_agent_settings_; | 261 const HttpUserAgentSettings* http_user_agent_settings_; |
252 | 262 |
253 DISALLOW_COPY_AND_ASSIGN(URLRequestHttpJob); | 263 DISALLOW_COPY_AND_ASSIGN(URLRequestHttpJob); |
254 }; | 264 }; |
255 | 265 |
256 } // namespace net | 266 } // namespace net |
257 | 267 |
258 #endif // NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ | 268 #endif // NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ |
OLD | NEW |