Chromium Code Reviews| 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 HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_ | |
| 6 #define HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/callback_forward.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/files/file_util.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "content/public/browser/download_manager_delegate.h" | |
| 16 | |
| 17 namespace headless { | |
| 18 | |
| 19 class DownloadManager; | |
| 20 | |
| 21 class HeadlessDownloadManagerDelegate | |
| 22 : public content::DownloadManagerDelegate { | |
| 23 public: | |
| 24 enum class DownloadBehavior { | |
| 25 // All downloads are denied. | |
| 26 DENY, | |
| 27 | |
| 28 // All downloads are accepted. | |
| 29 ALLOW | |
| 30 }; | |
| 31 | |
| 32 HeadlessDownloadManagerDelegate(); | |
| 33 ~HeadlessDownloadManagerDelegate() override; | |
| 34 | |
| 35 void SetDownloadManager(content::DownloadManager* manager); | |
| 36 | |
| 37 void Shutdown() override; | |
| 38 | |
| 39 bool DetermineDownloadTarget( | |
| 40 content::DownloadItem* download, | |
| 41 const content::DownloadTargetCallback& callback) override; | |
| 42 | |
| 43 bool ShouldOpenDownload( | |
| 44 content::DownloadItem* item, | |
| 45 const content::DownloadOpenDelayedCallback& callback) override; | |
| 46 | |
| 47 void GetNextId(const content::DownloadIdCallback& callback) override; | |
| 48 | |
| 49 void SetDownloadBehavior(const DownloadBehavior& behavior); | |
|
Sami
2017/05/19 13:57:26
nit: Pass by value
| |
| 50 void SetDownloadDirectory(const base::FilePath& path); | |
| 51 | |
| 52 private: | |
| 53 friend class base::RefCountedThreadSafe<HeadlessDownloadManagerDelegate>; | |
| 54 | |
| 55 typedef base::Callback<void(const base::FilePath&)> | |
| 56 FilenameDeterminedCallback; | |
| 57 | |
| 58 static void GenerateFilename(const GURL& url, | |
| 59 const std::string& content_disposition, | |
| 60 const std::string& suggested_filename, | |
| 61 const std::string& mime_type, | |
| 62 const base::FilePath& suggested_directory, | |
| 63 const FilenameDeterminedCallback& callback); | |
| 64 | |
| 65 void OnDownloadPathGenerated(uint32_t download_id, | |
| 66 const content::DownloadTargetCallback& callback, | |
| 67 const base::FilePath& suggested_path); | |
| 68 | |
| 69 content::DownloadManager* download_manager_; | |
| 70 base::FilePath default_download_path_; | |
| 71 DownloadBehavior download_behavior_; | |
| 72 base::WeakPtrFactory<HeadlessDownloadManagerDelegate> weak_ptr_factory_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(HeadlessDownloadManagerDelegate); | |
| 75 }; | |
| 76 | |
| 77 } // namespace headless | |
| 78 | |
| 79 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_ | |
| OLD | NEW |