Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Side by Side Diff: headless/lib/browser/headless_download_manager_delegate.h

Issue 2886693002: initial version of the headless download manager delegate
Patch Set: initial version of the headless download manager delegate Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "headless/public/headless_export.h"
17
18 namespace content {
19 class DownloadManager;
20 }
21
22 namespace headless {
23
24 class HEADLESS_EXPORT HeadlessDownloadManagerDelegate
25 : public content::DownloadManagerDelegate {
26 public:
27 enum class DownloadBehavior {
28 // All downloads are denied.
29 DENY,
30
31 // All downloads are accepted.
32 ALLOW
33 };
34
35 HeadlessDownloadManagerDelegate();
36 ~HeadlessDownloadManagerDelegate() override;
37
38 void SetDownloadManager(content::DownloadManager* manager);
39
40 void Shutdown() override;
41
42 bool DetermineDownloadTarget(
43 content::DownloadItem* download,
44 const content::DownloadTargetCallback& callback) override;
45
46 bool ShouldOpenDownload(
47 content::DownloadItem* item,
48 const content::DownloadOpenDelayedCallback& callback) override;
49
50 void GetNextId(const content::DownloadIdCallback& callback) override;
51
52 void SetDownloadBehavior(DownloadBehavior behavior);
53 void SetDownloadDirectory(const base::FilePath& path);
54
55 // Inhibits prompting and sets the default download path.
56 void SetDownloadBehaviorForTesting(
57 const base::FilePath& default_download_path);
58
59 private:
60 friend class base::RefCountedThreadSafe<HeadlessDownloadManagerDelegate>;
61
62 typedef base::Callback<void(const base::FilePath&)>
63 FilenameDeterminedCallback;
64
65 static void GenerateFilename(const GURL& url,
66 const std::string& content_disposition,
67 const std::string& suggested_filename,
68 const std::string& mime_type,
69 const base::FilePath& suggested_directory,
70 const FilenameDeterminedCallback& callback);
71
72 void OnDownloadPathGenerated(uint32_t download_id,
73 const content::DownloadTargetCallback& callback,
74 const base::FilePath& suggested_path);
75
76 content::DownloadManager* download_manager_;
77 base::FilePath default_download_path_;
78 DownloadBehavior download_behavior_;
79 base::WeakPtrFactory<HeadlessDownloadManagerDelegate> weak_ptr_factory_;
80
81 DISALLOW_COPY_AND_ASSIGN(HeadlessDownloadManagerDelegate);
82 };
83
84 } // namespace headless
85
86 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_devtools_manager_delegate.cc ('k') | headless/lib/browser/headless_download_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698