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

Side by Side Diff: components/image_fetcher/core/image_data_fetcher.h

Issue 2781473003: Add |SetImageDownloadLimit| to ImageFetcher to limit downloaded bytes (Closed)
Patch Set: Test fix: Mock pure virtual Setter in CrOS notification test Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ 5 #ifndef COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_
6 #define COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ 6 #define COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/optional.h"
15 #include "components/data_use_measurement/core/data_use_user_data.h" 16 #include "components/data_use_measurement/core/data_use_user_data.h"
16 #include "components/image_fetcher/core/request_metadata.h" 17 #include "components/image_fetcher/core/request_metadata.h"
17 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace net { 22 namespace net {
22 class URLFetcher; 23 class URLFetcher;
23 class URLRequestContextGetter; 24 class URLRequestContextGetter;
24 } // namespace net 25 } // namespace net
(...skipping 10 matching lines...) Expand all
35 36
36 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; 37 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName;
37 38
38 explicit ImageDataFetcher( 39 explicit ImageDataFetcher(
39 net::URLRequestContextGetter* url_request_context_getter); 40 net::URLRequestContextGetter* url_request_context_getter);
40 ~ImageDataFetcher() override; 41 ~ImageDataFetcher() override;
41 42
42 // Sets a service name against which to track data usage. 43 // Sets a service name against which to track data usage.
43 void SetDataUseServiceName(DataUseServiceName data_use_service_name); 44 void SetDataUseServiceName(DataUseServiceName data_use_service_name);
44 45
46 // Sets an upper limit for image downloads.
47 // Already running downloads are affected.
48 void SetImageDownloadLimit(base::Optional<int64_t> max_download_bytes);
49
45 // Fetches the raw image bytes from the given |image_url| and calls the given 50 // Fetches the raw image bytes from the given |image_url| and calls the given
46 // |callback|. The callback is run even if fetching the URL fails. In case 51 // |callback|. The callback is run even if fetching the URL fails. In case
47 // of an error an empty string is passed to the callback. 52 // of an error an empty string is passed to the callback.
48 void FetchImageData(const GURL& image_url, 53 void FetchImageData(const GURL& image_url,
49 const ImageDataFetcherCallback& callback); 54 const ImageDataFetcherCallback& callback);
50 55
51 // Like above, but lets the caller set a referrer. 56 // Like above, but lets the caller set a referrer.
52 void FetchImageData(const GURL& image_url, 57 void FetchImageData(const GURL& image_url,
53 const ImageDataFetcherCallback& callback, 58 const ImageDataFetcherCallback& callback,
54 const std::string& referrer, 59 const std::string& referrer,
55 net::URLRequest::ReferrerPolicy referrer_policy); 60 net::URLRequest::ReferrerPolicy referrer_policy);
56 61
57 private: 62 private:
58 struct ImageDataFetcherRequest; 63 struct ImageDataFetcherRequest;
59 64
60 // Method inherited from URLFetcherDelegate 65 // Methods inherited from URLFetcherDelegate
61 void OnURLFetchComplete(const net::URLFetcher* source) override; 66 void OnURLFetchComplete(const net::URLFetcher* source) override;
67 void OnURLFetchDownloadProgress(const net::URLFetcher* source,
68 int64_t current,
69 int64_t total,
70 int64_t current_network_bytes) override;
71
72 void FinishRequest(const net::URLFetcher* source,
73 const RequestMetadata& metadata,
74 const std::string& image_data);
62 75
63 // All active image url requests. 76 // All active image url requests.
64 std::map<const net::URLFetcher*, std::unique_ptr<ImageDataFetcherRequest>> 77 std::map<const net::URLFetcher*, std::unique_ptr<ImageDataFetcherRequest>>
65 pending_requests_; 78 pending_requests_;
66 79
67 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 80 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
68 81
69 DataUseServiceName data_use_service_name_; 82 DataUseServiceName data_use_service_name_;
70 83
71 // The next ID to use for a newly created URLFetcher. Each URLFetcher gets an 84 // The next ID to use for a newly created URLFetcher. Each URLFetcher gets an
72 // id when it is created. The |url_fetcher_id_| is incremented by one for each 85 // id when it is created. The |url_fetcher_id_| is incremented by one for each
73 // newly created URLFetcher. The URLFetcher ID can be used during testing to 86 // newly created URLFetcher. The URLFetcher ID can be used during testing to
74 // get individual URLFetchers and modify their state. Outside of tests this ID 87 // get individual URLFetchers and modify their state. Outside of tests this ID
75 // is not used. 88 // is not used.
76 int next_url_fetcher_id_; 89 int next_url_fetcher_id_;
77 90
91 // Upper limit for the number of bytes to download per image.
92 base::Optional<int64_t> max_download_bytes_;
93
78 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); 94 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher);
79 }; 95 };
80 96
81 } // namespace image_fetcher 97 } // namespace image_fetcher
82 98
83 #endif // COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ 99 #endif // COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_
OLDNEW
« no previous file with comments | « components/favicon/core/large_icon_service_unittest.cc ('k') | components/image_fetcher/core/image_data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698