persistent_download.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2021 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 WEBLAYER_BROWSER_PERSISTENT_DOWNLOAD_H_
  5. #define WEBLAYER_BROWSER_PERSISTENT_DOWNLOAD_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "weblayer/browser/download_impl.h"
  8. namespace download {
  9. class DownloadItem;
  10. }
  11. namespace weblayer {
  12. // A DownloadImpl that is persisted to disk. It will be backed by a
  13. // download::DownloadItem for which IsTransient returns false. This is used when
  14. // a user downloads a file from the web.
  15. class PersistentDownload : public DownloadImpl {
  16. public:
  17. PersistentDownload(const PersistentDownload& other) = delete;
  18. PersistentDownload& operator=(const PersistentDownload& other) = delete;
  19. ~PersistentDownload() override;
  20. static void Create(download::DownloadItem* item);
  21. static PersistentDownload* Get(download::DownloadItem* item);
  22. // Download:
  23. DownloadState GetState() override;
  24. int64_t GetTotalBytes() override;
  25. int64_t GetReceivedBytes() override;
  26. void Pause() override;
  27. void Resume() override;
  28. void Cancel() override;
  29. base::FilePath GetLocation() override;
  30. std::u16string GetFileNameToReportToUser() override;
  31. std::string GetMimeType() override;
  32. DownloadError GetError() override;
  33. // DownloadImpl:
  34. int GetNotificationId() override;
  35. bool IsTransient() override;
  36. GURL GetSourceUrl() override;
  37. const SkBitmap* GetLargeIcon() override;
  38. void OnFinished(bool activated) override;
  39. private:
  40. explicit PersistentDownload(download::DownloadItem* item);
  41. void PauseInternal();
  42. void ResumeInternal();
  43. void CancelInternal();
  44. raw_ptr<download::DownloadItem> item_;
  45. bool pause_pending_ = false;
  46. bool resume_pending_ = false;
  47. bool cancel_pending_ = false;
  48. base::WeakPtrFactory<PersistentDownload> weak_ptr_factory_{this};
  49. };
  50. } // namespace weblayer
  51. #endif // WEBLAYER_BROWSER_PERSISTENT_DOWNLOAD_H_