| 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_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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/power_monitor/power_observer.h" | 17 #include "base/power_monitor/power_observer.h" |
| 18 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
| 19 #include "net/base/load_states.h" | 19 #include "net/base/load_states.h" |
| 20 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_export.h" | 21 #include "net/base/net_export.h" |
| 21 #include "net/base/request_priority.h" | 22 #include "net/base/request_priority.h" |
| 22 #include "net/base/upload_progress.h" | 23 #include "net/base/upload_progress.h" |
| 23 #include "net/cookies/canonical_cookie.h" | 24 #include "net/cookies/canonical_cookie.h" |
| 24 #include "net/socket/connection_attempts.h" | 25 #include "net/socket/connection_attempts.h" |
| 25 #include "net/url_request/redirect_info.h" | 26 #include "net/url_request/redirect_info.h" |
| 26 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 29 namespace net { | 30 namespace net { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 272 |
| 272 // Delegates to URLRequest::Delegate. | 273 // Delegates to URLRequest::Delegate. |
| 273 bool CanEnablePrivacyMode() const; | 274 bool CanEnablePrivacyMode() const; |
| 274 | 275 |
| 275 // Notifies the job that the network is about to be used. | 276 // Notifies the job that the network is about to be used. |
| 276 void NotifyBeforeNetworkStart(bool* defer); | 277 void NotifyBeforeNetworkStart(bool* defer); |
| 277 | 278 |
| 278 // Notifies the job that headers have been received. | 279 // Notifies the job that headers have been received. |
| 279 void NotifyHeadersComplete(); | 280 void NotifyHeadersComplete(); |
| 280 | 281 |
| 281 // Notifies the request that the job has completed a Read operation. | |
| 282 void NotifyReadComplete(int bytes_read); | |
| 283 | |
| 284 // Notifies the request that a start error has occurred. | 282 // Notifies the request that a start error has occurred. |
| 285 void NotifyStartError(const URLRequestStatus& status); | 283 void NotifyStartError(const URLRequestStatus& status); |
| 286 | 284 |
| 287 // NotifyDone marks when we are done with a request. It is really | |
| 288 // a glorified set_status, but also does internal state checking and | |
| 289 // job tracking. It should be called once per request, when the job is | |
| 290 // finished doing all IO. | |
| 291 void NotifyDone(const URLRequestStatus& status); | |
| 292 | |
| 293 // Some work performed by NotifyDone must be completed on a separate task | |
| 294 // so as to avoid re-entering the delegate. This method exists to perform | |
| 295 // that work. | |
| 296 void CompleteNotifyDone(); | |
| 297 | |
| 298 // Used as an asynchronous callback for Kill to notify the URLRequest | 285 // Used as an asynchronous callback for Kill to notify the URLRequest |
| 299 // that we were canceled. | 286 // that we were canceled. |
| 300 void NotifyCanceled(); | 287 void NotifyCanceled(); |
| 301 | 288 |
| 302 // Notifies the job the request should be restarted. | 289 // Notifies the job the request should be restarted. |
| 303 // Should only be called if the job has not started a response. | 290 // Should only be called if the job has not started a response. |
| 304 void NotifyRestartRequired(); | 291 void NotifyRestartRequired(); |
| 305 | 292 |
| 306 // See corresponding functions in url_request.h. | 293 // See corresponding functions in url_request.h. |
| 307 void OnCallToDelegate(); | 294 void OnCallToDelegate(); |
| 308 void OnCallToDelegateComplete(); | 295 void OnCallToDelegateComplete(); |
| 309 | 296 |
| 310 // Called to read raw (pre-filtered) data from this Job. | 297 // Called to read raw (pre-filtered) data from this Job. Reads at most |
| 311 // If returning true, data was read from the job. buf will contain | 298 // |buf_size| bytes into |buf|. |
| 312 // the data, and bytes_read will receive the number of bytes read. | 299 // Possible return values: |
| 313 // If returning true, and bytes_read is returned as 0, there is no | 300 // >= 0: Read completed synchronously. Return value is the number of bytes |
| 314 // additional data to be read. | 301 // read. 0 means eof. |
| 315 // If returning false, an error occurred or an async IO is now pending. | 302 // ERR_IO_PENDING: Read pending asynchronously. |
| 316 // If async IO is pending, the status of the request will be | 303 // When the read completes, |ReadRawDataComplete| should be |
| 317 // URLRequestStatus::IO_PENDING, and buf must remain available until the | 304 // called. |
| 318 // operation is completed. See comments on URLRequest::Read for more | 305 // Any other negative number: Read failed synchronously. Return value is a |
| 319 // info. | 306 // network error code. |
| 320 virtual bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read); | 307 // This method might hold onto a reference to |buf| (by incrementing the |
| 308 // refcount) until the method completes or is cancelled. |
| 309 virtual int ReadRawData(IOBuffer* buf, int buf_size); |
| 321 | 310 |
| 322 // Called to tell the job that a filter has successfully reached the end of | 311 // Called to tell the job that a filter has successfully reached the end of |
| 323 // the stream. | 312 // the stream. |
| 324 virtual void DoneReading(); | 313 virtual void DoneReading(); |
| 325 | 314 |
| 326 // Called to tell the job that the body won't be read because it's a redirect. | 315 // Called to tell the job that the body won't be read because it's a redirect. |
| 327 // This is needed so that redirect headers can be cached even though their | 316 // This is needed so that redirect headers can be cached even though their |
| 328 // bodies are never read. | 317 // bodies are never read. |
| 329 virtual void DoneReadingRedirectResponse(); | 318 virtual void DoneReadingRedirectResponse(); |
| 330 | 319 |
| 331 // Informs the filter that data has been read into its buffer | 320 // Reads filtered data from the request. Returns OK if immediately successful, |
| 332 void FilteredDataRead(int bytes_read); | 321 // ERR_IO_PENDING if the request couldn't complete synchronously, and some |
| 333 | 322 // other error code if the request failed synchronously. Note that this |
| 334 // Reads filtered data from the request. Returns true if successful, | 323 // function can issue new asynchronous requests if needed, in which case it |
| 335 // false otherwise. Note, if there is not enough data received to | 324 // returns ERR_IO_PENDING. If this method completes synchronously, |
| 336 // return data, this call can issue a new async IO request under | 325 // |*bytes_read| is the number of bytes output by the filter chain if this |
| 337 // the hood. | 326 // method returns OK, or zero if this method returns an error. |
| 338 bool ReadFilteredData(int* bytes_read); | 327 Error ReadFilteredData(int* bytes_read); |
| 339 | 328 |
| 340 // Whether the response is being filtered in this job. | 329 // Whether the response is being filtered in this job. |
| 341 // Only valid after NotifyHeadersComplete() has been called. | 330 // Only valid after NotifyHeadersComplete() has been called. |
| 342 bool HasFilter() { return filter_ != NULL; } | 331 bool HasFilter() { return filter_ != NULL; } |
| 343 | 332 |
| 344 // At or near destruction time, a derived class may request that the filters | 333 // At or near destruction time, a derived class may request that the filters |
| 345 // be destroyed so that statistics can be gathered while the derived class is | 334 // be destroyed so that statistics can be gathered while the derived class is |
| 346 // still present to assist in calculations. This is used by URLRequestHttpJob | 335 // still present to assist in calculations. This is used by URLRequestHttpJob |
| 347 // to get SDCH to emit stats. | 336 // to get SDCH to emit stats. |
| 348 void DestroyFilters(); | 337 void DestroyFilters(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 360 void SetProxyServer(const HostPortPair& proxy_server); | 349 void SetProxyServer(const HostPortPair& proxy_server); |
| 361 | 350 |
| 362 // The number of bytes read before passing to the filter. This value reflects | 351 // The number of bytes read before passing to the filter. This value reflects |
| 363 // bytes read even when there is no filter. | 352 // bytes read even when there is no filter. |
| 364 int64 prefilter_bytes_read() const { return prefilter_bytes_read_; } | 353 int64 prefilter_bytes_read() const { return prefilter_bytes_read_; } |
| 365 | 354 |
| 366 // The number of bytes read after passing through the filter. This value | 355 // The number of bytes read after passing through the filter. This value |
| 367 // reflects bytes read even when there is no filter. | 356 // reflects bytes read even when there is no filter. |
| 368 int64 postfilter_bytes_read() const { return postfilter_bytes_read_; } | 357 int64 postfilter_bytes_read() const { return postfilter_bytes_read_; } |
| 369 | 358 |
| 359 // Turns an integer result code into an Error and a count of bytes read. |
| 360 // The semantics are: |
| 361 // |result| >= 0: |*error| == OK, |*count| == |result| |
| 362 // |result| < 0: |*error| = |result|, |*count| == 0 |
| 363 static void ConvertResultToError(int result, Error* error, int* count); |
| 364 |
| 365 // Completion callback for raw reads. See |ReadRawData| for details. |
| 366 // |bytes_read| is either >= 0 to indicate a successful read and count of |
| 367 // bytes read, or < 0 to indicate an error. |
| 368 void ReadRawDataComplete(int bytes_read); |
| 369 |
| 370 // The request that initiated this job. This value MAY BE NULL if the | 370 // The request that initiated this job. This value MAY BE NULL if the |
| 371 // request was released by DetachRequest(). | 371 // request was released by DetachRequest(). |
| 372 URLRequest* request_; | 372 URLRequest* request_; |
| 373 | 373 |
| 374 private: | 374 private: |
| 375 // When data filtering is enabled, this function is used to read data | 375 // When data filtering is enabled, this function is used to read data |
| 376 // for the filter. Returns true if raw data was read. Returns false if | 376 // for the filter. Returns a net error code to indicate if raw data was |
| 377 // an error occurred (or we are waiting for IO to complete). | 377 // successfully read, an error happened, or the IO is pending. |
| 378 bool ReadRawDataForFilter(int* bytes_read); | 378 Error ReadRawDataForFilter(int* bytes_read); |
| 379 |
| 380 // Informs the filter chain that data has been read into its buffer. |
| 381 void PushInputToFilter(int bytes_read); |
| 379 | 382 |
| 380 // Invokes ReadRawData and records bytes read if the read completes | 383 // Invokes ReadRawData and records bytes read if the read completes |
| 381 // synchronously. | 384 // synchronously. |
| 382 bool ReadRawDataHelper(IOBuffer* buf, int buf_size, int* bytes_read); | 385 Error ReadRawDataHelper(IOBuffer* buf, int buf_size, int* bytes_read); |
| 383 | 386 |
| 384 // Called in response to a redirect that was not canceled to follow the | 387 // Called in response to a redirect that was not canceled to follow the |
| 385 // redirect. The current job will be replaced with a new job loading the | 388 // redirect. The current job will be replaced with a new job loading the |
| 386 // given redirect destination. | 389 // given redirect destination. |
| 387 void FollowRedirect(const RedirectInfo& redirect_info); | 390 void FollowRedirect(const RedirectInfo& redirect_info); |
| 388 | 391 |
| 389 // Called after every raw read. If |bytes_read| is > 0, this indicates | 392 // Called after every raw read. If |bytes_read| is > 0, this indicates |
| 390 // a successful read of |bytes_read| unfiltered bytes. If |bytes_read| | 393 // a successful read of |bytes_read| unfiltered bytes. If |bytes_read| |
| 391 // is 0, this indicates that there is no additional data to read. If | 394 // is 0, this indicates that there is no additional data to read. |error| |
| 392 // |bytes_read| is < 0, an error occurred and no bytes were read. | 395 // specifies whether an error occurred and no bytes were read. |
| 393 void OnRawReadComplete(int bytes_read); | 396 void GatherRawReadStats(Error error, int bytes_read); |
| 394 | 397 |
| 395 // Updates the profiling info and notifies observers that an additional | 398 // Updates the profiling info and notifies observers that an additional |
| 396 // |bytes_read| unfiltered bytes have been read for this job. | 399 // |bytes_read| unfiltered bytes have been read for this job. |
| 397 void RecordBytesRead(int bytes_read); | 400 void RecordBytesRead(int bytes_read); |
| 398 | 401 |
| 399 // Called to query whether there is data available in the filter to be read | 402 // Called to query whether there is data available in the filter to be read |
| 400 // out. | 403 // out. |
| 401 bool FilterHasData(); | 404 bool FilterHasData(); |
| 402 | 405 |
| 406 // NotifyDone marks that request is done. It is really a glorified |
| 407 // set_status, but also does internal state checking and job tracking. It |
| 408 // should be called once per request, when the job is finished doing all IO. |
| 409 void NotifyDone(const URLRequestStatus& status); |
| 410 |
| 411 // Some work performed by NotifyDone must be completed asynchronously so |
| 412 // as to avoid re-entering URLRequest::Delegate. This method performs that |
| 413 // work. |
| 414 void CompleteNotifyDone(); |
| 415 |
| 403 // Subclasses may implement this method to record packet arrival times. | 416 // Subclasses may implement this method to record packet arrival times. |
| 404 // The default implementation does nothing. Only invoked when bytes have been | 417 // The default implementation does nothing. Only invoked when bytes have been |
| 405 // read since the last invocation. | 418 // read since the last invocation. |
| 406 virtual void UpdatePacketReadTimes(); | 419 virtual void UpdatePacketReadTimes(); |
| 407 | 420 |
| 408 // Computes a new RedirectInfo based on receiving a redirect response of | 421 // Computes a new RedirectInfo based on receiving a redirect response of |
| 409 // |location| and |http_status_code|. | 422 // |location| and |http_status_code|. |
| 410 RedirectInfo ComputeRedirectInfo(const GURL& location, int http_status_code); | 423 RedirectInfo ComputeRedirectInfo(const GURL& location, int http_status_code); |
| 411 | 424 |
| 412 // Notify the network delegate that more bytes have been received or sent over | 425 // Notify the network delegate that more bytes have been received or sent over |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 int64_t last_notified_total_sent_bytes_; | 477 int64_t last_notified_total_sent_bytes_; |
| 465 | 478 |
| 466 base::WeakPtrFactory<URLRequestJob> weak_factory_; | 479 base::WeakPtrFactory<URLRequestJob> weak_factory_; |
| 467 | 480 |
| 468 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); | 481 DISALLOW_COPY_AND_ASSIGN(URLRequestJob); |
| 469 }; | 482 }; |
| 470 | 483 |
| 471 } // namespace net | 484 } // namespace net |
| 472 | 485 |
| 473 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ | 486 #endif // NET_URL_REQUEST_URL_REQUEST_JOB_H_ |
| OLD | NEW |