image_downloader.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2020 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 ASH_PUBLIC_CPP_IMAGE_DOWNLOADER_H_
  5. #define ASH_PUBLIC_CPP_IMAGE_DOWNLOADER_H_
  6. #include "ash/public/cpp/ash_public_export.h"
  7. #include "base/callback_forward.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. class GURL;
  10. class AccountId;
  11. namespace gfx {
  12. class ImageSkia;
  13. } // namespace gfx
  14. namespace net {
  15. class HttpRequestHeaders;
  16. struct NetworkTrafficAnnotationTag;
  17. } // namespace net
  18. namespace ash {
  19. // Interface for a class which is responsible for downloading images in ash.
  20. class ASH_PUBLIC_EXPORT ImageDownloader {
  21. public:
  22. static ImageDownloader* Get();
  23. using DownloadCallback = base::OnceCallback<void(const gfx::ImageSkia&)>;
  24. ImageDownloader(const ImageDownloader&) = delete;
  25. ImageDownloader& operator=(const ImageDownloader&) = delete;
  26. // Downloads the image found at |url| for the primary profile. On completion,
  27. // |callback| is run with the downloaded |image|. In the event that the
  28. // download attempt fails, a nullptr image will be returned.
  29. virtual void Download(const GURL& url,
  30. const net::NetworkTrafficAnnotationTag& annotation_tag,
  31. DownloadCallback callback) = 0;
  32. // Additionally with this method, you can specify extra HTTP request headers
  33. // sent with the download request, as well as include an `AccountId` to
  34. // include credentials for downloading images where authentication is
  35. // required.
  36. virtual void Download(const GURL& url,
  37. const net::NetworkTrafficAnnotationTag& annotation_tag,
  38. const net::HttpRequestHeaders& additional_headers,
  39. absl::optional<AccountId> credentials_account_id,
  40. DownloadCallback callback) = 0;
  41. protected:
  42. ImageDownloader();
  43. virtual ~ImageDownloader();
  44. };
  45. } // namespace ash
  46. #endif // ASH_PUBLIC_CPP_IMAGE_DOWNLOADER_H_