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

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.h

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r148594 to and resolve conflicts with r148576 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 CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_
6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ 6 #define CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/hash_tables.h" 9 #include "base/hash_tables.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 30 matching lines...) Expand all
41 }; 41 };
42 } // namespace BASE_HASH_NAMESPACE 42 } // namespace BASE_HASH_NAMESPACE
43 #endif 43 #endif
44 44
45 // This is the Chrome side helper for the download system. 45 // This is the Chrome side helper for the download system.
46 class ChromeDownloadManagerDelegate 46 class ChromeDownloadManagerDelegate
47 : public base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>, 47 : public base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>,
48 public content::DownloadManagerDelegate, 48 public content::DownloadManagerDelegate,
49 public content::NotificationObserver { 49 public content::NotificationObserver {
50 public: 50 public:
51 // Callback type used with ChooseDownloadPath(). The callback should be
52 // invoked with the user-selected path as the argument. If the file selection
53 // was canceled, the argument should be the empty path.
54 typedef base::Callback<void(const FilePath&)> FileSelectedCallback;
55
51 explicit ChromeDownloadManagerDelegate(Profile* profile); 56 explicit ChromeDownloadManagerDelegate(Profile* profile);
52 57
53 void SetDownloadManager(content::DownloadManager* dm); 58 void SetDownloadManager(content::DownloadManager* dm);
54 59
55 // Should be called before the first call to ShouldCompleteDownload() to 60 // Should be called before the first call to ShouldCompleteDownload() to
56 // disable SafeBrowsing checks for |item|. 61 // disable SafeBrowsing checks for |item|.
57 static void DisableSafeBrowsing(content::DownloadItem* item); 62 static void DisableSafeBrowsing(content::DownloadItem* item);
58 63
64 // content::DownloadManagerDelegate
59 virtual void Shutdown() OVERRIDE; 65 virtual void Shutdown() OVERRIDE;
60 virtual content::DownloadId GetNextId() OVERRIDE; 66 virtual content::DownloadId GetNextId() OVERRIDE;
61 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; 67 virtual bool DetermineDownloadTarget(
62 virtual void ChooseDownloadPath(content::DownloadItem* item) OVERRIDE; 68 content::DownloadItem* item,
63 virtual FilePath GetIntermediatePath( 69 const content::DownloadTargetCallback& callback) OVERRIDE;
64 const content::DownloadItem& item) OVERRIDE;
65 virtual content::WebContents* 70 virtual content::WebContents*
66 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; 71 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE;
67 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; 72 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE;
68 virtual bool ShouldCompleteDownload( 73 virtual bool ShouldCompleteDownload(
69 content::DownloadItem* item, 74 content::DownloadItem* item,
70 const base::Closure& complete_callback) OVERRIDE; 75 const base::Closure& complete_callback) OVERRIDE;
71 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; 76 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE;
72 virtual bool GenerateFileHash() OVERRIDE; 77 virtual bool GenerateFileHash() OVERRIDE;
73 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; 78 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE;
74 virtual void UpdateItemInPersistentStore( 79 virtual void UpdateItemInPersistentStore(
(...skipping 10 matching lines...) Expand all
85 FilePath* website_save_dir, 90 FilePath* website_save_dir,
86 FilePath* download_save_dir, 91 FilePath* download_save_dir,
87 bool* skip_dir_check) OVERRIDE; 92 bool* skip_dir_check) OVERRIDE;
88 virtual void ChooseSavePath( 93 virtual void ChooseSavePath(
89 content::WebContents* web_contents, 94 content::WebContents* web_contents,
90 const FilePath& suggested_path, 95 const FilePath& suggested_path,
91 const FilePath::StringType& default_extension, 96 const FilePath::StringType& default_extension,
92 bool can_save_as_complete, 97 bool can_save_as_complete,
93 const content::SavePackagePathPickedCallback& callback) OVERRIDE; 98 const content::SavePackagePathPickedCallback& callback) OVERRIDE;
94 99
100 // Clears the last directory chosen by the user in response to a file chooser
101 // prompt. Called when clearing recent history.
102 void ClearLastDownloadPath();
103
95 DownloadPrefs* download_prefs() { return download_prefs_.get(); } 104 DownloadPrefs* download_prefs() { return download_prefs_.get(); }
96 DownloadHistory* download_history() { return download_history_.get(); } 105 DownloadHistory* download_history() { return download_history_.get(); }
97 106
98 protected: 107 protected:
99 // So that test classes can inherit from this for override purposes. 108 // So that test classes can inherit from this for override purposes.
100 virtual ~ChromeDownloadManagerDelegate(); 109 virtual ~ChromeDownloadManagerDelegate();
101 110
102 // Returns the SafeBrowsing download protection service if it's 111 // Returns the SafeBrowsing download protection service if it's
103 // enabled. Returns NULL otherwise. Protected virtual for testing. 112 // enabled. Returns NULL otherwise. Protected virtual for testing.
104 virtual safe_browsing::DownloadProtectionService* 113 virtual safe_browsing::DownloadProtectionService*
105 GetDownloadProtectionService(); 114 GetDownloadProtectionService();
106 115
107 // Returns true if this download should show the "dangerous file" warning. 116 // Returns true if this download should show the "dangerous file" warning.
108 // Various factors are considered, such as the type of the file, whether a 117 // Various factors are considered, such as the type of the file, whether a
109 // user action initiated the download, and whether the user has explicitly 118 // user action initiated the download, and whether the user has explicitly
110 // marked the file type as "auto open". Protected virtual for testing. 119 // marked the file type as "auto open". Protected virtual for testing.
111 virtual bool IsDangerousFile(const content::DownloadItem& download, 120 virtual bool IsDangerousFile(const content::DownloadItem& download,
112 const FilePath& suggested_path, 121 const FilePath& suggested_path,
113 bool visited_referrer_before); 122 bool visited_referrer_before);
114 123
115 // Obtains a path reservation by calling 124 // Obtains a path reservation by calling
116 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for 125 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for
117 // testing. 126 // testing.
118 virtual void GetReservedPath( 127 virtual void GetReservedPath(
119 content::DownloadItem& download, 128 content::DownloadItem& download,
120 const FilePath& target_path, 129 const FilePath& target_path,
121 const FilePath& default_download_path, 130 const FilePath& default_download_path,
122 bool should_uniquify_path, 131 bool should_uniquify_path,
123 const DownloadPathReservationTracker::ReservedPathCallback callback); 132 const DownloadPathReservationTracker::ReservedPathCallback& callback);
133
134 // Displays the file chooser dialog to prompt the user for the download
135 // location for |item|. |suggested_path| will be used as the initial download
136 // path. Once a location is available |callback| will be invoked with the
137 // selected full path. If the user cancels the dialog, then an empty FilePath
138 // will be passed into |callback|. Protected virtual for testing.
139 virtual void ChooseDownloadPath(content::DownloadItem* item,
140 const FilePath& suggested_path,
141 const FileSelectedCallback& callback);
124 142
125 // So that test classes that inherit from this for override purposes 143 // So that test classes that inherit from this for override purposes
126 // can call back into the DownloadManager. 144 // can call back into the DownloadManager.
127 scoped_refptr<content::DownloadManager> download_manager_; 145 scoped_refptr<content::DownloadManager> download_manager_;
128 146
129 private: 147 private:
130 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; 148 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>;
131 149
132 // content::NotificationObserver implementation. 150 // content::NotificationObserver implementation.
133 virtual void Observe(int type, 151 virtual void Observe(int type,
134 const content::NotificationSource& source, 152 const content::NotificationSource& source,
135 const content::NotificationDetails& details) OVERRIDE; 153 const content::NotificationDetails& details) OVERRIDE;
136 154
137 // Callback function after url is checked with safebrowsing service. 155 // Callback function after url is checked with safebrowsing service.
138 void CheckDownloadUrlDone( 156 void CheckDownloadUrlDone(
139 int32 download_id, 157 int32 download_id,
158 const content::DownloadTargetCallback& callback,
140 safe_browsing::DownloadProtectionService::DownloadCheckResult result); 159 safe_browsing::DownloadProtectionService::DownloadCheckResult result);
141 160
142 // Callback function after the DownloadProtectionService completes. 161 // Callback function after the DownloadProtectionService completes.
143 void CheckClientDownloadDone( 162 void CheckClientDownloadDone(
144 int32 download_id, 163 int32 download_id,
145 safe_browsing::DownloadProtectionService::DownloadCheckResult result); 164 safe_browsing::DownloadProtectionService::DownloadCheckResult result);
146 165
147 // Callback function after we check whether the referrer URL has been visited 166 // Callback function after we check whether the referrer URL has been visited
148 // before today. Determines the danger state of the download based on the file 167 // before today. Determines the danger state of the download based on the file
149 // type and |visited_referrer_before|. Generates a target path for the 168 // type and |visited_referrer_before|. Generates a target path for the
150 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get 169 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get
151 // a reserved path for the download. The path is then passed into 170 // a reserved path for the download. The path is then passed into
152 // OnPathReservationAvailable(). 171 // OnPathReservationAvailable().
153 void CheckVisitedReferrerBeforeDone(int32 download_id, 172 void CheckVisitedReferrerBeforeDone(
154 content::DownloadDangerType danger_type, 173 int32 download_id,
155 bool visited_referrer_before); 174 const content::DownloadTargetCallback& callback,
175 content::DownloadDangerType danger_type,
176 bool visited_referrer_before);
156 177
157 #if defined (OS_CHROMEOS) 178 #if defined (OS_CHROMEOS)
158 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls 179 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls
159 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path 180 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path
160 // for the download. The path is then passed into 181 // for the download. The path is then passed into
161 // OnPathReservationAvailable(). 182 // OnPathReservationAvailable().
162 void SubstituteGDataDownloadPathCallback( 183 void SubstituteGDataDownloadPathCallback(
163 int32 download_id, 184 int32 download_id,
185 const content::DownloadTargetCallback& callback,
164 bool should_prompt, 186 bool should_prompt,
165 bool is_forced_path, 187 bool is_forced_path,
166 content::DownloadDangerType danger_type, 188 content::DownloadDangerType danger_type,
167 const FilePath& unverified_path); 189 const FilePath& unverified_path);
168 #endif 190 #endif
169 191
192 // Determine the intermediate path to use for |target_path|. |danger_type|
193 // specifies the danger level of the download.
194 FilePath GetIntermediatePath(const FilePath& target_path,
195 content::DownloadDangerType danger_type);
196
170 // Called on the UI thread once a reserved path is available. Updates the 197 // Called on the UI thread once a reserved path is available. Updates the
171 // download identified by |download_id| with the |target_path|, target 198 // download identified by |download_id| with the |target_path|, target
172 // disposition and |danger_type|. 199 // disposition and |danger_type|.
173 void OnPathReservationAvailable( 200 void OnPathReservationAvailable(
174 int32 download_id, 201 int32 download_id,
202 const content::DownloadTargetCallback& callback,
175 bool should_prompt, 203 bool should_prompt,
176 content::DownloadDangerType danger_type, 204 content::DownloadDangerType danger_type,
177 const FilePath& target_path, 205 const FilePath& reserved_path,
178 bool target_path_verified); 206 bool reserved_path_verified);
207
208 // Called on the UI thread once the final target path is available.
209 void OnTargetPathDetermined(
210 int32 download_id,
211 const content::DownloadTargetCallback& callback,
212 content::DownloadItem::TargetDisposition disposition,
213 content::DownloadDangerType danger_type,
214 const FilePath& target_path);
179 215
180 // Callback from history system. 216 // Callback from history system.
181 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); 217 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle);
182 218
183 // Check policy of whether we should open this download with a web intents 219 // Check policy of whether we should open this download with a web intents
184 // dispatch. 220 // dispatch.
185 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); 221 bool ShouldOpenWithWebIntents(const content::DownloadItem* item);
186 222
187 // Open the given item with a web intent dispatch. 223 // Open the given item with a web intent dispatch.
188 void OpenWithWebIntent(const content::DownloadItem* item); 224 void OpenWithWebIntent(const content::DownloadItem* item);
(...skipping 24 matching lines...) Expand all
213 #if !defined(OS_ANDROID) 249 #if !defined(OS_ANDROID)
214 // The ExtensionDownloadsEventRouter dispatches download creation, change, and 250 // The ExtensionDownloadsEventRouter dispatches download creation, change, and
215 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a 251 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
216 // chrome-level concept and its lifetime should match DownloadManager. There 252 // chrome-level concept and its lifetime should match DownloadManager. There
217 // should be a separate EDER for on-record and off-record managers. 253 // should be a separate EDER for on-record and off-record managers.
218 // There does not appear to be a separate ExtensionSystem for on-record and 254 // There does not appear to be a separate ExtensionSystem for on-record and
219 // off-record profiles, so ExtensionSystem cannot own the EDER. 255 // off-record profiles, so ExtensionSystem cannot own the EDER.
220 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; 256 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_;
221 #endif 257 #endif
222 258
259 // The directory most recently chosen by the user in response to a Save As
260 // dialog for a regular download.
261 FilePath last_download_path_;
262
223 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); 263 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate);
224 }; 264 };
225 265
226 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ 266 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover.cc ('k') | chrome/browser/download/chrome_download_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698