atom_download_manager_delegate.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2015 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_
  5. #define ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_
  6. #include <string>
  7. #include "base/memory/weak_ptr.h"
  8. #include "content/public/browser/download_manager_delegate.h"
  9. namespace content {
  10. class DownloadManager;
  11. }
  12. namespace atom {
  13. class AtomDownloadManagerDelegate : public content::DownloadManagerDelegate {
  14. public:
  15. using CreateDownloadPathCallback =
  16. base::Callback<void(const base::FilePath&)>;
  17. explicit AtomDownloadManagerDelegate(content::DownloadManager* manager);
  18. ~AtomDownloadManagerDelegate() override;
  19. void OnDownloadPathGenerated(uint32_t download_id,
  20. const content::DownloadTargetCallback& callback,
  21. const base::FilePath& default_path);
  22. // content::DownloadManagerDelegate:
  23. void Shutdown() override;
  24. bool DetermineDownloadTarget(
  25. content::DownloadItem* download,
  26. const content::DownloadTargetCallback& callback) override;
  27. bool ShouldOpenDownload(
  28. content::DownloadItem* download,
  29. const content::DownloadOpenDelayedCallback& callback) override;
  30. void GetNextId(const content::DownloadIdCallback& callback) override;
  31. private:
  32. // Get the save path set on the associated api::DownloadItem object
  33. void GetItemSavePath(content::DownloadItem* item, base::FilePath* path);
  34. content::DownloadManager* download_manager_;
  35. base::WeakPtrFactory<AtomDownloadManagerDelegate> weak_ptr_factory_;
  36. DISALLOW_COPY_AND_ASSIGN(AtomDownloadManagerDelegate);
  37. };
  38. } // namespace atom
  39. #endif // ATOM_BROWSER_ATOM_DOWNLOAD_MANAGER_DELEGATE_H_