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

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, 7 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/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/download_manager_delegate.h"
15
16 namespace headless {
17
18 class DownloadManager;
19
20 class HeadlessDownloadManagerDelegate
21 : public content::DownloadManagerDelegate {
22 public:
23 enum class DownloadBehavior {
24 // All downloads are denied.
25 DENY,
26
27 // All downloads are accepted.
28 ALLOW
29 };
30
31 HeadlessDownloadManagerDelegate();
32 ~HeadlessDownloadManagerDelegate() override;
33
34 void SetDownloadManager(content::DownloadManager* manager);
35
36 void Shutdown() override;
37
38 bool DetermineDownloadTarget(
39 content::DownloadItem* download,
40 const content::DownloadTargetCallback& callback) override;
41
42 bool ShouldOpenDownload(
43 content::DownloadItem* item,
44 const content::DownloadOpenDelayedCallback& callback) override;
45
46 void GetNextId(const content::DownloadIdCallback& callback) override;
47
48 // Inhibits prompting and sets the default download path.
49 void SetDownloadBehaviorForTesting(
Sami 2017/05/17 13:20:41 Did you forget to add the test sources since this
50 const base::FilePath& default_download_path);
51
52 void SetDownloadBehavior(const std::string& behavior);
Sami 2017/05/17 13:20:41 It feels like these should take the enum and a bas
53 void SetDownloadDirectory(const std::string& path);
54
55 private:
56 friend class base::RefCountedThreadSafe<HeadlessDownloadManagerDelegate>;
57
58 typedef base::Callback<void(const base::FilePath&)>
59 FilenameDeterminedCallback;
60
61 static void GenerateFilename(const GURL& url,
62 const std::string& content_disposition,
63 const std::string& suggested_filename,
64 const std::string& mime_type,
65 const base::FilePath& suggested_directory,
66 const FilenameDeterminedCallback& callback);
67
68 void OnDownloadPathGenerated(uint32_t download_id,
69 const content::DownloadTargetCallback& callback,
70 const base::FilePath& suggested_path);
71
72 content::DownloadManager* download_manager_;
73 base::FilePath default_download_path_;
74 DownloadBehavior download_behavior_;
75 base::WeakPtrFactory<HeadlessDownloadManagerDelegate> weak_ptr_factory_;
76
77 DISALLOW_COPY_AND_ASSIGN(HeadlessDownloadManagerDelegate);
78 };
79
80 } // namespace headless
81
82 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698