| Index: chrome/common/net/url_fetcher.h
|
| diff --git a/chrome/common/net/url_fetcher.h b/chrome/common/net/url_fetcher.h
|
| index f4fcf77ee5696ae4ae6c5ea7b06038cf2368d557..5ff7fa7e937d671924d8fb3d2d8691247dc905d7 100644
|
| --- a/chrome/common/net/url_fetcher.h
|
| +++ b/chrome/common/net/url_fetcher.h
|
| @@ -20,10 +20,16 @@
|
|
|
| #include "base/memory/ref_counted.h"
|
| #include "base/message_loop.h"
|
| +#include "base/platform_file.h"
|
| #include "base/time.h"
|
|
|
| +class FilePath;
|
| class GURL;
|
|
|
| +namespace base {
|
| +class MessageLoopProxy;
|
| +} // namespace base
|
| +
|
| namespace net {
|
| class HostPortPair;
|
| class HttpResponseHeaders;
|
| @@ -68,18 +74,44 @@ class URLFetcher {
|
| HEAD,
|
| };
|
|
|
| + // Where should the response be saved? Use set_response_destination()
|
| + // to choose.
|
| + enum ResponseDestinationType {
|
| + STRING, // Default
|
| + TEMP_FILE
|
| + };
|
| +
|
| class Delegate {
|
| public:
|
| + // TODO(skerner): This will be removed in favor of the |data|-free
|
| + // version below. Leaving this for now to make the initial code review
|
| + // easy to read.
|
| + virtual void OnURLFetchComplete(const URLFetcher* source,
|
| + const GURL& url,
|
| + const net::URLRequestStatus& status,
|
| + int response_code,
|
| + const net::ResponseCookies& cookies,
|
| + const std::string& data);
|
| +
|
| // This will be called when the URL has been fetched, successfully or not.
|
| // |response_code| is the HTTP response code (200, 404, etc.) if
|
| - // applicable. |url|, |status| and |data| are all valid until the
|
| - // URLFetcher instance is destroyed.
|
| + // applicable. |url| and |status| are all valid until the URLFetcher
|
| + // instance is destroyed.
|
| virtual void OnURLFetchComplete(const URLFetcher* source,
|
| const GURL& url,
|
| const net::URLRequestStatus& status,
|
| int response_code,
|
| - const net::ResponseCookies& cookies,
|
| - const std::string& data) = 0;
|
| + const net::ResponseCookies& cookies);
|
| +
|
| + // Called on a file writing error. Only called when writing the response
|
| + // to a file.
|
| + // REVIEWER PLEASE NOTE: This method would be unnecessary if the failure
|
| + // could be encoded in a net::URLRequestStatus. However, it seems odd
|
| + // to put a file system error in that object. Is it worth having this
|
| + // method?
|
| + virtual void OnFileWriteError(const URLFetcher* source,
|
| + const GURL& url,
|
| + base::PlatformFileError error);
|
|
|
| protected:
|
| virtual ~Delegate() {}
|
| @@ -183,6 +215,23 @@ class URLFetcher {
|
| }
|
| #endif // defined(UNIT_TEST)
|
|
|
| + ResponseDestinationType response_destination() {
|
| + return response_destination_;
|
| + }
|
| +
|
| + // Where should the response be saved? This should only be called before
|
| + // calling Start(). If the response should be saved to a file, you need
|
| + // to call set_file_message_loop_proxy() to give the thread on which file
|
| + // operations may be done.
|
| + void set_response_destination(ResponseDestinationType response_destination) {
|
| + response_destination_ = response_destination;
|
| + }
|
| +
|
| + // Set the message loop proxy for file operations. Used to write the
|
| + // response to a file.
|
| + void set_file_message_loop_proxy(
|
| + scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy);
|
| +
|
| // Retrieve the response headers from the request. Must only be called after
|
| // the OnURLFetchComplete callback has run.
|
| virtual net::HttpResponseHeaders* response_headers() const;
|
| @@ -207,6 +256,14 @@ class URLFetcher {
|
| // Reports that the received content was malformed.
|
| void ReceivedContentWasMalformed();
|
|
|
| + // Get the response as a string. Return false if the fetcher was not
|
| + // set to store the response as a string.
|
| + bool GetResponseAsString(std::string* response_string) const;
|
| +
|
| + // Get the path to the file containing the response body. Returns false
|
| + // if the response body was not saved to a file.
|
| + bool GetResponseAsFilePath(FilePath* response_path) const;
|
| +
|
| // Cancels all existing URLFetchers. Will notify the URLFetcher::Delegates.
|
| // Note that any new URLFetchers created while this is running will not be
|
| // cancelled. Typically, one would call this in the CleanUp() method of an IO
|
| @@ -245,6 +302,9 @@ class URLFetcher {
|
| // Maximum retries allowed.
|
| int max_retries_;
|
|
|
| + // Where should responses be saved?
|
| + ResponseDestinationType response_destination_;
|
| +
|
| static bool g_interception_enabled;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(URLFetcher);
|
|
|