Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ | 6 #define CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "base/memory/ref_counted.h" | |
|
wtc
2011/10/26 23:34:46
Nit: list this header before "base/platform_file.h
jam
2011/10/26 23:39:06
Done.
| |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 | 15 |
| 15 class FilePath; | 16 class FilePath; |
| 16 class GURL; | 17 class GURL; |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class MessageLoopProxy; | 20 class MessageLoopProxy; |
| 20 class TimeDelta; | 21 class TimeDelta; |
| 21 } | 22 } |
| 22 | 23 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 HEAD, | 76 HEAD, |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 // |url| is the URL to send the request to. | 79 // |url| is the URL to send the request to. |
| 79 // |request_type| is the type of request to make. | 80 // |request_type| is the type of request to make. |
| 80 // |d| the object that will receive the callback on fetch completion. | 81 // |d| the object that will receive the callback on fetch completion. |
| 81 static URLFetcher* Create(const GURL& url, | 82 static URLFetcher* Create(const GURL& url, |
| 82 RequestType request_type, | 83 RequestType request_type, |
| 83 URLFetcherDelegate* d); | 84 URLFetcherDelegate* d); |
| 84 | 85 |
| 85 // Like above, but if there's a Factory registered with the implementation it | 86 // Like above, but if there's a URLFetcherFactory registered with the |
| 86 // will be used. |id| may be used during testing to identify who is creating | 87 // implementation it will be used. |id| may be used during testing to identify |
| 87 // the URLFetcher. | 88 // who is creating the URLFetcher. |
| 88 static URLFetcher* Create(int id, | 89 static URLFetcher* Create(int id, |
| 89 const GURL& url, | 90 const GURL& url, |
| 90 RequestType request_type, | 91 RequestType request_type, |
| 91 content::URLFetcherDelegate* d); | 92 content::URLFetcherDelegate* d); |
| 92 | 93 |
| 93 // Cancels all existing URLFetchers. Will notify the URLFetcherDelegates. | 94 // Cancels all existing URLFetchers. Will notify the URLFetcherDelegates. |
| 94 // Note that any new URLFetchers created while this is running will not be | 95 // Note that any new URLFetchers created while this is running will not be |
| 95 // cancelled. Typically, one would call this in the CleanUp() method of an IO | 96 // cancelled. Typically, one would call this in the CleanUp() method of an IO |
| 96 // thread, so that no new URLRequests would be able to start on the IO thread | 97 // thread, so that no new URLRequests would be able to start on the IO thread |
| 97 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO | 98 // anyway. This doesn't prevent new URLFetchers from trying to post to the IO |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 // after backoff_delay() elapses. URLFetcher has it set to true by default. | 152 // after backoff_delay() elapses. URLFetcher has it set to true by default. |
| 152 virtual void SetAutomaticallyRetryOn5xx(bool retry) = 0; | 153 virtual void SetAutomaticallyRetryOn5xx(bool retry) = 0; |
| 153 | 154 |
| 154 virtual void SetMaxRetries(int max_retries) = 0; | 155 virtual void SetMaxRetries(int max_retries) = 0; |
| 155 virtual int GetMaxRetries() const = 0; | 156 virtual int GetMaxRetries() const = 0; |
| 156 | 157 |
| 157 // Returns the back-off delay before the request will be retried, | 158 // Returns the back-off delay before the request will be retried, |
| 158 // when a 5xx response was received. | 159 // when a 5xx response was received. |
| 159 virtual base::TimeDelta GetBackoffDelay() const = 0; | 160 virtual base::TimeDelta GetBackoffDelay() const = 0; |
| 160 | 161 |
| 161 // Sets the back-off delay, allowing to mock 5xx requests in unit-tests. | |
| 162 virtual void SetBackoffDelayForTesting(base::TimeDelta backoff_delay) = 0; | |
|
wtc
2011/10/26 23:34:46
This change should be mentioned in the CL's commit
jam
2011/10/26 23:39:06
I had just added this method to the interface in m
| |
| 163 | |
| 164 // By default, the response is saved in a string. Call this method to save the | 162 // By default, the response is saved in a string. Call this method to save the |
| 165 // response to a temporary file instead. Must be called before Start(). | 163 // response to a temporary file instead. Must be called before Start(). |
| 166 // |file_message_loop_proxy| will be used for all file operations. | 164 // |file_message_loop_proxy| will be used for all file operations. |
| 167 virtual void SaveResponseToTemporaryFile( | 165 virtual void SaveResponseToTemporaryFile( |
| 168 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) = 0; | 166 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) = 0; |
| 169 | 167 |
| 170 // Retrieve the response headers from the request. Must only be called after | 168 // Retrieve the response headers from the request. Must only be called after |
| 171 // the OnURLFetchComplete callback has run. | 169 // the OnURLFetchComplete callback has run. |
| 172 virtual net::HttpResponseHeaders* GetResponseHeaders() const = 0; | 170 virtual net::HttpResponseHeaders* GetResponseHeaders() const = 0; |
| 173 | 171 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 186 virtual void Start() = 0; | 184 virtual void Start() = 0; |
| 187 | 185 |
| 188 // Restarts the URLFetcher with a new URLRequestContextGetter. | 186 // Restarts the URLFetcher with a new URLRequestContextGetter. |
| 189 virtual void StartWithRequestContextGetter( | 187 virtual void StartWithRequestContextGetter( |
| 190 net::URLRequestContextGetter* request_context_getter) = 0; | 188 net::URLRequestContextGetter* request_context_getter) = 0; |
| 191 | 189 |
| 192 // Return the URL that we were asked to fetch. | 190 // Return the URL that we were asked to fetch. |
| 193 virtual const GURL& GetOriginalUrl() const = 0; | 191 virtual const GURL& GetOriginalUrl() const = 0; |
| 194 | 192 |
| 195 // Return the URL that this fetcher is processing. | 193 // Return the URL that this fetcher is processing. |
| 196 virtual const GURL& GetUrl() const = 0; | 194 virtual const GURL& GetUrl() const = 0; |
|
wtc
2011/10/27 21:29:16
Nit: these two methods should be named GetOriginal
jam
2011/10/27 22:34:41
good point. done.
| |
| 197 | 195 |
| 198 // The status of the URL fetch. | 196 // The status of the URL fetch. |
| 199 virtual const net::URLRequestStatus& GetStatus() const = 0; | 197 virtual const net::URLRequestStatus& GetStatus() const = 0; |
| 200 | 198 |
| 201 // The http response code received. Will return RESPONSE_CODE_INVALID | 199 // The http response code received. Will return RESPONSE_CODE_INVALID |
| 202 // if an error prevented any response from being received. | 200 // if an error prevented any response from being received. |
| 203 virtual int GetResponseCode() const = 0; | 201 virtual int GetResponseCode() const = 0; |
| 204 | 202 |
| 205 // Cookies recieved. | 203 // Cookies recieved. |
| 206 virtual const net::ResponseCookies& GetCookies() const = 0; | 204 virtual const net::ResponseCookies& GetCookies() const = 0; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 223 // true, caller takes responsibility for the temp file, and it will not | 221 // true, caller takes responsibility for the temp file, and it will not |
| 224 // be removed once the URLFetcher is destroyed. User should not take | 222 // be removed once the URLFetcher is destroyed. User should not take |
| 225 // ownership more than once, or call this method after taking ownership. | 223 // ownership more than once, or call this method after taking ownership. |
| 226 virtual bool GetResponseAsFilePath(bool take_ownership, | 224 virtual bool GetResponseAsFilePath(bool take_ownership, |
| 227 FilePath* out_response_path) const = 0; | 225 FilePath* out_response_path) const = 0; |
| 228 }; | 226 }; |
| 229 | 227 |
| 230 } // namespace content | 228 } // namespace content |
| 231 | 229 |
| 232 #endif // CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ | 230 #endif // CONTENT_PUBLIC_COMMON_URL_FETCHER_H_ |
| OLD | NEW |