Chromium Code Reviews| Index: components/image_fetcher/core/image_data_fetcher.h |
| diff --git a/components/image_fetcher/core/image_data_fetcher.h b/components/image_fetcher/core/image_data_fetcher.h |
| index cac22fa2f581f121889c18fbcf4d3b6e508c8860..b8cf257c4b3f0e1ae9dbf0605440df9599e5acab 100644 |
| --- a/components/image_fetcher/core/image_data_fetcher.h |
| +++ b/components/image_fetcher/core/image_data_fetcher.h |
| @@ -42,6 +42,13 @@ class ImageDataFetcher : public net::URLFetcherDelegate { |
| // Sets a service name against which to track data usage. |
| void SetDataUseServiceName(DataUseServiceName data_use_service_name); |
| + // Sets an upper limit for image downloads that is by default disabled. |
|
Marc Treib
2017/03/27 13:16:42
nit: Remove "that is by default disabled", IMO tha
fhorschig
2017/03/27 14:33:43
Done.
|
| + // Setting |max_download_bytes| to a negative value will disable the limit. |
|
Marc Treib
2017/03/27 13:16:42
Hm. Make it a base::Optional<int64_t> instead? IMO
fhorschig
2017/03/27 14:33:43
Done.
|
| + // Already running downloads are immediately affected. |
| + void SetImageDownloadLimit(int64_t max_download_bytes) { |
| + max_download_bytes_ = max_download_bytes < 0 ? 0 : max_download_bytes; |
|
Marc Treib
2017/03/27 13:16:42
Move implementation to .cc file?
fhorschig
2017/03/27 14:33:43
Done.
|
| + } |
| + |
| // Fetches the raw image bytes from the given |image_url| and calls the given |
| // |callback|. The callback is run even if fetching the URL fails. In case |
| // of an error an empty string is passed to the callback. |
| @@ -57,8 +64,12 @@ class ImageDataFetcher : public net::URLFetcherDelegate { |
| private: |
| struct ImageDataFetcherRequest; |
| - // Method inherited from URLFetcherDelegate |
| + // Methods inherited from URLFetcherDelegate |
| void OnURLFetchComplete(const net::URLFetcher* source) override; |
| + void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| + int64_t current, |
| + int64_t total, |
| + int64_t current_network_bytes) override; |
| // All active image url requests. |
| std::map<const net::URLFetcher*, std::unique_ptr<ImageDataFetcherRequest>> |
| @@ -75,6 +86,10 @@ class ImageDataFetcher : public net::URLFetcherDelegate { |
| // is not used. |
| int next_url_fetcher_id_; |
| + // Running requests exceeding this limit will be canceled immediately. By |
|
Marc Treib
2017/03/27 13:16:42
Upper limit for the number of bytes to download pe
fhorschig
2017/03/27 14:33:43
Done.
|
| + // default negative and therefore disabled. |
| + int64_t max_download_bytes_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); |
| }; |