Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Unified Diff: components/image_fetcher/core/image_data_fetcher.h

Issue 2781473003: Add |SetImageDownloadLimit| to ImageFetcher to limit downloaded bytes (Closed)
Patch Set: Use base::Optional<int64_t> Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ba03723f579d351ac494e4b9956d69dae70c4ff8 100644
--- a/components/image_fetcher/core/image_data_fetcher.h
+++ b/components/image_fetcher/core/image_data_fetcher.h
@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/optional.h"
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/image_fetcher/core/request_metadata.h"
#include "net/url_request/url_fetcher_delegate.h"
@@ -42,6 +43,10 @@ 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.
+ // Already running downloads are immediately affected.
Marc Treib 2017/03/27 14:49:18 nit: They're affected as soon as we get the next P
fhorschig 2017/03/27 16:33:34 Gone.
+ void SetImageDownloadLimit(const base::Optional<int64_t>& max_download_bytes);
Marc Treib 2017/03/27 14:49:18 I think it'd be fine to pass this by value - it's
fhorschig 2017/03/27 16:33:34 Hmpf, and I spent all those hours replacing that.
+
// 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 +62,16 @@ 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;
+
+ void FinishRequest(const net::URLFetcher* source,
+ const RequestMetadata& metadata,
+ const std::string& image_data);
// All active image url requests.
std::map<const net::URLFetcher*, std::unique_ptr<ImageDataFetcherRequest>>
@@ -75,6 +88,9 @@ class ImageDataFetcher : public net::URLFetcherDelegate {
// is not used.
int next_url_fetcher_id_;
+ // Upper limit for the number of bytes to download per image.
+ base::Optional<int64_t> max_download_bytes_;
+
DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher);
};

Powered by Google App Engine
This is Rietveld 408576698