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

Side by Side Diff: content/public/browser/download_manager_delegate.h

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use a callback with DetermineDownloadTarget(). Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 6 #define CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/public/browser/download_danger_type.h"
16 #include "content/public/browser/download_item.h"
15 #include "content/public/browser/save_page_type.h" 17 #include "content/public/browser/save_page_type.h"
16 18
17 namespace content { 19 namespace content {
18 20
19 class DownloadId; 21 class DownloadId;
20 class DownloadItem;
21 class WebContents; 22 class WebContents;
22 23
23 // Called by SavePackage when it creates a DownloadItem. 24 // Called by SavePackage when it creates a DownloadItem.
24 typedef base::Callback<void(DownloadItem*)> 25 typedef base::Callback<void(DownloadItem*)>
25 SavePackageDownloadCreatedCallback; 26 SavePackageDownloadCreatedCallback;
26 27
27 // Will be called asynchronously with the results of the ChooseSavePath 28 // Will be called asynchronously with the results of the ChooseSavePath
28 // operation. If the delegate wants notification of the download item created 29 // operation. If the delegate wants notification of the download item created
29 // in response to this operation, the SavePackageDownloadCreatedCallback will be 30 // in response to this operation, the SavePackageDownloadCreatedCallback will be
30 // non-null. 31 // non-null.
31 typedef base::Callback<void(const FilePath&, 32 typedef base::Callback<void(const FilePath&,
32 content::SavePageType, 33 content::SavePageType,
33 const SavePackageDownloadCreatedCallback&)> 34 const SavePackageDownloadCreatedCallback&)>
34 SavePackagePathPickedCallback; 35 SavePackagePathPickedCallback;
35 36
37 typedef base::Callback<void(
38 const FilePath& target_path,
39 content::DownloadItem::TargetDisposition disposition,
40 content::DownloadDangerType danger_type,
41 const FilePath& intermediate_path)> DownloadTargetCallback;
42
36 // Browser's download manager: manages all downloads and destination view. 43 // Browser's download manager: manages all downloads and destination view.
37 class CONTENT_EXPORT DownloadManagerDelegate { 44 class CONTENT_EXPORT DownloadManagerDelegate {
38 public: 45 public:
39 // Lets the delegate know that the download manager is shutting down. 46 // Lets the delegate know that the download manager is shutting down.
40 virtual void Shutdown() {} 47 virtual void Shutdown() {}
41 48
42 // Returns a new DownloadId. 49 // Returns a new DownloadId.
43 virtual DownloadId GetNextId(); 50 virtual DownloadId GetNextId();
44 51
45 // Notifies the delegate that a download is starting. The delegate can return 52 // The delegate needs to generate a filename for the new download |item|. Once
46 // false to delay the start of the download, in which case it should call 53 // the target information has been determined, the delegate is required to
47 // DownloadManager::RestartDownload when it's ready. 54 // call DownloadItem::OnDownloadTargetDetermined(). This function should
Randy Smith (Not in Mondays) 2012/07/10 18:33:09 nit: "... required to call the callback."
asanka 2012/07/11 20:03:32 Done.
48 virtual bool ShouldStartDownload(int32 download_id); 55 // return |true| if it has or will invoke |callback|. If it returns |false|,
49 56 // the download manager will continue the download using a default, possibly
50 // Asks the user for the path for a download. The delegate calls 57 // empty, target path.
Randy Smith (Not in Mondays) 2012/07/10 18:33:09 nit: If you're allowing the callback to be invoked
asanka 2012/07/11 20:03:32 Done.
51 // DownloadManager::FileSelected or DownloadManager::FileSelectionCanceled to 58 virtual bool DetermineDownloadTarget(DownloadItem* item,
52 // give the answer. 59 const DownloadTargetCallback& callback);
53 virtual void ChooseDownloadPath(DownloadItem* item) {}
54
55 // Allows the embedder to set an intermediate name for the download until it's
56 // complete. The return value is the intermediate path to use. If the embedder
57 // doesn't want to set an intermediate path, it should return
58 // item.GetTargetFilePath(). If there's already a file at the returned path,
59 // it will not be overwritten. Instead the path will be uniquified by adding a
60 // suffix to the filename.
61 virtual FilePath GetIntermediatePath(const DownloadItem& item);
62 60
63 // Called when the download system wants to alert a WebContents that a 61 // Called when the download system wants to alert a WebContents that a
64 // download has started, but the TabConetnts has gone away. This lets an 62 // download has started, but the TabConetnts has gone away. This lets an
65 // delegate return an alternative WebContents. The delegate can return NULL. 63 // delegate return an alternative WebContents. The delegate can return NULL.
66 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload(); 64 virtual WebContents* GetAlternativeWebContentsToNotifyForDownload();
67 65
68 // Tests if a file type should be opened automatically. 66 // Tests if a file type should be opened automatically.
69 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path); 67 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path);
70 68
71 // Allows the delegate to delay completion of the download. This function 69 // Allows the delegate to delay completion of the download. This function
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 108
111 // Notifies the delegate that it should remove the download item from its 109 // Notifies the delegate that it should remove the download item from its
112 // persistent store. 110 // persistent store.
113 virtual void RemoveItemFromPersistentStore(DownloadItem* item) {} 111 virtual void RemoveItemFromPersistentStore(DownloadItem* item) {}
114 112
115 // Notifies the delegate to remove downloads from the given time range. 113 // Notifies the delegate to remove downloads from the given time range.
116 virtual void RemoveItemsFromPersistentStoreBetween( 114 virtual void RemoveItemsFromPersistentStoreBetween(
117 base::Time remove_begin, 115 base::Time remove_begin,
118 base::Time remove_end) {} 116 base::Time remove_end) {}
119 117
118 // Invoked when history is being cleared to clear the delegate's transient
119 // state.
120 virtual void ClearTransientState() {}
121
120 // Retrieve the directories to save html pages and downloads to. 122 // Retrieve the directories to save html pages and downloads to.
121 virtual void GetSaveDir(WebContents* web_contents, 123 virtual void GetSaveDir(WebContents* web_contents,
122 FilePath* website_save_dir, 124 FilePath* website_save_dir,
123 FilePath* download_save_dir, 125 FilePath* download_save_dir,
124 bool* skip_dir_check) {} 126 bool* skip_dir_check) {}
125 127
126 // Asks the user for the path to save a page. The delegate calls the callback 128 // Asks the user for the path to save a page. The delegate calls the callback
127 // to give the answer. 129 // to give the answer.
128 virtual void ChooseSavePath(WebContents* web_contents, 130 virtual void ChooseSavePath(WebContents* web_contents,
129 const FilePath& suggested_path, 131 const FilePath& suggested_path,
130 const FilePath::StringType& default_extension, 132 const FilePath::StringType& default_extension,
131 bool can_save_as_complete, 133 bool can_save_as_complete,
132 const SavePackagePathPickedCallback& callback) { 134 const SavePackagePathPickedCallback& callback) {
133 } 135 }
134 136
135 protected: 137 protected:
136 virtual ~DownloadManagerDelegate(); 138 virtual ~DownloadManagerDelegate();
137 }; 139 };
138 140
139 } // namespace content 141 } // namespace content
140 142
141 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ 143 #endif // CONTENT_PUBLIC_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698