| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void CheckDownloadUrlDone( | 144 void CheckDownloadUrlDone( |
| 157 int32 download_id, | 145 int32 download_id, |
| 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 |
| 154 struct VisitedReferrerBeforeDoneParameters { |
| 155 VisitedReferrerBeforeDoneParameters(); |
| 156 ~VisitedReferrerBeforeDoneParameters(); |
| 157 int32 download_id; |
| 158 content::DownloadTargetCallback callback; |
| 159 content::DownloadDangerType danger_type; |
| 160 }; |
| 161 |
| 166 // Callback function after we check whether the referrer URL has been visited | 162 // 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 | 163 // 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 | 164 // type, |found_visits|, |count|, |first_visit|. Generates a target path for |
| 169 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get | 165 // the download. Invokes |DownloadPathReservationTracker::GetReservedPath| to |
| 170 // a reserved path for the download. The path is then passed into | 166 // get a reserved path for the download. The path is then passed into |
| 171 // OnPathReservationAvailable(). | 167 // OnPathReservationAvailable(). |
| 172 void CheckVisitedReferrerBeforeDone( | 168 void CheckVisitedReferrerBeforeDone( |
| 173 int32 download_id, | 169 const VisitedReferrerBeforeDoneParameters& params, |
| 174 const content::DownloadTargetCallback& callback, | 170 HistoryService::Handle unused_handle, |
| 175 content::DownloadDangerType danger_type, | 171 bool found_visits, |
| 176 bool visited_referrer_before); | 172 int count, |
| 173 base::Time first_visit); |
| 177 | 174 |
| 178 #if defined (OS_CHROMEOS) | 175 #if defined (OS_CHROMEOS) |
| 179 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls | 176 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls |
| 180 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path | 177 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path |
| 181 // for the download. The path is then passed into | 178 // for the download. The path is then passed into |
| 182 // OnPathReservationAvailable(). | 179 // OnPathReservationAvailable(). |
| 183 void SubstituteDriveDownloadPathCallback( | 180 void SubstituteDriveDownloadPathCallback( |
| 184 int32 download_id, | 181 int32 download_id, |
| 185 const content::DownloadTargetCallback& callback, | 182 const content::DownloadTargetCallback& callback, |
| 186 bool should_prompt, | 183 bool should_prompt, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 206 bool reserved_path_verified); | 203 bool reserved_path_verified); |
| 207 | 204 |
| 208 // Called on the UI thread once the final target path is available. | 205 // Called on the UI thread once the final target path is available. |
| 209 void OnTargetPathDetermined( | 206 void OnTargetPathDetermined( |
| 210 int32 download_id, | 207 int32 download_id, |
| 211 const content::DownloadTargetCallback& callback, | 208 const content::DownloadTargetCallback& callback, |
| 212 content::DownloadItem::TargetDisposition disposition, | 209 content::DownloadItem::TargetDisposition disposition, |
| 213 content::DownloadDangerType danger_type, | 210 content::DownloadDangerType danger_type, |
| 214 const FilePath& target_path); | 211 const FilePath& target_path); |
| 215 | 212 |
| 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 | 213 // Check policy of whether we should open this download with a web intents |
| 220 // dispatch. | 214 // dispatch. |
| 221 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 215 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
| 222 | 216 |
| 223 // Open the given item with a web intent dispatch. | 217 // Open the given item with a web intent dispatch. |
| 224 void OpenWithWebIntent(const content::DownloadItem* item); | 218 void OpenWithWebIntent(const content::DownloadItem* item); |
| 225 | 219 |
| 226 // Internal gateways for ShouldCompleteDownload(). | 220 // Internal gateways for ShouldCompleteDownload(). |
| 227 bool IsDownloadReadyForCompletion( | 221 bool IsDownloadReadyForCompletion( |
| 228 content::DownloadItem* item, | 222 content::DownloadItem* item, |
| 229 const base::Closure& internal_complete_callback); | 223 const base::Closure& internal_complete_callback); |
| 230 void ShouldCompleteDownloadInternal( | 224 void ShouldCompleteDownloadInternal( |
| 231 int download_id, | 225 int download_id, |
| 232 const base::Closure& user_complete_callback); | 226 const base::Closure& user_complete_callback); |
| 233 | 227 |
| 234 Profile* profile_; | 228 Profile* profile_; |
| 235 int next_download_id_; | 229 int next_download_id_; |
| 236 scoped_ptr<DownloadPrefs> download_prefs_; | 230 scoped_ptr<DownloadPrefs> download_prefs_; |
| 237 scoped_ptr<DownloadHistory> download_history_; | |
| 238 | 231 |
| 239 // Maps from pending extension installations to DownloadItem IDs. | 232 // Maps from pending extension installations to DownloadItem IDs. |
| 240 typedef base::hash_map<extensions::CrxInstaller*, int> CrxInstallerMap; | 233 typedef base::hash_map<extensions::CrxInstaller*, int> CrxInstallerMap; |
| 241 CrxInstallerMap crx_installers_; | 234 CrxInstallerMap crx_installers_; |
| 242 | 235 |
| 236 CancelableRequestConsumer history_consumer_; |
| 237 |
| 243 content::NotificationRegistrar registrar_; | 238 content::NotificationRegistrar registrar_; |
| 244 | 239 |
| 245 // On Android, GET downloads are not handled by the DownloadManager. | 240 // On Android, GET downloads are not handled by the DownloadManager. |
| 246 // Once we have extensions on android, we probably need the EventRouter | 241 // Once we have extensions on android, we probably need the EventRouter |
| 247 // in ContentViewDownloadDelegate which knows about both GET and POST | 242 // in ContentViewDownloadDelegate which knows about both GET and POST |
| 248 // downloads. | 243 // downloads. |
| 249 #if !defined(OS_ANDROID) | 244 #if !defined(OS_ANDROID) |
| 250 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | 245 // The ExtensionDownloadsEventRouter dispatches download creation, change, and |
| 251 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | 246 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a |
| 252 // chrome-level concept and its lifetime should match DownloadManager. There | 247 // chrome-level concept and its lifetime should match DownloadManager. There |
| 253 // should be a separate EDER for on-record and off-record managers. | 248 // 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 | 249 // There does not appear to be a separate ExtensionSystem for on-record and |
| 255 // off-record profiles, so ExtensionSystem cannot own the EDER. | 250 // off-record profiles, so ExtensionSystem cannot own the EDER. |
| 256 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; | 251 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; |
| 257 #endif | 252 #endif |
| 258 | 253 |
| 259 // The directory most recently chosen by the user in response to a Save As | 254 // The directory most recently chosen by the user in response to a Save As |
| 260 // dialog for a regular download. | 255 // dialog for a regular download. |
| 261 FilePath last_download_path_; | 256 FilePath last_download_path_; |
| 262 | 257 |
| 263 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 258 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
| 264 }; | 259 }; |
| 265 | 260 |
| 266 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 261 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
| OLD | NEW |