Index: chrome/common/net/url_fetcher.h |
diff --git a/chrome/common/net/url_fetcher.h b/chrome/common/net/url_fetcher.h |
index 3ed0e6491c1fdf81394df470874f585927d8ebca..bf2648ca4c6a9c6c1aff76b7c901fe89ef718922 100644 |
--- a/chrome/common/net/url_fetcher.h |
+++ b/chrome/common/net/url_fetcher.h |
@@ -67,12 +67,36 @@ class URLFetcher { |
HEAD, |
}; |
+ // Abstract class used to hold the response body. Delegate generates |
+ // an implementation of this interface, and gets a pointer to it when |
+ // the fetch is complete. |
+ class ResponseBodyContainerInterface { |
+ public: |
+ // Add bytes to the response body. |
+ virtual void Append(char* data, int data_length) = 0; |
+ |
+ // If the class supports returning the body as a string, return true |
+ // and set |out_body| to the response body. Otherwise, return false. |
+ virtual bool GetAsString(std::string* out_body) const = 0; |
+ }; |
+ |
class Delegate { |
public: |
// 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. |
+ virtual void OnURLFetchCompleteNew( |
+ const URLFetcher* source, |
+ const GURL& url, |
+ const net::URLRequestStatus& status, |
+ int response_code, |
+ const ResponseCookies& cookies, |
+ const ResponseBodyContainerInterface& response_body); |
+ |
+ // TODO(skerner): To avoid changing existing code, keep the old |
+ // method, whre |data| is a string. Once we finalize interface changes, |
+ // this will be removed. |
virtual void OnURLFetchComplete(const URLFetcher* source, |
const GURL& url, |
const net::URLRequestStatus& status, |
@@ -80,6 +104,13 @@ class URLFetcher { |
const ResponseCookies& cookies, |
const std::string& data) = 0; |
+ // Get a container into which the response body can be written. |
+ // Delegate can control how response is held by the choice of the |
+ // concrete type this method returns. For example, to process the |
+ // response body as it is received, return a class that does |
+ // processing on each call to ResponseBodyContainerInterface::Append(). |
+ virtual ResponseBodyContainerInterface* CreateResponseBodyContainer(); |
+ |
protected: |
virtual ~Delegate() {} |
}; |