OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/time.h" |
13 #include "net/base/filter.h" | 14 #include "net/base/filter.h" |
14 #include "net/base/load_states.h" | 15 #include "net/base/load_states.h" |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 class AuthChallengeInfo; | 18 class AuthChallengeInfo; |
18 class HttpResponseInfo; | 19 class HttpResponseInfo; |
19 class IOBuffer; | 20 class IOBuffer; |
20 class UploadData; | 21 class UploadData; |
21 } | 22 } |
22 | 23 |
23 class GURL; | 24 class GURL; |
24 class URLRequest; | 25 class URLRequest; |
25 class URLRequestStatus; | 26 class URLRequestStatus; |
26 class URLRequestJobMetrics; | 27 class URLRequestJobMetrics; |
27 | 28 |
28 // The URLRequestJob is using RefCounterThreadSafe because some sub classes | 29 // The URLRequestJob is using RefCounterThreadSafe because some sub classes |
29 // can be destroyed on multiple threads. This is the case of the | 30 // can be destroyed on multiple threads. This is the case of the |
30 // UrlRequestFileJob. | 31 // UrlRequestFileJob. |
31 class URLRequestJob : public base::RefCountedThreadSafe<URLRequestJob>, | 32 class URLRequestJob : public base::RefCountedThreadSafe<URLRequestJob>, |
32 public FilterContext { | 33 public FilterContext { |
33 public: | 34 public: |
| 35 // When histogramming results related to SDCH and/or an SDCH latency test, the |
| 36 // number of packets for which we need to record arrival times so as to |
| 37 // calculate interpacket latencies. We currently are only looking at the |
| 38 // first few packets, as we're monitoring the impact of the initial TCP |
| 39 // congestion window on stalling of transmissions. |
| 40 static const size_t kSdchPacketHistogramCount = 5; |
| 41 |
34 explicit URLRequestJob(URLRequest* request); | 42 explicit URLRequestJob(URLRequest* request); |
35 virtual ~URLRequestJob(); | 43 virtual ~URLRequestJob(); |
36 | 44 |
37 // Returns the request that owns this job. THIS POINTER MAY BE NULL if the | 45 // Returns the request that owns this job. THIS POINTER MAY BE NULL if the |
38 // request was destroyed. | 46 // request was destroyed. |
39 URLRequest* request() const { | 47 URLRequest* request() const { |
40 return request_; | 48 return request_; |
41 } | 49 } |
42 | 50 |
43 // Sets the upload data, most requests have no upload data, so this is a NOP. | 51 // Sets the upload data, most requests have no upload data, so this is a NOP. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 202 |
195 // FilterContext methods: | 203 // FilterContext methods: |
196 // These methods are not applicable to all connections. | 204 // These methods are not applicable to all connections. |
197 virtual bool GetMimeType(std::string* mime_type) const { return false; } | 205 virtual bool GetMimeType(std::string* mime_type) const { return false; } |
198 virtual bool GetURL(GURL* gurl) const; | 206 virtual bool GetURL(GURL* gurl) const; |
199 virtual base::Time GetRequestTime() const; | 207 virtual base::Time GetRequestTime() const; |
200 virtual bool IsCachedContent() const; | 208 virtual bool IsCachedContent() const; |
201 virtual int64 GetByteReadCount() const; | 209 virtual int64 GetByteReadCount() const; |
202 virtual int GetResponseCode() const { return -1; } | 210 virtual int GetResponseCode() const { return -1; } |
203 virtual int GetInputStreamBufferSize() const { return kFilterBufSize; } | 211 virtual int GetInputStreamBufferSize() const { return kFilterBufSize; } |
| 212 virtual void RecordPacketStats(StatisticSelector statistic) const; |
204 | 213 |
205 protected: | 214 protected: |
206 // Notifies the job that headers have been received. | 215 // Notifies the job that headers have been received. |
207 void NotifyHeadersComplete(); | 216 void NotifyHeadersComplete(); |
208 | 217 |
209 // Notifies the request that the job has completed a Read operation. | 218 // Notifies the request that the job has completed a Read operation. |
210 void NotifyReadComplete(int bytes_read); | 219 void NotifyReadComplete(int bytes_read); |
211 | 220 |
212 // Notifies the request that a start error has occurred. | 221 // Notifies the request that a start error has occurred. |
213 void NotifyStartError(const URLRequestStatus& status); | 222 void NotifyStartError(const URLRequestStatus& status); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 274 |
266 // Set the status of the job. | 275 // Set the status of the job. |
267 void SetStatus(const URLRequestStatus& status); | 276 void SetStatus(const URLRequestStatus& status); |
268 | 277 |
269 // Whether the job is doing performance profiling | 278 // Whether the job is doing performance profiling |
270 bool is_profiling_; | 279 bool is_profiling_; |
271 | 280 |
272 // Contains IO performance measurement when profiling is enabled. | 281 // Contains IO performance measurement when profiling is enabled. |
273 scoped_ptr<URLRequestJobMetrics> metrics_; | 282 scoped_ptr<URLRequestJobMetrics> metrics_; |
274 | 283 |
| 284 // Facilitate histogramming by turning on packet counting. |
| 285 // If called more than once, the largest value will be used. |
| 286 void EnablePacketCounting(size_t max_packets_timed); |
| 287 |
275 private: | 288 private: |
276 // Size of filter input buffers used by this class. | 289 // Size of filter input buffers used by this class. |
277 static const int kFilterBufSize; | 290 static const int kFilterBufSize; |
278 | 291 |
279 // When data filtering is enabled, this function is used to read data | 292 // When data filtering is enabled, this function is used to read data |
280 // for the filter. Returns true if raw data was read. Returns false if | 293 // for the filter. Returns true if raw data was read. Returns false if |
281 // an error occurred (or we are waiting for IO to complete). | 294 // an error occurred (or we are waiting for IO to complete). |
282 bool ReadRawDataForFilter(int *bytes_read); | 295 bool ReadRawDataForFilter(int *bytes_read); |
283 | 296 |
284 // Called in response to a redirect that was not canceled to follow the | 297 // Called in response to a redirect that was not canceled to follow the |
285 // redirect. The current job will be replaced with a new job loading the | 298 // redirect. The current job will be replaced with a new job loading the |
286 // given redirect destination. | 299 // given redirect destination. |
287 void FollowRedirect(const GURL& location, int http_status_code); | 300 void FollowRedirect(const GURL& location, int http_status_code); |
288 | 301 |
289 // Updates the profiling info and notifies observers that bytes_read bytes | 302 // Updates the profiling info and notifies observers that bytes_read bytes |
290 // have been read. | 303 // have been read. |
291 void RecordBytesRead(int bytes_read); | 304 void RecordBytesRead(int bytes_read); |
292 | 305 |
293 private: | |
294 // Called to query whether there is data available in the filter to be read | 306 // Called to query whether there is data available in the filter to be read |
295 // out. | 307 // out. |
296 bool FilterHasData(); | 308 bool FilterHasData(); |
297 | 309 |
| 310 // Record packet arrival times for possible use in histograms. |
| 311 void UpdatePacketReadTimes(); |
| 312 |
298 // Indicates that the job is done producing data, either it has completed | 313 // Indicates that the job is done producing data, either it has completed |
299 // all the data or an error has been encountered. Set exclusively by | 314 // all the data or an error has been encountered. Set exclusively by |
300 // NotifyDone so that it is kept in sync with the request. | 315 // NotifyDone so that it is kept in sync with the request. |
301 bool done_; | 316 bool done_; |
302 | 317 |
303 // Cache the load flags from request_ because it might go away. | 318 // Cache the load flags from request_ because it might go away. |
304 int load_flags_; | 319 int load_flags_; |
305 | 320 |
306 // The data stream filter which is enabled on demand. | 321 // The data stream filter which is enabled on demand. |
307 scoped_ptr<Filter> filter_; | 322 scoped_ptr<Filter> filter_; |
308 | 323 |
309 // If the filter filled its output buffer, then there is a change that it | 324 // If the filter filled its output buffer, then there is a change that it |
310 // still has internal data to emit, and this flag is set. | 325 // still has internal data to emit, and this flag is set. |
311 bool filter_needs_more_output_space_; | 326 bool filter_needs_more_output_space_; |
312 | 327 |
313 // When we filter data, we receive data into the filter buffers. After | 328 // When we filter data, we receive data into the filter buffers. After |
314 // processing the filtered data, we return the data in the caller's buffer. | 329 // processing the filtered data, we return the data in the caller's buffer. |
315 // While the async IO is in progress, we save the user buffer here, and | 330 // While the async IO is in progress, we save the user buffer here, and |
316 // when the IO completes, we fill this in. | 331 // when the IO completes, we fill this in. |
317 net::IOBuffer *read_buffer_; | 332 net::IOBuffer *read_buffer_; |
318 int read_buffer_len_; | 333 int read_buffer_len_; |
319 | 334 |
320 // Used by HandleResponseIfNecessary to track whether we've sent the | 335 // Used by HandleResponseIfNecessary to track whether we've sent the |
321 // OnResponseStarted callback and potentially redirect callbacks as well. | 336 // OnResponseStarted callback and potentially redirect callbacks as well. |
322 bool has_handled_response_; | 337 bool has_handled_response_; |
323 | 338 |
324 // Expected content size | 339 // Expected content size |
325 int64 expected_content_size_; | 340 int64 expected_content_size_; |
326 | 341 |
| 342 //---------------------------------------------------------------------------- |
| 343 // Data used for statistics gathering in some instances. This data is only |
| 344 // used for histograms etc., and is not required. It is optionally gathered |
| 345 // based on the settings of several control variables. |
| 346 |
| 347 // Enable recording of packet arrival times for histogramming. |
| 348 bool packet_timing_enabled_; |
| 349 |
| 350 // TODO(jar): improve the quality of the gathered info by gathering most times |
| 351 // at a lower point in the network stack, assuring we have actual packet |
| 352 // boundaries, rather than approximations. Also note that input byte count |
| 353 // as gathered here is post-SSL, and post-cache-fetch, and does not reflect |
| 354 // true packet arrival times in such cases. |
| 355 |
327 // Total number of bytes read from network (or cache) and and typically handed | 356 // Total number of bytes read from network (or cache) and and typically handed |
328 // to filter to process. Used to histogram compression ratios, and error | 357 // to filter to process. Used to histogram compression ratios, and error |
329 // recovery scenarios in filters. | 358 // recovery scenarios in filters. |
330 int64 filter_input_byte_count_; | 359 int64 filter_input_byte_count_; |
331 | 360 |
| 361 // The number of bytes that have been accounted for in packets (where some of |
| 362 // those packets may possibly have had their time of arrival recorded). |
| 363 int64 bytes_observed_in_packets_; |
| 364 |
| 365 // Limit on the size of the array packet_times_. This can be set to |
| 366 // zero, and then no packet times will be gathered. |
| 367 size_t max_packets_timed_; |
| 368 |
| 369 // Arrival times for some of the first few packets. |
| 370 std::vector<base::Time> packet_times_; |
| 371 |
| 372 // The request time may not be available when we are being destroyed, so we |
| 373 // snapshot it early on. |
| 374 base::Time request_time_snapshot_; |
| 375 |
| 376 // Since we don't save all packet times in packet_times_, we save the |
| 377 // last time for use in histograms. |
| 378 base::Time final_packet_time_; |
| 379 |
| 380 // The count of the number of packets, some of which may not have been timed. |
| 381 // We're ignoring overflow, as 1430 x 2^31 is a LOT of bytes. |
| 382 int observed_packet_count_; |
| 383 |
332 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); | 384 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); |
333 }; | 385 }; |
334 | 386 |
335 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 387 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
OLD | NEW |