OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_IMAGE_FETCHER_H_ | 5 #ifndef COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_H_ |
6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_H_ | 6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "components/data_use_measurement/core/data_use_user_data.h" | 12 #include "components/data_use_measurement/core/data_use_user_data.h" |
13 #include "components/image_fetcher/image_fetcher_delegate.h" | 13 #include "components/image_fetcher/image_fetcher_delegate.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class Image; | 17 class Image; |
| 18 class Size; |
18 } | 19 } |
19 | 20 |
20 namespace image_fetcher { | 21 namespace image_fetcher { |
21 | 22 |
22 // A class used to fetch server images. It can be called from any thread and the | 23 // A class used to fetch server images. It can be called from any thread and the |
23 // callback will be called on the thread which initiated the fetch. | 24 // callback will be called on the thread which initiated the fetch. |
24 class ImageFetcher { | 25 class ImageFetcher { |
25 public: | 26 public: |
26 ImageFetcher() {} | 27 ImageFetcher() {} |
27 virtual ~ImageFetcher() {} | 28 virtual ~ImageFetcher() {} |
28 | 29 |
29 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; | 30 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; |
30 | 31 |
31 virtual void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) = 0; | 32 virtual void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) = 0; |
32 | 33 |
33 // Sets a service name against which to track data usage. | 34 // Sets a service name against which to track data usage. |
34 virtual void SetDataUseServiceName( | 35 virtual void SetDataUseServiceName( |
35 DataUseServiceName data_use_service_name) = 0; | 36 DataUseServiceName data_use_service_name) = 0; |
36 | 37 |
| 38 // Sets the desired size for images with multiple frames (like .ico files). |
| 39 // By default, the image fetcher choses smaller images. Override to choose a |
| 40 // frame with a size as close as possible to |size| (trying to take one in |
| 41 // larger size if there's no precise match). Passing gfx::Size() as |
| 42 // |size| is also supported and will result in chosing the smallest available |
| 43 // size. |
| 44 virtual void SetDesiredImageFrameSize(const gfx::Size& size) = 0; |
| 45 |
37 // An empty gfx::Image will be returned to the callback in case the image | 46 // An empty gfx::Image will be returned to the callback in case the image |
38 // could not be fetched. | 47 // could not be fetched. |
39 virtual void StartOrQueueNetworkRequest( | 48 virtual void StartOrQueueNetworkRequest( |
40 const std::string& id, | 49 const std::string& id, |
41 const GURL& image_url, | 50 const GURL& image_url, |
42 base::Callback<void(const std::string&, const gfx::Image&)> callback) = 0; | 51 base::Callback<void(const std::string&, const gfx::Image&)> callback) = 0; |
43 | 52 |
44 // TODO(treib,markusheintz): Now that iOS uses the same ImageFetcherImpl (see | 53 // TODO(treib,markusheintz): Now that iOS uses the same ImageFetcherImpl (see |
45 // crbug.com/689020), add a getter for the ImageDecoder here. | 54 // crbug.com/689020), add a getter for the ImageDecoder here. |
46 | 55 |
47 private: | 56 private: |
48 DISALLOW_COPY_AND_ASSIGN(ImageFetcher); | 57 DISALLOW_COPY_AND_ASSIGN(ImageFetcher); |
49 }; | 58 }; |
50 | 59 |
51 } // namespace image_fetcher | 60 } // namespace image_fetcher |
52 | 61 |
53 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_H_ | 62 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_H_ |
OLD | NEW |