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 "base/memory/weak_ptr.h" |
| 13 #include "chrome/browser/download/download_history.h" |
| 14 #include "chrome/browser/download/download_path_reservation_tracker.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 DownloadHistory; |
22 class DownloadPrefs; | 23 class DownloadPrefs; |
23 class ExtensionDownloadsEventRouter; | 24 class ExtensionDownloadsEventRouter; |
24 class Profile; | 25 class Profile; |
(...skipping 25 matching lines...) Expand all Loading... |
50 public: | 51 public: |
51 // Callback type used with ChooseDownloadPath(). The callback should be | 52 // Callback type used with ChooseDownloadPath(). The callback should be |
52 // invoked with the user-selected path as the argument. If the file selection | 53 // invoked with the user-selected path as the argument. If the file selection |
53 // was canceled, the argument should be the empty path. | 54 // was canceled, the argument should be the empty path. |
54 typedef base::Callback<void(const FilePath&)> FileSelectedCallback; | 55 typedef base::Callback<void(const FilePath&)> FileSelectedCallback; |
55 | 56 |
56 explicit ChromeDownloadManagerDelegate(Profile* profile); | 57 explicit ChromeDownloadManagerDelegate(Profile* profile); |
57 | 58 |
58 void SetDownloadManager(content::DownloadManager* dm); | 59 void SetDownloadManager(content::DownloadManager* dm); |
59 | 60 |
| 61 void AddHistoryObserver(DownloadHistory::Observer* observer); |
| 62 void RemoveHistoryObserver(DownloadHistory::Observer* observer); |
| 63 |
60 // Should be called before the first call to ShouldCompleteDownload() to | 64 // Should be called before the first call to ShouldCompleteDownload() to |
61 // disable SafeBrowsing checks for |item|. | 65 // disable SafeBrowsing checks for |item|. |
62 static void DisableSafeBrowsing(content::DownloadItem* item); | 66 static void DisableSafeBrowsing(content::DownloadItem* item); |
63 | 67 |
64 // content::DownloadManagerDelegate | 68 // content::DownloadManagerDelegate |
65 virtual void Shutdown() OVERRIDE; | 69 virtual void Shutdown() OVERRIDE; |
66 virtual content::DownloadId GetNextId() OVERRIDE; | 70 virtual content::DownloadId GetNextId() OVERRIDE; |
67 virtual bool DetermineDownloadTarget( | 71 virtual bool DetermineDownloadTarget( |
68 content::DownloadItem* item, | 72 content::DownloadItem* item, |
69 const content::DownloadTargetCallback& callback) OVERRIDE; | 73 const content::DownloadTargetCallback& callback) OVERRIDE; |
70 virtual content::WebContents* | 74 virtual content::WebContents* |
71 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; | 75 GetAlternativeWebContentsToNotifyForDownload() OVERRIDE; |
72 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; | 76 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; |
73 virtual bool ShouldCompleteDownload( | 77 virtual bool ShouldCompleteDownload( |
74 content::DownloadItem* item, | 78 content::DownloadItem* item, |
75 const base::Closure& complete_callback) OVERRIDE; | 79 const base::Closure& complete_callback) OVERRIDE; |
76 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; | 80 virtual bool ShouldOpenDownload(content::DownloadItem* item) OVERRIDE; |
77 virtual bool GenerateFileHash() OVERRIDE; | 81 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, | 82 virtual void GetSaveDir(content::BrowserContext* browser_context, |
90 FilePath* website_save_dir, | 83 FilePath* website_save_dir, |
91 FilePath* download_save_dir, | 84 FilePath* download_save_dir, |
92 bool* skip_dir_check) OVERRIDE; | 85 bool* skip_dir_check) OVERRIDE; |
93 virtual void ChooseSavePath( | 86 virtual void ChooseSavePath( |
94 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
95 const FilePath& suggested_path, | 88 const FilePath& suggested_path, |
96 const FilePath::StringType& default_extension, | 89 const FilePath::StringType& default_extension, |
97 bool can_save_as_complete, | 90 bool can_save_as_complete, |
98 const content::SavePackagePathPickedCallback& callback) OVERRIDE; | 91 const content::SavePackagePathPickedCallback& callback) OVERRIDE; |
99 | 92 |
100 // Clears the last directory chosen by the user in response to a file chooser | 93 // Clears the last directory chosen by the user in response to a file chooser |
101 // prompt. Called when clearing recent history. | 94 // prompt. Called when clearing recent history. |
102 void ClearLastDownloadPath(); | 95 void ClearLastDownloadPath(); |
103 | 96 |
104 DownloadPrefs* download_prefs() { return download_prefs_.get(); } | 97 DownloadPrefs* download_prefs() { return download_prefs_.get(); } |
105 DownloadHistory* download_history() { return download_history_.get(); } | |
106 | 98 |
107 protected: | 99 protected: |
108 // So that test classes can inherit from this for override purposes. | 100 // So that test classes can inherit from this for override purposes. |
109 virtual ~ChromeDownloadManagerDelegate(); | 101 virtual ~ChromeDownloadManagerDelegate(); |
110 | 102 |
111 // Returns the SafeBrowsing download protection service if it's | 103 // Returns the SafeBrowsing download protection service if it's |
112 // enabled. Returns NULL otherwise. Protected virtual for testing. | 104 // enabled. Returns NULL otherwise. Protected virtual for testing. |
113 virtual safe_browsing::DownloadProtectionService* | 105 virtual safe_browsing::DownloadProtectionService* |
114 GetDownloadProtectionService(); | 106 GetDownloadProtectionService(); |
115 | 107 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 bool reserved_path_verified); | 198 bool reserved_path_verified); |
207 | 199 |
208 // Called on the UI thread once the final target path is available. | 200 // Called on the UI thread once the final target path is available. |
209 void OnTargetPathDetermined( | 201 void OnTargetPathDetermined( |
210 int32 download_id, | 202 int32 download_id, |
211 const content::DownloadTargetCallback& callback, | 203 const content::DownloadTargetCallback& callback, |
212 content::DownloadItem::TargetDisposition disposition, | 204 content::DownloadItem::TargetDisposition disposition, |
213 content::DownloadDangerType danger_type, | 205 content::DownloadDangerType danger_type, |
214 const FilePath& target_path); | 206 const FilePath& target_path); |
215 | 207 |
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 | 208 // Check policy of whether we should open this download with a web intents |
220 // dispatch. | 209 // dispatch. |
221 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); | 210 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); |
222 | 211 |
223 // Open the given item with a web intent dispatch. | 212 // Open the given item with a web intent dispatch. |
224 void OpenWithWebIntent(const content::DownloadItem* item); | 213 void OpenWithWebIntent(const content::DownloadItem* item); |
225 | 214 |
226 // Internal gateways for ShouldCompleteDownload(). | 215 // Internal gateways for ShouldCompleteDownload(). |
227 bool IsDownloadReadyForCompletion( | 216 bool IsDownloadReadyForCompletion( |
228 content::DownloadItem* item, | 217 content::DownloadItem* item, |
(...skipping 28 matching lines...) Expand all Loading... |
257 #endif | 246 #endif |
258 | 247 |
259 // The directory most recently chosen by the user in response to a Save As | 248 // The directory most recently chosen by the user in response to a Save As |
260 // dialog for a regular download. | 249 // dialog for a regular download. |
261 FilePath last_download_path_; | 250 FilePath last_download_path_; |
262 | 251 |
263 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); | 252 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); |
264 }; | 253 }; |
265 | 254 |
266 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ | 255 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ |
OLD | NEW |