Chromium Code Reviews| Index: net/url_request/url_request_job.h |
| diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h |
| index beae02111bde59587c9705d5f6799a821372c390..284c8b9545d23ef87ab5277025ec6a1f4e3bd577 100644 |
| --- a/net/url_request/url_request_job.h |
| +++ b/net/url_request/url_request_job.h |
| @@ -22,6 +22,7 @@ |
| #include "net/base/request_priority.h" |
| #include "net/base/upload_progress.h" |
| #include "net/cookies/canonical_cookie.h" |
| +#include "net/filter/stream_source.h" |
| #include "net/socket/connection_attempts.h" |
| #include "net/url_request/redirect_info.h" |
| #include "net/url_request/url_request.h" |
| @@ -47,6 +48,7 @@ class X509Certificate; |
| class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| public: |
| + typedef base::Callback<void(net::Error, size_t)> ReadRawCompleteCallback; |
|
mmenke
2016/07/21 18:14:10
Is this even used?
If not, remove it.
If so, nee
xunjieli
2016/07/27 20:32:04
Done. Sorry, it isn't used.
|
| explicit URLRequestJob(URLRequest* request, |
| NetworkDelegate* network_delegate); |
| ~URLRequestJob() override; |
| @@ -143,13 +145,11 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // network stack makes the request to. |
| virtual void PopulateNetErrorDetails(NetErrorDetails* details) const; |
| - // Called to setup a stream filter for this request. An example of filter is |
| - // content encoding/decoding. |
| - // Subclasses should return the appropriate Filter, or NULL for no Filter. |
| - // This class takes ownership of the returned Filter. |
| - // |
| - // The default implementation returns NULL. |
| - virtual std::unique_ptr<Filter> SetupFilter() const; |
| + // Called to set up a StreamSource chain for this request. |
| + // Subclasses should return the appropriate first StreamSource of the chain, |
| + // or nullptr if no StreamSource should be used. This class takes ownership of |
|
mmenke
2016/07/21 18:14:10
"... or nullptr on error"?
xunjieli
2016/07/27 20:32:04
Done.
|
| + // the returned StreamSource. |
| + virtual std::unique_ptr<StreamSource> SetupSource(); |
|
mmenke
2016/07/21 18:14:10
This should be private, right? It's an old commen
xunjieli
2016/07/27 20:32:05
Do you mean protected instead? The subclasses (htt
mmenke
2016/07/28 18:40:12
Oops...I didn't realize subclasses recursively cal
|
| // Called to determine if this response is a redirect. Only makes sense |
| // for some types of requests. This method returns true if the response |
| @@ -216,10 +216,6 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // Whether we have processed the response for that request yet. |
| bool has_response_started() const { return has_handled_response_; } |
| - // The number of bytes read before passing to the filter. This value reflects |
| - // bytes read even when there is no filter. |
| - int64_t prefilter_bytes_read() const { return prefilter_bytes_read_; } |
| - |
| // These methods are not applicable to all connections. |
| virtual bool GetMimeType(std::string* mime_type) const; |
| virtual int GetResponseCode() const; |
| @@ -248,8 +244,16 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| static GURL ComputeReferrerForRedirect(URLRequest::ReferrerPolicy policy, |
| const std::string& referrer, |
| const GURL& redirect_destination); |
| + // The number of bytes read before passing to the filter. This value reflects |
| + // bytes read even when there is no filter. |
| + int64_t prefilter_bytes_read() const; |
| protected: |
| + // Helper method used to perform tasks after reading from |source_| is |
| + // completed. |synchronous| true if the read completed synchronously. |
| + // See the documentation for |Read| above for the contract of this method. |
| + void SourceReadComplete(bool synchronous, int result); |
| + |
| // Notifies the job that a certificate is requested. |
| void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info); |
| @@ -307,25 +311,6 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // bodies are never read. |
| virtual void DoneReadingRedirectResponse(); |
| - // Reads filtered data from the request. Returns OK if immediately successful, |
| - // ERR_IO_PENDING if the request couldn't complete synchronously, and some |
| - // other error code if the request failed synchronously. Note that this |
| - // function can issue new asynchronous requests if needed, in which case it |
| - // returns ERR_IO_PENDING. If this method completes synchronously, |
| - // |*bytes_read| is the number of bytes output by the filter chain if this |
| - // method returns OK, or zero if this method returns an error. |
| - Error ReadFilteredData(int* bytes_read); |
| - |
| - // Whether the response is being filtered in this job. |
| - // Only valid after NotifyHeadersComplete() has been called. |
| - bool HasFilter() { return filter_ != NULL; } |
| - |
| - // At or near destruction time, a derived class may request that the filters |
| - // be destroyed so that statistics can be gathered while the derived class is |
| - // still present to assist in calculations. This is used by URLRequestHttpJob |
| - // to get SDCH to emit stats. |
| - void DestroyFilters(); |
| - |
| // Provides derived classes with access to the request's network delegate. |
| NetworkDelegate* network_delegate() { return network_delegate_; } |
| @@ -337,7 +322,7 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // The number of bytes read after passing through the filter. This value |
| // reflects bytes read even when there is no filter. |
| - int64_t postfilter_bytes_read() const { return postfilter_bytes_read_; } |
| + int64_t postfilter_bytes_read() const; |
| // Turns an integer result code into an Error and a count of bytes read. |
| // The semantics are: |
| @@ -354,21 +339,16 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| URLRequest* request_; |
| private: |
| + class URLRequestJobStreamSource; |
| // Set the status of the associated URLRequest. |
| // TODO(mmenke): Make the URLRequest manage its own status. |
| void SetStatus(const URLRequestStatus& status); |
| - // When data filtering is enabled, this function is used to read data |
| - // for the filter. Returns a net error code to indicate if raw data was |
| - // successfully read, an error happened, or the IO is pending. |
| - Error ReadRawDataForFilter(int* bytes_read); |
| - |
| - // Informs the filter chain that data has been read into its buffer. |
| - void PushInputToFilter(int bytes_read); |
| - |
| // Invokes ReadRawData and records bytes read if the read completes |
| // synchronously. |
| - Error ReadRawDataHelper(IOBuffer* buf, int buf_size, int* bytes_read); |
| + int ReadRawDataHelper(IOBuffer* buf, |
| + int buf_size, |
| + const CompletionCallback& callback); |
| // Called in response to a redirect that was not canceled to follow the |
| // redirect. The current job will be replaced with a new job loading the |
| @@ -377,18 +357,14 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // Called after every raw read. If |bytes_read| is > 0, this indicates |
| // a successful read of |bytes_read| unfiltered bytes. If |bytes_read| |
| - // is 0, this indicates that there is no additional data to read. |error| |
| - // specifies whether an error occurred and no bytes were read. |
| - void GatherRawReadStats(Error error, int bytes_read); |
| + // is 0, this indicates that there is no additional data to read. |
| + // If |bytes_read| is negative, no bytes were read. |
| + void GatherRawReadStats(int bytes_read); |
| // Updates the profiling info and notifies observers that an additional |
| // |bytes_read| unfiltered bytes have been read for this job. |
| void RecordBytesRead(int bytes_read); |
| - // Called to query whether there is data available in the filter to be read |
| - // out. |
| - bool FilterHasData(); |
| - |
| // NotifyDone marks that request is done. It is really a glorified |
| // set_status, but also does internal state checking and job tracking. It |
| // should be called once per request, when the job is finished doing all IO. |
| @@ -418,22 +394,12 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // NotifyDone so that it is kept in sync with the request. |
| bool done_; |
| - int64_t prefilter_bytes_read_; |
| - int64_t postfilter_bytes_read_; |
| - |
| - // The data stream filter which is enabled on demand. |
| - std::unique_ptr<Filter> filter_; |
| + // The first StreamSource of the StreamSource chain used. |
| + std::unique_ptr<StreamSource> source_; |
| - // If the filter filled its output buffer, then there is a change that it |
| - // still has internal data to emit, and this flag is set. |
| - bool filter_needs_more_output_space_; |
| - |
| - // When we filter data, we receive data into the filter buffers. After |
| - // processing the filtered data, we return the data in the caller's buffer. |
| - // While the async IO is in progress, we save the user buffer here, and |
| - // when the IO completes, we fill this in. |
| - scoped_refptr<IOBuffer> filtered_read_buffer_; |
| - int filtered_read_buffer_len_; |
| + // Keep a reference to the buffer passed in via URLRequestJob::Read() so it |
| + // doesn't get destroyed when the read has not completed. |
| + scoped_refptr<IOBuffer> pending_read_buffer_; |
| // We keep a pointer to the read buffer while asynchronous reads are |
| // in progress, so we are able to pass those bytes to job observers. |
| @@ -462,6 +428,16 @@ class NET_EXPORT URLRequestJob : public base::PowerObserver { |
| // notification. |
| int64_t last_notified_total_sent_bytes_; |
| + // None null if ReadRawData() returned ERR_IO_PENDING, and the read has not |
|
mmenke
2016/07/21 18:14:10
Non-null if...
xunjieli
2016/07/27 20:32:04
Done.
|
| + // completed. |
| + CompletionCallback read_raw_callback_; |
| + |
| + // Number of raw network bytes read from job subclass. |
| + size_t prefilter_bytes_read_; |
| + |
| + // Number of bytes after applying filters. |
| + size_t postfilter_bytes_read_; |
| + |
| base::WeakPtrFactory<URLRequestJob> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(URLRequestJob); |