OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_ |
| 6 #define COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_ |
| 7 |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 12 #include "components/image_fetcher/image_data_fetcher.h" |
| 13 |
| 14 namespace base { |
| 15 class TaskRunner; |
| 16 } |
| 17 |
| 18 namespace net { |
| 19 class URLRequestContextGetter; |
| 20 } |
| 21 |
| 22 class GURL; |
| 23 |
| 24 namespace image_fetcher { |
| 25 |
| 26 // Callback that informs of the download of an image encoded in |data|. |
| 27 using IOSImageDataFetcherCallback = void (^)(NSData* data); |
| 28 |
| 29 class IOSImageDataFetcherWrapper { |
| 30 public: |
| 31 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; |
| 32 |
| 33 // The TaskRunner is used to decode the image if it is WebP-encoded. |
| 34 IOSImageDataFetcherWrapper( |
| 35 net::URLRequestContextGetter* url_request_context_getter, |
| 36 const scoped_refptr<base::TaskRunner>& task_runner); |
| 37 virtual ~IOSImageDataFetcherWrapper(); |
| 38 |
| 39 // Start downloading the image at the given |image_url|. The |callback| will |
| 40 // be called with the downloaded image, or nil if any error happened or the |
| 41 // http response header is not HTTP_OK (200). If the url is a data URL, the |
| 42 // http response header is considered to be HTTP_OK. |
| 43 // |callback| cannot be nil. |
| 44 virtual void FetchImageDataWebpDecoded(const GURL& image_url, |
| 45 IOSImageDataFetcherCallback callback); |
| 46 |
| 47 // Sets a service name against which to track data usage. |
| 48 void SetDataUseServiceName(DataUseServiceName data_use_service_name); |
| 49 |
| 50 private: |
| 51 // The task runner used to decode images if necessary. |
| 52 const scoped_refptr<base::TaskRunner> task_runner_; |
| 53 ImageDataFetcher image_data_fetcher_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(IOSImageDataFetcherWrapper); |
| 56 }; |
| 57 |
| 58 } // namespace image_fetcher |
| 59 |
| 60 #endif // COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_ |
OLD | NEW |