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

Unified Diff: chrome/browser/download/download_target_determiner_delegate.h

Issue 12850002: Move download filename determintion into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests on Android Created 7 years, 8 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: chrome/browser/download/download_target_determiner_delegate.h
diff --git a/chrome/browser/download/download_target_determiner_delegate.h b/chrome/browser/download/download_target_determiner_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..bba99aea5722b408c77fc61ae912c743ede70389
--- /dev/null
+++ b/chrome/browser/download/download_target_determiner_delegate.h
@@ -0,0 +1,110 @@
+// Copyright 2013 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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_
+#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_
+
+#include "base/callback_forward.h"
+
+#include "chrome/browser/download/download_path_reservation_tracker.h"
+#include "content/public/browser/download_danger_type.h"
+
+class ExtensionDownloadsEventRouter;
+
+namespace base {
+class FilePath;
+}
+
+namespace content {
+class DownloadItem;
+}
+
+// Delegate for DownloadTargetDeterminer. The delegate isn't owned by
+// DownloadTargetDeterminer and is expected to outlive it.
+class DownloadTargetDeterminerDelegate {
+ public:
+ // Callback to be invoked after NotifyExtensions() completes. The
+ // |new_virtual_path| should be set to a new path if an extension wishes to
+ // override the download path. |conflict_action| should be set to the action
+ // to take if a file exists at |new_virtual_path|. If |new_virtual_path| is
+ // empty, then the download target will be unchanged and |conflict_action| is
+ // ignored.
+ typedef base::Callback<void(
+ const base::FilePath& new_virtual_path,
+ DownloadPathReservationTracker::FilenameConflictAction conflict_action)>
+ NotifyExtensionsCallback;
+
+ // Callback to be invoked when ReserveVirtualPath() completes. If the path
+ // reservation is successful, then |successful| should be true and
+ // |reserved_path| should contain the reserved path. Otherwise, |successful|
+ // should be false. In the failure case, |reserved_path| is ignored.
+ typedef base::Callback<void(const base::FilePath& reserved_path,
+ bool successful)> ReservedPathCallback;
+
+ // Callback to be invoked when PromptUserForDownloadPath() completes.
+ // |virtual_path|: The path chosen by the user. If the user cancels the file
+ // selection, then this parameter will be the empty path. On Chrome OS,
+ // this path may contain virtual mount points if the user chose a virtual
+ // path (e.g. Google Drive).
+ typedef base::Callback<void(const base::FilePath& virtual_path)>
+ FileSelectedCallback;
+
+ // Callback to be invoked when DetermineLocalPath() completes. The argument
+ // should be the determined local path. It should be non-empty on success. If
+ // |virtual_path| is already a local path, then |virtual_path| should be
+ // returned as-is.
+ typedef base::Callback<void(const base::FilePath&)> LocalPathCallback;
+
+ // Callback to be invoked after CheckDownloadUrl() completes. The parameter to
+ // the callback should indicate the danger type of the download based on the
+ // results of the URL check.
+ typedef base::Callback<void(content::DownloadDangerType danger_type)>
+ CheckDownloadUrlCallback;
+
+ // Notifies extensions of the impending filename determination. |virtual_path|
+ // is the current suggested virtual path. The |callback| should be invoked to
+ // indicate whether any extensions wish to override the path.
+ virtual void NotifyExtensions(content::DownloadItem* download,
+ const base::FilePath& virtual_path,
+ const NotifyExtensionsCallback& callback) = 0;
+
+ // Reserve |virtual_path|. This is expected to check the following:
+ // - Whether |virtual_path| can be written to by the user. If not, the
+ // |virtual_path| can be changed to writeable path if necessary.
+ // - If |conflict_action| is UNIQUIFY then |virtual_path| should be modified
+ // so that the new path is writeable and unique.
+ //
+ // |callback| should be invoked on completion with the results.
+ virtual void ReserveVirtualPath(
+ content::DownloadItem* download,
+ const base::FilePath& virtual_path,
+ DownloadPathReservationTracker::FilenameConflictAction conflict_action,
+ const ReservedPathCallback& callback) = 0;
+
+ // Display a prompt to the user requesting that a download target be chosen.
+ // Should invoke |callback| upon completion.
+ virtual void PromptUserForDownloadPath(
+ content::DownloadItem* download,
+ const base::FilePath& virtual_path,
+ const FileSelectedCallback& callback) = 0;
+
+ // If |virtual_path| is not a local path, should return a possibly temporary
+ // local path to use for storing the downloaded file. If |virtual_path| is
+ // already local, then it should return the same path. |callback| should be
+ // invoked to return the path.
+ virtual void DetermineLocalPath(content::DownloadItem* download,
+ const base::FilePath& virtual_path,
+ const LocalPathCallback& callback) = 0;
+
+ // Check whether the download URL is malicious and invoke |callback| with a
+ // suggested danger type for the download.
+ virtual void CheckDownloadUrl(content::DownloadItem* download,
+ const base::FilePath& virtual_path,
+ const CheckDownloadUrlCallback& callback) = 0;
+
+ protected:
+ virtual ~DownloadTargetDeterminerDelegate();
+};
+
+#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_DETERMINER_DELEGATE_H_
« no previous file with comments | « chrome/browser/download/download_target_determiner.cc ('k') | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698