OLD | NEW |
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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "chrome/browser/common/cancelable_request.h" |
| 13 #include "chrome/browser/download/download_path_reservation_tracker.h" |
| 14 #include "chrome/browser/history/history.h" |
13 #include "chrome/browser/safe_browsing/download_protection_service.h" | 15 #include "chrome/browser/safe_browsing/download_protection_service.h" |
14 #include "chrome/browser/download/download_path_reservation_tracker.h" | |
15 #include "content/public/browser/download_danger_type.h" | 16 #include "content/public/browser/download_danger_type.h" |
16 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
17 #include "content/public/browser/download_manager_delegate.h" | 18 #include "content/public/browser/download_manager_delegate.h" |
18 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
20 | 21 |
21 class DownloadHistory; | |
22 class DownloadPrefs; | 22 class DownloadPrefs; |
23 class ExtensionDownloadsEventRouter; | 23 class ExtensionDownloadsEventRouter; |
24 class Profile; | 24 class Profile; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 class DownloadManager; | 27 class DownloadManager; |
28 } | 28 } |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 class CrxInstaller; | 31 class CrxInstaller; |
(...skipping 18 matching lines...) Expand all Loading... |
50 public: | 50 public: |
51 // Callback type used with ChooseDownloadPath(). The callback should be | 51 // Callback type used with ChooseDownloadPath(). The callback should be |
52 // invoked with the user-selected path as the argument. If the file selection | 52 // invoked with the user-selected path as the argument. If the file selection |
53 // was canceled, the argument should be the empty path. | 53 // was canceled, the argument should be the empty path. |
54 typedef base::Callback<void(const FilePath&)> FileSelectedCallback; | 54 typedef base::Callback<void(const FilePath&)> FileSelectedCallback; |
55 | 55 |
56 explicit ChromeDownloadManagerDelegate(Profile* profile); | 56 explicit ChromeDownloadManagerDelegate(Profile* profile); |
57 | 57 |
58 void SetDownloadManager(content::DownloadManager* dm); | 58 void SetDownloadManager(content::DownloadManager* dm); |
59 | 59 |
60 // Should be called before the call to ShouldCompleteDownload() to | 60 // Should be called before the first call to ShouldCompleteDownload() to |
61 // disable SafeBrowsing checks for |item|. | 61 // disable SafeBrowsing checks for |item|. |
62 static void DisableSafeBrowsing(content::DownloadItem* item); | 62 static void DisableSafeBrowsing(content::DownloadItem* item); |
63 | 63 |
64 // content::DownloadManagerDelegate | 64 // content::DownloadManagerDelegate |
65 virtual void Shutdown() OVERRIDE; | 65 virtual void Shutdown() OVERRIDE; |
66 virtual content::DownloadId GetNextId() OVERRIDE; | 66 virtual content::DownloadId GetNextId() OVERRIDE; |
67 virtual bool DetermineDownloadTarget( | 67 virtual bool DetermineDownloadTarget( |
68 content::DownloadItem* item, | 68 content::DownloadItem* item, |
69 const content::DownloadTargetCallback& callback) OVERRIDE; | 69 const content::DownloadTargetCallback& callback) OVERRIDE; |
70 virtual content::WebContents* | 70 virtual content::WebContents* |
71 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; | 71 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; |
72 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 72 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
73 virtual bool ShouldCompleteDownload( | 73 virtual bool ShouldCompleteDownload( |
74 content::DownloadItem* item, | 74 content::DownloadItem* item, |
75 const base::Closure& complete_callback) OVERRIDE; | 75 const base::Closure& complete_callback) OVERRIDE; |
76 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; | 76 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; |
77 virtual bool GenerateFileHash() OVERRIDE; | 77 virtual bool GenerateFileHash() OVERRIDE; |
78 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; | |
79 virtual void UpdateItemInPersistentStore( | |
80 content::DownloadItem* item) OVERRIDE; | |
81 virtual void UpdatePathForItemInPersistentStore( | |
82 content::DownloadItem* item, | |
83 const FilePath& new_path) OVERRIDE; | |
84 virtual void RemoveItemFromPersistentStore( | |
85 content::DownloadItem* item) OVERRIDE; | |
86 virtual void RemoveItemsFromPersistentStoreBetween( | |
87 base::Time remove_begin, | |
88 base::Time remove_end) OVERRIDE; | |
89 virtual void GetSaveDir(content::BrowserContext* browser_context, | 78 virtual void GetSaveDir(content::BrowserContext* browser_context, |
90 FilePath* website_save_dir, | 79 FilePath* website_save_dir, |
91 FilePath* download_save_dir, | 80 FilePath* download_save_dir, |
92 bool* skip_dir_check) OVERRIDE; | 81 bool* skip_dir_check) OVERRIDE; |
93 virtual void ChooseSavePath( | 82 virtual void ChooseSavePath( |
94 content::WebContents* web_contents, | 83 content::WebContents* web_contents, |
95 const FilePath& suggested_path, | 84 const FilePath& suggested_path, |
96 const FilePath::StringType& default_extension, | 85 const FilePath::StringType& default_extension, |
97 bool can_save_as_complete, | 86 bool can_save_as_complete, |
98 const content::SavePackagePathPickedCallback& callback) OVERRIDE; | 87 const content::SavePackagePathPickedCallback& callback) OVERRIDE; |
99 | 88 |
100 // Clears the last directory chosen by the user in response to a file chooser | 89 // Clears the last directory chosen by the user in response to a file chooser |
101 // prompt. Called when clearing recent history. | 90 // prompt. Called when clearing recent history. |
102 void ClearLastDownloadPath(); | 91 void ClearLastDownloadPath(); |
103 | 92 |
104 DownloadPrefs* download_prefs() { return download_prefs_.get(); } | 93 DownloadPrefs* download_prefs() { return download_prefs_.get(); } |
105 DownloadHistory* download_history() { return download_history_.get(); } | |
106 | 94 |
107 protected: | 95 protected: |
108 // So that test classes can inherit from this for override purposes. | 96 // So that test classes can inherit from this for override purposes. |
109 virtual ~ChromeDownloadManagerDelegate(); | 97 virtual ~ChromeDownloadManagerDelegate(); |
110 | 98 |
111 // Returns the SafeBrowsing download protection service if it's | 99 // Returns the SafeBrowsing download protection service if it's |
112 // enabled. Returns NULL otherwise. Protected virtual for testing. | 100 // enabled. Returns NULL otherwise. Protected virtual for testing. |
113 virtual safe_browsing::DownloadProtectionService* | 101 virtual safe_browsing::DownloadProtectionService* |
114 GetDownloadProtectionService(); | 102 GetDownloadProtectionService(); |
115 | 103 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const content::DownloadTargetCallback& callback, | 146 const content::DownloadTargetCallback& callback, |
159 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 147 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
160 | 148 |
161 // Callback function after the DownloadProtectionService completes. | 149 // Callback function after the DownloadProtectionService completes. |
162 void CheckClientDownloadDone( | 150 void CheckClientDownloadDone( |
163 int32 download_id, | 151 int32 download_id, |
164 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 152 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
165 | 153 |
166 // Callback function after we check whether the referrer URL has been visited | 154 // Callback function after we check whether the referrer URL has been visited |
167 // before today. Determines the danger state of the download based on the file | 155 // before today. Determines the danger state of the download based on the file |
168 // type and |visited_referrer_before|. Generates a target path for the | 156 // type, |found_visits|, |count|, |first_visit|. Generates a target path for |
169 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get | 157 // the download. Invokes |DownloadPathReservationTracker::GetReservedPath| to |
170 // a reserved path for the download. The path is then passed into | 158 // get a reserved path for the download. The path is then passed into |
171 // OnPathReservationAvailable(). | 159 // OnPathReservationAvailable(). |
172 void CheckVisitedReferrerBeforeDone( | 160 void CheckVisitedReferrerBeforeDone( |
173 int32 download_id, | 161 int32 download_id, |
174 const content::DownloadTargetCallback& callback, | 162 const content::DownloadTargetCallback& callback, |
175 content::DownloadDangerType danger_type, | 163 content::DownloadDangerType danger_type, |
176 bool visited_referrer_before); | 164 bool visited_referrer_before); |
177 | 165 |
178 #if defined (OS_CHROMEOS) | 166 #if defined (OS_CHROMEOS) |
179 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls | 167 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls |
180 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path | 168 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path |
181 // for the download. The path is then passed into | 169 // for the download. The path is then passed into |
182 // OnPathReservationAvailable(). | 170 // OnPathReservationAvailable(). |
183 void SubstituteDriveDownloadPathCallback( | 171 void SubstituteDriveDownloadPathCallback( |
184 int32 download_id, | 172 int32 download_id, |
185 const content::DownloadTargetCallback& callback, | 173 const content::DownloadTargetCallback& callback, |
186 bool should_prompt, | 174 bool should_prompt, |
(...skipping 19 matching lines...) Expand all Loading... |
206 bool reserved_path_verified); | 194 bool reserved_path_verified); |
207 | 195 |
208 // Called on the UI thread once the final target path is available. | 196 // Called on the UI thread once the final target path is available. |
209 void OnTargetPathDetermined( | 197 void OnTargetPathDetermined( |
210 int32 download_id, | 198 int32 download_id, |
211 const content::DownloadTargetCallback& callback, | 199 const content::DownloadTargetCallback& callback, |
212 content::DownloadItem::TargetDisposition disposition, | 200 content::DownloadItem::TargetDisposition disposition, |
213 content::DownloadDangerType danger_type, | 201 content::DownloadDangerType danger_type, |
214 const FilePath& target_path); | 202 const FilePath& target_path); |
215 | 203 |
216 // Callback from history system. | |
217 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | |
218 | |
219 // Check policy of whether we should open this download with a web intents | 204 // Check policy of whether we should open this download with a web intents |
220 // dispatch. | 205 // dispatch. |
221 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 206 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
222 | 207 |
223 // Open the given item with a web intent dispatch. | 208 // Open the given item with a web intent dispatch. |
224 void OpenWithWebIntent(const content::DownloadItem* item); | 209 void OpenWithWebIntent(const content::DownloadItem* item); |
225 | 210 |
226 // Internal gateways for ShouldCompleteDownload(). | 211 // Internal gateways for ShouldCompleteDownload(). |
227 bool IsDownloadReadyForCompletion( | 212 bool IsDownloadReadyForCompletion( |
228 content::DownloadItem* item, | 213 content::DownloadItem* item, |
229 const base::Closure& internal_complete_callback); | 214 const base::Closure& internal_complete_callback); |
230 void ShouldCompleteDownloadInternal( | 215 void ShouldCompleteDownloadInternal( |
231 int download_id, | 216 int download_id, |
232 const base::Closure& user_complete_callback); | 217 const base::Closure& user_complete_callback); |
233 | 218 |
234 Profile* profile_; | 219 Profile* profile_; |
235 int next_download_id_; | 220 int next_download_id_; |
236 scoped_ptr<DownloadPrefs> download_prefs_; | 221 scoped_ptr<DownloadPrefs> download_prefs_; |
237 scoped_ptr<DownloadHistory> download_history_; | |
238 | 222 |
239 // Maps from pending extension installations to DownloadItem IDs. | 223 // Maps from pending extension installations to DownloadItem IDs. |
240 typedef base::hash_map<extensions::CrxInstaller*, int> CrxInstallerMap; | 224 typedef base::hash_map<extensions::CrxInstaller*, int> CrxInstallerMap; |
241 CrxInstallerMap crx_installers_; | 225 CrxInstallerMap crx_installers_; |
242 | 226 |
| 227 CancelableRequestConsumer history_consumer_; |
| 228 |
243 content::NotificationRegistrar registrar_; | 229 content::NotificationRegistrar registrar_; |
244 | 230 |
245 // On Android, GET downloads are not handled by the DownloadManager. | 231 // On Android, GET downloads are not handled by the DownloadManager. |
246 // Once we have extensions on android, we probably need the EventRouter | 232 // Once we have extensions on android, we probably need the EventRouter |
247 // in ContentViewDownloadDelegate which knows about both GET and POST | 233 // in ContentViewDownloadDelegate which knows about both GET and POST |
248 // downloads. | 234 // downloads. |
249 #if !defined(OS_ANDROID) | 235 #if !defined(OS_ANDROID) |
250 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | 236 // The ExtensionDownloadsEventRouter dispatches download creation, change, and |
251 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | 237 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a |
252 // chrome-level concept and its lifetime should match DownloadManager. There | 238 // chrome-level concept and its lifetime should match DownloadManager. There |
253 // should be a separate EDER for on-record and off-record managers. | 239 // should be a separate EDER for on-record and off-record managers. |
254 // There does not appear to be a separate ExtensionSystem for on-record and | 240 // There does not appear to be a separate ExtensionSystem for on-record and |
255 // off-record profiles, so ExtensionSystem cannot own the EDER. | 241 // off-record profiles, so ExtensionSystem cannot own the EDER. |
256 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; | 242 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; |
257 #endif | 243 #endif |
258 | 244 |
259 // The directory most recently chosen by the user in response to a Save As | 245 // The directory most recently chosen by the user in response to a Save As |
260 // dialog for a regular download. | 246 // dialog for a regular download. |
261 FilePath last_download_path_; | 247 FilePath last_download_path_; |
262 | 248 |
263 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 249 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
264 }; | 250 }; |
265 | 251 |
266 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 252 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |