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

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, 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 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..e58715d217a522196e7b287e849ead504a9d1255
--- /dev/null
+++ b/headless/lib/browser/headless_download_manager_delegate.h
@@ -0,0 +1,86 @@
+// 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/files/file_util.h"
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/download_manager_delegate.h"
+#include "headless/public/headless_export.h"
+
+namespace content {
+class DownloadManager;
+}
+
+namespace headless {
+
+class HEADLESS_EXPORT 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;
+
+ void SetDownloadBehavior(DownloadBehavior behavior);
+ void SetDownloadDirectory(const base::FilePath& path);
+
+ // Inhibits prompting and sets the default download path.
+ void SetDownloadBehaviorForTesting(
+ const base::FilePath& default_download_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_
« 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