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(content::DownloadItem* item) OVERRIDE; |
60 virtual void ChooseDownloadPath(content::DownloadItem* item) OVERRIDE; | |
61 virtual FilePath GetIntermediatePath( | |
62 const content::DownloadItem& item) OVERRIDE; | |
63 virtual content::WebContents* | 60 virtual content::WebContents* |
64 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; | 61 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; |
65 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 62 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
66 virtual bool ShouldCompleteDownload( | 63 virtual bool ShouldCompleteDownload( |
67 content::DownloadItem* item, | 64 content::DownloadItem* item, |
68 const base::Closure& complete_callback) OVERRIDE; | 65 const base::Closure& complete_callback) OVERRIDE; |
69 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; | 66 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; |
70 virtual bool GenerateFileHash() OVERRIDE; | 67 virtual bool GenerateFileHash() OVERRIDE; |
71 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; | 68 virtual void AddItemToPersistentStore(content::DownloadItem* item) OVERRIDE; |
72 virtual void UpdateItemInPersistentStore( | 69 virtual void UpdateItemInPersistentStore( |
73 content::DownloadItem* item) OVERRIDE; | 70 content::DownloadItem* item) OVERRIDE; |
74 virtual void UpdatePathForItemInPersistentStore( | 71 virtual void UpdatePathForItemInPersistentStore( |
75 content::DownloadItem* item, | 72 content::DownloadItem* item, |
76 const FilePath& new_path) OVERRIDE; | 73 const FilePath& new_path) OVERRIDE; |
77 virtual void RemoveItemFromPersistentStore( | 74 virtual void RemoveItemFromPersistentStore( |
78 content::DownloadItem* item) OVERRIDE; | 75 content::DownloadItem* item) OVERRIDE; |
79 virtual void RemoveItemsFromPersistentStoreBetween( | 76 virtual void RemoveItemsFromPersistentStoreBetween( |
80 base::Time remove_begin, | 77 base::Time remove_begin, |
81 base::Time remove_end) OVERRIDE; | 78 base::Time remove_end) OVERRIDE; |
| 79 virtual void ClearTransientState() OVERRIDE; |
82 virtual void GetSaveDir(content::WebContents* web_contents, | 80 virtual void GetSaveDir(content::WebContents* web_contents, |
83 FilePath* website_save_dir, | 81 FilePath* website_save_dir, |
84 FilePath* download_save_dir, | 82 FilePath* download_save_dir, |
85 bool* skip_dir_check) OVERRIDE; | 83 bool* skip_dir_check) OVERRIDE; |
86 virtual void ChooseSavePath( | 84 virtual void ChooseSavePath( |
87 content::WebContents* web_contents, | 85 content::WebContents* web_contents, |
88 const FilePath& suggested_path, | 86 const FilePath& suggested_path, |
89 const FilePath::StringType& default_extension, | 87 const FilePath::StringType& default_extension, |
90 bool can_save_as_complete, | 88 bool can_save_as_complete, |
91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; | 89 const content::SavePackagePathPickedCallback& callback) OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
113 // Obtains a path reservation by calling | 111 // Obtains a path reservation by calling |
114 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for | 112 // DownloadPathReservationTracker::GetReservedPath(). Protected virtual for |
115 // testing. | 113 // testing. |
116 virtual void GetReservedPath( | 114 virtual void GetReservedPath( |
117 content::DownloadItem& download, | 115 content::DownloadItem& download, |
118 const FilePath& target_path, | 116 const FilePath& target_path, |
119 const FilePath& default_download_path, | 117 const FilePath& default_download_path, |
120 bool should_uniquify_path, | 118 bool should_uniquify_path, |
121 const DownloadPathReservationTracker::ReservedPathCallback callback); | 119 const DownloadPathReservationTracker::ReservedPathCallback callback); |
122 | 120 |
| 121 // Displays the file chooser dialog to prompt the user for the download |
| 122 // location for |item|. |suggested_path| will be used as the initial download |
| 123 // path. Once a location is available |file_selected_callback| will be invoked |
| 124 // with the selected full path. If the user cancels the dialog, then an empty |
| 125 // FilePath will be passed into |file_selected_callback|. Protected virtual |
| 126 // for testing. |
| 127 virtual void ChooseDownloadPath(content::DownloadItem* item, |
| 128 const FilePath& suggested_path, |
| 129 const base::Callback<void(const FilePath&)>& |
| 130 file_selected_callback); |
| 131 |
123 // So that test classes that inherit from this for override purposes | 132 // So that test classes that inherit from this for override purposes |
124 // can call back into the DownloadManager. | 133 // can call back into the DownloadManager. |
125 scoped_refptr<content::DownloadManager> download_manager_; | 134 scoped_refptr<content::DownloadManager> download_manager_; |
126 | 135 |
127 private: | 136 private: |
128 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; | 137 friend class base::RefCountedThreadSafe<ChromeDownloadManagerDelegate>; |
129 | 138 |
130 // content::NotificationObserver implementation. | 139 // content::NotificationObserver implementation. |
131 virtual void Observe(int type, | 140 virtual void Observe(int type, |
132 const content::NotificationSource& source, | 141 const content::NotificationSource& source, |
(...skipping 25 matching lines...) Expand all Loading... |
158 // for the download. The path is then passed into | 167 // for the download. The path is then passed into |
159 // OnPathReservationAvailable(). | 168 // OnPathReservationAvailable(). |
160 void SubstituteGDataDownloadPathCallback( | 169 void SubstituteGDataDownloadPathCallback( |
161 int32 download_id, | 170 int32 download_id, |
162 bool should_prompt, | 171 bool should_prompt, |
163 bool is_forced_path, | 172 bool is_forced_path, |
164 content::DownloadDangerType danger_type, | 173 content::DownloadDangerType danger_type, |
165 const FilePath& unverified_path); | 174 const FilePath& unverified_path); |
166 #endif | 175 #endif |
167 | 176 |
| 177 // Determine the intermediate path to use for |target_path|. |danger_type| |
| 178 // specifies the danger level of the download. |
| 179 FilePath GetIntermediatePath(const FilePath& target_path, |
| 180 content::DownloadDangerType danger_type); |
| 181 |
168 // Called on the UI thread once a reserved path is available. Updates the | 182 // Called on the UI thread once a reserved path is available. Updates the |
169 // download identified by |download_id| with the |target_path|, target | 183 // download identified by |download_id| with the |target_path|, target |
170 // disposition and |danger_type|. | 184 // disposition and |danger_type|. |
171 void OnPathReservationAvailable( | 185 void OnPathReservationAvailable( |
172 int32 download_id, | 186 int32 download_id, |
173 bool should_prompt, | 187 bool should_prompt, |
174 content::DownloadDangerType danger_type, | 188 content::DownloadDangerType danger_type, |
175 const FilePath& target_path, | 189 const FilePath& reserved_path, |
176 bool target_path_verified); | 190 bool reserved_path_verified); |
| 191 |
| 192 // Called on the UI thread once the final target path is available. |
| 193 void OnTargetPathAvailable( |
| 194 int32 download_id, |
| 195 content::DownloadItem::TargetDisposition disposition, |
| 196 content::DownloadDangerType danger_type, |
| 197 const FilePath& target_path); |
177 | 198 |
178 // Callback from history system. | 199 // Callback from history system. |
179 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 200 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
180 | 201 |
181 // Check policy of whether we should open this download with a web intents | 202 // Check policy of whether we should open this download with a web intents |
182 // dispatch. | 203 // dispatch. |
183 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 204 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
184 | 205 |
185 // Open the given item with a web intent dispatch. | 206 // Open the given item with a web intent dispatch. |
186 void OpenWithWebIntent(const content::DownloadItem* item); | 207 void OpenWithWebIntent(const content::DownloadItem* item); |
(...skipping 18 matching lines...) Expand all Loading... |
205 content::NotificationRegistrar registrar_; | 226 content::NotificationRegistrar registrar_; |
206 | 227 |
207 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | 228 // The ExtensionDownloadsEventRouter dispatches download creation, change, and |
208 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | 229 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a |
209 // chrome-level concept and its lifetime should match DownloadManager. There | 230 // chrome-level concept and its lifetime should match DownloadManager. There |
210 // should be a separate EDER for on-record and off-record managers. | 231 // 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 | 232 // There does not appear to be a separate ExtensionSystem for on-record and |
212 // off-record profiles, so ExtensionSystem cannot own the EDER. | 233 // off-record profiles, so ExtensionSystem cannot own the EDER. |
213 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; | 234 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; |
214 | 235 |
| 236 // The directory most recently chosen by the user in response to a Save As |
| 237 // dialog for a regular download. |
| 238 FilePath last_download_path_; |
| 239 |
215 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 240 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
216 }; | 241 }; |
217 | 242 |
218 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 243 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |