Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.h

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

Powered by Google App Engine
This is Rietveld 408576698