ios_image_data_fetcher_wrapper.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_
  5. #define COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_
  6. #import <Foundation/Foundation.h>
  7. #include "base/memory/ref_counted.h"
  8. #include "components/image_fetcher/core/image_data_fetcher.h"
  9. #include "components/image_fetcher/core/image_fetcher_types.h"
  10. #include "net/url_request/referrer_policy.h"
  11. namespace network {
  12. class SharedURLLoaderFactory;
  13. }
  14. class GURL;
  15. namespace image_fetcher {
  16. class IOSImageDataFetcherWrapper {
  17. public:
  18. // The TaskRunner is used to decode the image if it is WebP-encoded.
  19. explicit IOSImageDataFetcherWrapper(
  20. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
  21. IOSImageDataFetcherWrapper(const IOSImageDataFetcherWrapper&) = delete;
  22. IOSImageDataFetcherWrapper& operator=(const IOSImageDataFetcherWrapper&) =
  23. delete;
  24. virtual ~IOSImageDataFetcherWrapper();
  25. // Helper to start downloading and possibly decoding the image without a
  26. // referrer.
  27. void FetchImageDataWebpDecoded(const GURL& image_url,
  28. ImageDataFetcherBlock callback,
  29. bool send_cookies = false);
  30. // Start downloading the image at the given |image_url|. The |callback| will
  31. // be called with the downloaded image, or nil if any error happened. If the
  32. // image is WebP it will be decoded.
  33. // The |referrer| and |referrer_policy| will be passed on to the underlying
  34. // URLLoader.
  35. // |callback| cannot be nil.
  36. void FetchImageDataWebpDecoded(const GURL& image_url,
  37. ImageDataFetcherBlock callback,
  38. const std::string& referrer,
  39. net::ReferrerPolicy referrer_policy,
  40. bool send_cookies = false);
  41. // Test-only accessor for underlying ImageDataFetcher.
  42. ImageDataFetcher* AccessImageDataFetcherForTesting() {
  43. return &image_data_fetcher_;
  44. }
  45. private:
  46. ImageDataFetcherCallback CallbackForImageDataFetcher(
  47. ImageDataFetcherBlock callback);
  48. ImageDataFetcher image_data_fetcher_;
  49. };
  50. } // namespace image_fetcher
  51. #endif // COMPONENTS_IMAGE_FETCHER_IOS_IOS_IMAGE_DATA_FETCHER_WRAPPER_H_