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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: headless/lib/browser/headless_download_manager_delegate.h
diff --git a/headless/lib/browser/headless_download_manager_delegate.h b/headless/lib/browser/headless_download_manager_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..8fbcf925fbc1a90494382084e24a9f7f5450b3d7
--- /dev/null
+++ b/headless/lib/browser/headless_download_manager_delegate.h
@@ -0,0 +1,82 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_
+#define HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_
+
+#include <stdint.h>
+
+#include "base/callback_forward.h"
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/download_manager_delegate.h"
+
+namespace headless {
+
+class DownloadManager;
+
+class HeadlessDownloadManagerDelegate
+ : public content::DownloadManagerDelegate {
+ public:
+ enum class DownloadBehavior {
+ // All downloads are denied.
+ DENY,
+
+ // All downloads are accepted.
+ ALLOW
+ };
+
+ HeadlessDownloadManagerDelegate();
+ ~HeadlessDownloadManagerDelegate() override;
+
+ void SetDownloadManager(content::DownloadManager* manager);
+
+ void Shutdown() override;
+
+ bool DetermineDownloadTarget(
+ content::DownloadItem* download,
+ const content::DownloadTargetCallback& callback) override;
+
+ bool ShouldOpenDownload(
+ content::DownloadItem* item,
+ const content::DownloadOpenDelayedCallback& callback) override;
+
+ void GetNextId(const content::DownloadIdCallback& callback) override;
+
+ // Inhibits prompting and sets the default download path.
+ void SetDownloadBehaviorForTesting(
Sami 2017/05/17 13:20:41 Did you forget to add the test sources since this
+ const base::FilePath& default_download_path);
+
+ void SetDownloadBehavior(const std::string& behavior);
Sami 2017/05/17 13:20:41 It feels like these should take the enum and a bas
+ void SetDownloadDirectory(const std::string& path);
+
+ private:
+ friend class base::RefCountedThreadSafe<HeadlessDownloadManagerDelegate>;
+
+ typedef base::Callback<void(const base::FilePath&)>
+ FilenameDeterminedCallback;
+
+ static void GenerateFilename(const GURL& url,
+ const std::string& content_disposition,
+ const std::string& suggested_filename,
+ const std::string& mime_type,
+ const base::FilePath& suggested_directory,
+ const FilenameDeterminedCallback& callback);
+
+ void OnDownloadPathGenerated(uint32_t download_id,
+ const content::DownloadTargetCallback& callback,
+ const base::FilePath& suggested_path);
+
+ content::DownloadManager* download_manager_;
+ base::FilePath default_download_path_;
+ DownloadBehavior download_behavior_;
+ base::WeakPtrFactory<HeadlessDownloadManagerDelegate> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(HeadlessDownloadManagerDelegate);
+};
+
+} // namespace headless
+
+#endif // HEADLESS_LIB_BROWSER_HEADLESS_DOWNLOAD_MANAGER_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698