| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 explicit ChromeDownloadManagerDelegate(Profile* profile); | 49 explicit ChromeDownloadManagerDelegate(Profile* profile); |
| 50 | 50 |
| 51 void SetDownloadManager(content::DownloadManager* dm); | 51 void SetDownloadManager(content::DownloadManager* dm); |
| 52 | 52 |
| 53 // Should be called before the first call to ShouldCompleteDownload() to | 53 // Should be called before the first call to ShouldCompleteDownload() to |
| 54 // disable SafeBrowsing checks for |item|. | 54 // disable SafeBrowsing checks for |item|. |
| 55 static void DisableSafeBrowsing(content::DownloadItem* item); | 55 static void DisableSafeBrowsing(content::DownloadItem* item); |
| 56 | 56 |
| 57 virtual void Shutdown() OVERRIDE; | 57 virtual void Shutdown() OVERRIDE; |
| 58 virtual content::DownloadId GetNextId() OVERRIDE; | 58 virtual content::DownloadId GetNextId() OVERRIDE; |
| 59 virtual bool ShouldStartDownload(int32 download_id) OVERRIDE; | 59 virtual bool DetermineDownloadTarget( |
| 60 virtual void ChooseDownloadPath(content::DownloadItem* item) OVERRIDE; | 60 content::DownloadItem* item, |
| 61 virtual FilePath GetIntermediatePath( | 61 const content::DownloadTargetCallback& callback) OVERRIDE; |
| 62 const content::DownloadItem& item) OVERRIDE; | |
| 63 virtual content::WebContents* | 62 virtual content::WebContents* |
| 64 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; | 63 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; |
| 65 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 64 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
| 66 virtual bool ShouldCompleteDownload( | 65 virtual bool ShouldCompleteDownload( |
| 67 content::DownloadItem* item, | 66 content::DownloadItem* item, |
| 68 const base::Closure& complete_callback) OVERRIDE; | 67 const base::Closure& complete_callback) OVERRIDE; |
| 69 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; | 68 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; |
| 70 virtual bool GenerateFileHash() OVERRIDE; | 69 virtual bool GenerateFileHash() OVERRIDE; |
| 71 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; | 70 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; |
| 72 virtual void UpdateItemInPersistentStore( | 71 virtual void UpdateItemInPersistentStore( |
| 73 content::DownloadItem* item) OVERRIDE; | 72 content::DownloadItem* item) OVERRIDE; |
| 74 virtual void UpdatePathForItemInPersistentStore( | 73 virtual void UpdatePathForItemInPersistentStore( |
| 75 content::DownloadItem* item, | 74 content::DownloadItem* item, |
| 76 const FilePath& new_path) OVERRIDE; | 75 const FilePath& new_path) OVERRIDE; |
| 77 virtual void RemoveItemFromPersistentStore( | 76 virtual void RemoveItemFromPersistentStore( |
| 78 content::DownloadItem* item) OVERRIDE; | 77 content::DownloadItem* item) OVERRIDE; |
| 79 virtual void RemoveItemsFromPersistentStoreBetween( | 78 virtual void RemoveItemsFromPersistentStoreBetween( |
| 80 base::Time remove_begin, | 79 base::Time remove_begin, |
| 81 base::Time remove_end) OVERRIDE; | 80 base::Time remove_end) OVERRIDE; |
| 81 virtual void ClearTransientState() OVERRIDE; |
| 82 virtual void GetSaveDir(content::WebContents* web_contents, | 82 virtual void GetSaveDir(content::WebContents* web_contents, |
| 83 FilePath* website_save_dir, | 83 FilePath* website_save_dir, |
| 84 FilePath* download_save_dir, | 84 FilePath* download_save_dir, |
| 85 bool* skip_dir_check) OVERRIDE; | 85 bool* skip_dir_check) OVERRIDE; |
| 86 virtual void ChooseSavePath( | 86 virtual void ChooseSavePath( |
| 87 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
| 88 const FilePath& suggested_path, | 88 const FilePath& suggested_path, |
| 89 const FilePath::StringType& default_extension, | 89 const FilePath::StringType& default_extension, |
| 90 bool can_save_as_complete, | 90 bool can_save_as_complete, |
| 91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; | 91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 111 bool visited_referrer_before); | 111 bool visited_referrer_before); |
| 112 | 112 |
| 113 // Obtains a path reservation by calling | 113 // Obtains a path reservation by calling |
| 114 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for | 114 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for |
| 115 // testing. | 115 // testing. |
| 116 virtual void GetReservedPath( | 116 virtual void GetReservedPath( |
| 117 content::DownloadItem& download, | 117 content::DownloadItem& download, |
| 118 const FilePath& target_path, | 118 const FilePath& target_path, |
| 119 const FilePath& default_download_path, | 119 const FilePath& default_download_path, |
| 120 bool should_uniquify_path, | 120 bool should_uniquify_path, |
| 121 const DownloadPathReservationTracker::ReservedPathCallback callback); | 121 const DownloadPathReservationTracker::ReservedPathCallback& callback); |
| 122 |
| 123 // Displays the file chooser dialog to prompt the user for the download |
| 124 // location for |item|. |suggested_path| will be used as the initial download |
| 125 // path. Once a location is available |file_selected_callback| will be invoked |
| 126 // with the selected full path. If the user cancels the dialog, then an empty |
| 127 // FilePath will be passed into |file_selected_callback|. Protected virtual |
| 128 // for testing. |
| 129 virtual void ChooseDownloadPath(content::DownloadItem* item, |
| 130 const FilePath& suggested_path, |
| 131 const base::Callback<void(const FilePath&)>& |
| 132 file_selected_callback); |
| 122 | 133 |
| 123 // So that test classes that inherit from this for override purposes | 134 // So that test classes that inherit from this for override purposes |
| 124 // can call back into the DownloadManager. | 135 // can call back into the DownloadManager. |
| 125 scoped_refptr<content::DownloadManager> download_manager_; | 136 scoped_refptr<content::DownloadManager> download_manager_; |
| 126 | 137 |
| 127 private: | 138 private: |
| 128 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; | 139 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; |
| 129 | 140 |
| 130 // content::NotificationObserver implementation. | 141 // content::NotificationObserver implementation. |
| 131 virtual void Observe(int type, | 142 virtual void Observe(int type, |
| 132 const content::NotificationSource& source, | 143 const content::NotificationSource& source, |
| 133 const content::NotificationDetails& details) OVERRIDE; | 144 const content::NotificationDetails& details) OVERRIDE; |
| 134 | 145 |
| 135 // Callback function after url is checked with safebrowsing service. | 146 // Callback function after url is checked with safebrowsing service. |
| 136 void CheckDownloadUrlDone( | 147 void CheckDownloadUrlDone( |
| 137 int32 download_id, | 148 int32 download_id, |
| 149 const content::DownloadTargetCallback& callback, |
| 138 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 150 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
| 139 | 151 |
| 140 // Callback function after the DownloadProtectionService completes. | 152 // Callback function after the DownloadProtectionService completes. |
| 141 void CheckClientDownloadDone( | 153 void CheckClientDownloadDone( |
| 142 int32 download_id, | 154 int32 download_id, |
| 143 safe_browsing::DownloadProtectionService::DownloadCheckResult result); | 155 safe_browsing::DownloadProtectionService::DownloadCheckResult result); |
| 144 | 156 |
| 145 // Callback function after we check whether the referrer URL has been visited | 157 // Callback function after we check whether the referrer URL has been visited |
| 146 // before today. Determines the danger state of the download based on the file | 158 // before today. Determines the danger state of the download based on the file |
| 147 // type and |visited_referrer_before|. Generates a target path for the | 159 // type and |visited_referrer_before|. Generates a target path for the |
| 148 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get | 160 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get |
| 149 // a reserved path for the download. The path is then passed into | 161 // a reserved path for the download. The path is then passed into |
| 150 // OnPathReservationAvailable(). | 162 // OnPathReservationAvailable(). |
| 151 void CheckVisitedReferrerBeforeDone(int32 download_id, | 163 void CheckVisitedReferrerBeforeDone( |
| 152 content::DownloadDangerType danger_type, | 164 int32 download_id, |
| 153 bool visited_referrer_before); | 165 const content::DownloadTargetCallback& callback, |
| 166 content::DownloadDangerType danger_type, |
| 167 bool visited_referrer_before); |
| 154 | 168 |
| 155 #if defined (OS_CHROMEOS) | 169 #if defined (OS_CHROMEOS) |
| 156 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls | 170 // GDataDownloadObserver::SubstituteGDataDownloadPath callback. Calls |
| 157 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path | 171 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path |
| 158 // for the download. The path is then passed into | 172 // for the download. The path is then passed into |
| 159 // OnPathReservationAvailable(). | 173 // OnPathReservationAvailable(). |
| 160 void SubstituteGDataDownloadPathCallback( | 174 void SubstituteGDataDownloadPathCallback( |
| 161 int32 download_id, | 175 int32 download_id, |
| 176 const content::DownloadTargetCallback& callback, |
| 162 bool should_prompt, | 177 bool should_prompt, |
| 163 bool is_forced_path, | 178 bool is_forced_path, |
| 164 content::DownloadDangerType danger_type, | 179 content::DownloadDangerType danger_type, |
| 165 const FilePath& unverified_path); | 180 const FilePath& unverified_path); |
| 166 #endif | 181 #endif |
| 167 | 182 |
| 183 // Determine the intermediate path to use for |target_path|. |danger_type| |
| 184 // specifies the danger level of the download. |
| 185 FilePath GetIntermediatePath(const FilePath& target_path, |
| 186 content::DownloadDangerType danger_type); |
| 187 |
| 168 // Called on the UI thread once a reserved path is available. Updates the | 188 // Called on the UI thread once a reserved path is available. Updates the |
| 169 // download identified by |download_id| with the |target_path|, target | 189 // download identified by |download_id| with the |target_path|, target |
| 170 // disposition and |danger_type|. | 190 // disposition and |danger_type|. |
| 171 void OnPathReservationAvailable( | 191 void OnPathReservationAvailable( |
| 172 int32 download_id, | 192 int32 download_id, |
| 193 const content::DownloadTargetCallback& callback, |
| 173 bool should_prompt, | 194 bool should_prompt, |
| 174 content::DownloadDangerType danger_type, | 195 content::DownloadDangerType danger_type, |
| 175 const FilePath& target_path, | 196 const FilePath& reserved_path, |
| 176 bool target_path_verified); | 197 bool reserved_path_verified); |
| 198 |
| 199 // Called on the UI thread once the final target path is available. |
| 200 void OnTargetPathDetermined( |
| 201 int32 download_id, |
| 202 const content::DownloadTargetCallback& callback, |
| 203 content::DownloadItem::TargetDisposition disposition, |
| 204 content::DownloadDangerType danger_type, |
| 205 const FilePath& target_path); |
| 177 | 206 |
| 178 // Callback from history system. | 207 // Callback from history system. |
| 179 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 208 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
| 180 | 209 |
| 181 // Check policy of whether we should open this download with a web intents | 210 // Check policy of whether we should open this download with a web intents |
| 182 // dispatch. | 211 // dispatch. |
| 183 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 212 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
| 184 | 213 |
| 185 // Open the given item with a web intent dispatch. | 214 // Open the given item with a web intent dispatch. |
| 186 void OpenWithWebIntent(const content::DownloadItem* item); | 215 void OpenWithWebIntent(const content::DownloadItem* item); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 205 content::NotificationRegistrar registrar_; | 234 content::NotificationRegistrar registrar_; |
| 206 | 235 |
| 207 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | 236 // The ExtensionDownloadsEventRouter dispatches download creation, change, and |
| 208 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | 237 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a |
| 209 // chrome-level concept and its lifetime should match DownloadManager. There | 238 // chrome-level concept and its lifetime should match DownloadManager. There |
| 210 // 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. |
| 211 // 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 |
| 212 // off-record profiles, so ExtensionSystem cannot own the EDER. | 241 // off-record profiles, so ExtensionSystem cannot own the EDER. |
| 213 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; | 242 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; |
| 214 | 243 |
| 244 // The directory most recently chosen by the user in response to a Save As |
| 245 // dialog for a regular download. |
| 246 FilePath last_download_path_; |
| 247 |
| 215 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 248 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
| 216 }; | 249 }; |
| 217 | 250 |
| 218 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 251 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
| OLD | NEW |