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

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: @r167394 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"
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
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( 76 virtual bool ShouldOpenDownload(
77 content::DownloadItem* item, 77 content::DownloadItem* item,
78 const content::DownloadOpenDelayedCallback& callback) OVERRIDE; 78 const content::DownloadOpenDelayedCallback& callback) OVERRIDE;
79 virtual bool GenerateFileHash() OVERRIDE; 79 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, 80 virtual void GetSaveDir(content::BrowserContext* browser_context,
92 FilePath* website_save_dir, 81 FilePath* website_save_dir,
93 FilePath* download_save_dir, 82 FilePath* download_save_dir,
94 bool* skip_dir_check) OVERRIDE; 83 bool* skip_dir_check) OVERRIDE;
95 virtual void ChooseSavePath( 84 virtual void ChooseSavePath(
96 content::WebContents* web_contents, 85 content::WebContents* web_contents,
97 const FilePath& suggested_path, 86 const FilePath& suggested_path,
98 const FilePath::StringType& default_extension, 87 const FilePath::StringType& default_extension,
99 bool can_save_as_complete, 88 bool can_save_as_complete,
100 const content::SavePackagePathPickedCallback& callback) OVERRIDE; 89 const content::SavePackagePathPickedCallback& callback) OVERRIDE;
101 90
102 // Clears the last directory chosen by the user in response to a file chooser 91 // Clears the last directory chosen by the user in response to a file chooser
103 // prompt. Called when clearing recent history. 92 // prompt. Called when clearing recent history.
104 void ClearLastDownloadPath(); 93 void ClearLastDownloadPath();
105 94
106 DownloadPrefs* download_prefs() { return download_prefs_.get(); } 95 DownloadPrefs* download_prefs() { return download_prefs_.get(); }
107 DownloadHistory* download_history() { return download_history_.get(); }
108 96
109 protected: 97 protected:
110 // So that test classes can inherit from this for override purposes. 98 // So that test classes can inherit from this for override purposes.
111 virtual ~ChromeDownloadManagerDelegate(); 99 virtual ~ChromeDownloadManagerDelegate();
112 100
113 // Returns the SafeBrowsing download protection service if it's 101 // Returns the SafeBrowsing download protection service if it's
114 // enabled. Returns NULL otherwise. Protected virtual for testing. 102 // enabled. Returns NULL otherwise. Protected virtual for testing.
115 virtual safe_browsing::DownloadProtectionService* 103 virtual safe_browsing::DownloadProtectionService*
116 GetDownloadProtectionService(); 104 GetDownloadProtectionService();
117 105
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const content::DownloadTargetCallback& callback, 148 const content::DownloadTargetCallback& callback,
161 safe_browsing::DownloadProtectionService::DownloadCheckResult result); 149 safe_browsing::DownloadProtectionService::DownloadCheckResult result);
162 150
163 // Callback function after the DownloadProtectionService completes. 151 // Callback function after the DownloadProtectionService completes.
164 void CheckClientDownloadDone( 152 void CheckClientDownloadDone(
165 int32 download_id, 153 int32 download_id,
166 safe_browsing::DownloadProtectionService::DownloadCheckResult result); 154 safe_browsing::DownloadProtectionService::DownloadCheckResult result);
167 155
168 // Callback function after we check whether the referrer URL has been visited 156 // 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 157 // 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 158 // type, |found_visits|, |count|, |first_visit|. Generates a target path for
171 // download. Invokes |DownloadPathReservationTracker::GetReservedPath| to get 159 // the download. Invokes |DownloadPathReservationTracker::GetReservedPath| to
172 // a reserved path for the download. The path is then passed into 160 // get a reserved path for the download. The path is then passed into
173 // OnPathReservationAvailable(). 161 // OnPathReservationAvailable().
174 void CheckVisitedReferrerBeforeDone( 162 void CheckVisitedReferrerBeforeDone(
175 int32 download_id, 163 int32 download_id,
176 const content::DownloadTargetCallback& callback, 164 const content::DownloadTargetCallback& callback,
177 content::DownloadDangerType danger_type, 165 content::DownloadDangerType danger_type,
178 bool visited_referrer_before); 166 bool visited_referrer_before);
179 167
180 #if defined (OS_CHROMEOS) 168 #if defined (OS_CHROMEOS)
181 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls 169 // DriveDownloadObserver::SubstituteDriveDownloadPath callback. Calls
182 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path 170 // |DownloadPathReservationTracker::GetReservedPath| to get a reserved path
183 // for the download. The path is then passed into 171 // for the download. The path is then passed into
184 // OnPathReservationAvailable(). 172 // OnPathReservationAvailable().
185 void SubstituteDriveDownloadPathCallback( 173 void SubstituteDriveDownloadPathCallback(
186 int32 download_id, 174 int32 download_id,
187 const content::DownloadTargetCallback& callback, 175 const content::DownloadTargetCallback& callback,
188 bool should_prompt, 176 bool should_prompt,
(...skipping 19 matching lines...) Expand all
208 bool reserved_path_verified); 196 bool reserved_path_verified);
209 197
210 // Called on the UI thread once the final target path is available. 198 // Called on the UI thread once the final target path is available.
211 void OnTargetPathDetermined( 199 void OnTargetPathDetermined(
212 int32 download_id, 200 int32 download_id,
213 const content::DownloadTargetCallback& callback, 201 const content::DownloadTargetCallback& callback,
214 content::DownloadItem::TargetDisposition disposition, 202 content::DownloadItem::TargetDisposition disposition,
215 content::DownloadDangerType danger_type, 203 content::DownloadDangerType danger_type,
216 const FilePath& target_path); 204 const FilePath& target_path);
217 205
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 206 // Check policy of whether we should open this download with a web intents
222 // dispatch. 207 // dispatch.
223 bool ShouldOpenWithWebIntents(const content::DownloadItem* item); 208 bool ShouldOpenWithWebIntents(const content::DownloadItem* item);
224 209
225 // Open the given item with a web intent dispatch. 210 // Open the given item with a web intent dispatch.
226 void OpenWithWebIntent(const content::DownloadItem* item); 211 void OpenWithWebIntent(const content::DownloadItem* item);
227 212
228 // Internal gateways for ShouldCompleteDownload(). 213 // Internal gateways for ShouldCompleteDownload().
229 bool IsDownloadReadyForCompletion( 214 bool IsDownloadReadyForCompletion(
230 content::DownloadItem* item, 215 content::DownloadItem* item,
231 const base::Closure& internal_complete_callback); 216 const base::Closure& internal_complete_callback);
232 void ShouldCompleteDownloadInternal( 217 void ShouldCompleteDownloadInternal(
233 int download_id, 218 int download_id,
234 const base::Closure& user_complete_callback); 219 const base::Closure& user_complete_callback);
235 220
236 Profile* profile_; 221 Profile* profile_;
237 int next_download_id_; 222 int next_download_id_;
238 scoped_ptr<DownloadPrefs> download_prefs_; 223 scoped_ptr<DownloadPrefs> download_prefs_;
239 scoped_ptr<DownloadHistory> download_history_;
240 224
241 // Maps from pending extension installations to DownloadItem IDs. 225 // Maps from pending extension installations to DownloadItem IDs.
242 typedef base::hash_map<extensions::CrxInstaller*, 226 typedef base::hash_map<extensions::CrxInstaller*,
243 content::DownloadOpenDelayedCallback> CrxInstallerMap; 227 content::DownloadOpenDelayedCallback> CrxInstallerMap;
244 CrxInstallerMap crx_installers_; 228 CrxInstallerMap crx_installers_;
245 229
230 CancelableRequestConsumer history_consumer_;
231
246 content::NotificationRegistrar registrar_; 232 content::NotificationRegistrar registrar_;
247 233
248 // On Android, GET downloads are not handled by the DownloadManager. 234 // On Android, GET downloads are not handled by the DownloadManager.
249 // Once we have extensions on android, we probably need the EventRouter 235 // Once we have extensions on android, we probably need the EventRouter
250 // in ContentViewDownloadDelegate which knows about both GET and POST 236 // in ContentViewDownloadDelegate which knows about both GET and POST
251 // downloads. 237 // downloads.
252 #if !defined(OS_ANDROID) 238 #if !defined(OS_ANDROID)
253 // The ExtensionDownloadsEventRouter dispatches download creation, change, and 239 // The ExtensionDownloadsEventRouter dispatches download creation, change, and
254 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a 240 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
255 // chrome-level concept and its lifetime should match DownloadManager. There 241 // chrome-level concept and its lifetime should match DownloadManager. There
256 // should be a separate EDER for on-record and off-record managers. 242 // 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 243 // There does not appear to be a separate ExtensionSystem for on-record and
258 // off-record profiles, so ExtensionSystem cannot own the EDER. 244 // off-record profiles, so ExtensionSystem cannot own the EDER.
259 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_; 245 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_;
260 #endif 246 #endif
261 247
262 // 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
263 // dialog for a regular download. 249 // dialog for a regular download.
264 FilePath last_download_path_; 250 FilePath last_download_path_;
265 251
266 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate); 252 DISALLOW_COPY_AND_ASSIGN(ChromeDownloadManagerDelegate);
267 }; 253 };
268 254
269 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_ 255 #endif // CHROME_BROWSER_DOWNLOAD_CHROME_DOWNLOAD_MANAGER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698