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

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

Issue 7277073: Support for adding save page download items into downloads history. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months 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
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // The DownloadManager object manages the process of downloading, including 5 // The DownloadManager object manages the process of downloading, including
6 // updates to the history system and providing the information for displaying 6 // updates to the history system and providing the information for displaying
7 // the downloads view in the Destinations tab. There is one DownloadManager per 7 // the downloads view in the Destinations tab. There is one DownloadManager per
8 // active profile in Chrome. 8 // active profile in Chrome.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 // Called immediately after the DownloadManager puts up a select file 85 // Called immediately after the DownloadManager puts up a select file
86 // dialog. 86 // dialog.
87 // |id| indicates which download opened the dialog. 87 // |id| indicates which download opened the dialog.
88 virtual void SelectFileDialogDisplayed(int32 id) {} 88 virtual void SelectFileDialogDisplayed(int32 id) {}
89 89
90 protected: 90 protected:
91 virtual ~Observer() {} 91 virtual ~Observer() {}
92 }; 92 };
93 93
94 typedef std::vector<DownloadItem*> DownloadVector;
95
94 // Return all temporary downloads that reside in the specified directory. 96 // Return all temporary downloads that reside in the specified directory.
95 void GetTemporaryDownloads(const FilePath& dir_path, 97 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result);
96 std::vector<DownloadItem*>* result);
97 98
98 // Return all non-temporary downloads in the specified directory that are 99 // Return all non-temporary downloads in the specified directory that are
99 // are in progress or have completed. 100 // are in progress or have completed.
100 void GetAllDownloads(const FilePath& dir_path, 101 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result);
101 std::vector<DownloadItem*>* result);
102 102
103 // Return all non-temporary downloads in the specified directory that are 103 // Return all non-temporary downloads in the specified directory that are
104 // in-progress (including dangerous downloads waiting for user confirmation). 104 // in-progress (including dangerous downloads waiting for user confirmation).
105 void GetCurrentDownloads(const FilePath& dir_path, 105 void GetCurrentDownloads(const FilePath& dir_path, DownloadVector* result);
106 std::vector<DownloadItem*>* result);
107 106
108 // Returns all non-temporary downloads matching |query|. Empty query matches 107 // Returns all non-temporary downloads matching |query|. Empty query matches
109 // everything. 108 // everything.
110 void SearchDownloads(const string16& query, 109 void SearchDownloads(const string16& query, DownloadVector* result);
111 std::vector<DownloadItem*>* result);
112 110
113 // Returns true if initialized properly. 111 // Returns true if initialized properly.
114 bool Init(Profile* profile); 112 bool Init(Profile* profile);
115 113
116 // Notifications sent from the download thread to the UI thread 114 // Notifications sent from the download thread to the UI thread
117 void StartDownload(int32 id); 115 void StartDownload(int32 id);
118 void UpdateDownload(int32 download_id, int64 size); 116 void UpdateDownload(int32 download_id, int64 size);
119 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 117 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
120 // is not available. 118 // is not available.
121 void OnResponseCompleted(int32 download_id, int64 size, int os_error, 119 void OnResponseCompleted(int32 download_id, int64 size, int os_error,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 int RemoveDownloads(const base::Time remove_begin); 153 int RemoveDownloads(const base::Time remove_begin);
156 154
157 // Remove all downloads will delete all downloads. The number of downloads 155 // Remove all downloads will delete all downloads. The number of downloads
158 // deleted is returned back to the caller. 156 // deleted is returned back to the caller.
159 int RemoveAllDownloads(); 157 int RemoveAllDownloads();
160 158
161 // Final download manager transition for download: Update the download 159 // Final download manager transition for download: Update the download
162 // history and remove the download from |active_downloads_|. 160 // history and remove the download from |active_downloads_|.
163 void DownloadCompleted(int32 download_id); 161 void DownloadCompleted(int32 download_id);
164 162
165 // Called when a Save Page As download is started. Transfers ownership
166 // of |download_item| to the DownloadManager.
167 void SavePageAsDownloadStarted(DownloadItem* download_item);
168
169 // Download the object at the URL. Used in cases such as "Save Link As..." 163 // Download the object at the URL. Used in cases such as "Save Link As..."
170 void DownloadUrl(const GURL& url, 164 void DownloadUrl(const GURL& url,
171 const GURL& referrer, 165 const GURL& referrer,
172 const std::string& referrer_encoding, 166 const std::string& referrer_encoding,
173 TabContents* tab_contents); 167 TabContents* tab_contents);
174 168
175 // Download the object at the URL and save it to the specified path. The 169 // Download the object at the URL and save it to the specified path. The
176 // download is treated as the temporary download and thus will not appear 170 // download is treated as the temporary download and thus will not appear
177 // in the download history. Used in cases such as drag and drop. 171 // in the download history. Used in cases such as drag and drop.
178 void DownloadUrlToFile(const GURL& url, 172 void DownloadUrlToFile(const GURL& url,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); 248 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
255 249
256 // Assert the named download item is on the correct queues 250 // Assert the named download item is on the correct queues
257 // in the DownloadManager. For debugging. 251 // in the DownloadManager. For debugging.
258 void AssertQueueStateConsistent(DownloadItem* download); 252 void AssertQueueStateConsistent(DownloadItem* download);
259 253
260 // Get the download item from the history map. Useful after the item has 254 // Get the download item from the history map. Useful after the item has
261 // been removed from the active map, or was retrieved from the history DB. 255 // been removed from the active map, or was retrieved from the history DB.
262 DownloadItem* GetDownloadItem(int id); 256 DownloadItem* GetDownloadItem(int id);
263 257
258 // Called when Save Page download starts. Transfers ownership of |download|
259 // to the DownloadManager.
260 void SavePageDownloadStarted(DownloadItem* download);
261
262 // Callback when Save Page As entry is commited to the history system.
263 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle);
264
265 // Called when Save Page download is done.
266 void SavePageDownloadFinished(DownloadItem* download);
267
268 // Id for next Save Page.
269 int32 GetNextSavePageId();
270
264 private: 271 private:
272 typedef std::set<DownloadItem*> DownloadSet;
273 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
274
265 // For testing. 275 // For testing.
266 friend class DownloadManagerTest; 276 friend class DownloadManagerTest;
267 friend class MockDownloadManager; 277 friend class MockDownloadManager;
278 friend class SavePageBrowserTest;
268 279
269 // This class is used to let an incognito DownloadManager observe changes to 280 // This class is used to let an incognito DownloadManager observe changes to
270 // a normal DownloadManager, to propagate ModelChanged() calls from the parent 281 // a normal DownloadManager, to propagate ModelChanged() calls from the parent
271 // DownloadManager to the observers of the incognito DownloadManager. 282 // DownloadManager to the observers of the incognito DownloadManager.
272 class OtherDownloadManagerObserver : public Observer { 283 class OtherDownloadManagerObserver : public Observer {
273 public: 284 public:
274 explicit OtherDownloadManagerObserver( 285 explicit OtherDownloadManagerObserver(
275 DownloadManager* observing_download_manager); 286 DownloadManager* observing_download_manager);
276 virtual ~OtherDownloadManagerObserver(); 287 virtual ~OtherDownloadManagerObserver();
277 288
278 // Observer interface. 289 // Observer interface.
279 virtual void ModelChanged(); 290 virtual void ModelChanged();
280 virtual void ManagerGoingDown(); 291 virtual void ManagerGoingDown();
281 292
282 private: 293 private:
283 // The incognito download manager. 294 // The incognito download manager.
284 DownloadManager* observing_download_manager_; 295 DownloadManager* observing_download_manager_;
285 296
286 // The original profile's download manager. 297 // The original profile's download manager.
287 DownloadManager* observed_download_manager_; 298 DownloadManager* observed_download_manager_;
288 }; 299 };
289 300
290 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 301 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
291 friend class DeleteTask<DownloadManager>; 302 friend class DeleteTask<DownloadManager>;
292 friend class OtherDownloadManagerObserver; 303 friend class OtherDownloadManagerObserver;
293 304
294 virtual ~DownloadManager(); 305 virtual ~DownloadManager();
295 306
307 DownloadHistory* download_history() { return download_history_.get(); }
Paweł Hajdan Jr. 2011/08/01 18:22:59 nit: Why private? If it's needed just go ahead and
achuithb 2011/08/01 21:19:54 I had it as public but Randy preferred to have thi
achuithb 2011/08/02 19:00:41 I forgot Randy is on vacation. I'm going to make t
Randy Smith (Not in Mondays) 2011/08/03 16:03:09 My memory is that it was only needed by tests. I
Paweł Hajdan Jr. 2011/08/03 19:07:46 I think it's better to use #ifdef UNIT_TEST then r
achuithb 2011/08/03 19:52:43 Pawel: It's not a unit test. Is UNIT_TEST also app
Paweł Hajdan Jr. 2011/08/03 20:49:40 If it isn't it's a bug.
achuithb 2011/08/03 21:05:28 Done.
308
296 // Called on the FILE thread to check the existence of a downloaded file. 309 // Called on the FILE thread to check the existence of a downloaded file.
297 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); 310 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path);
298 311
299 // Called on the UI thread if the FILE thread detects the removal of 312 // Called on the UI thread if the FILE thread detects the removal of
300 // the downloaded file. The UI thread updates the state of the file 313 // the downloaded file. The UI thread updates the state of the file
301 // and then notifies this update to the file's observer. 314 // and then notifies this update to the file's observer.
302 void OnFileRemovalDetected(int64 db_handle); 315 void OnFileRemovalDetected(int64 db_handle);
303 316
304 // Called on the download thread to check whether the suggested file path 317 // Called on the download thread to check whether the suggested file path
305 // exists. We don't check if the file exists on the UI thread to avoid UI 318 // exists. We don't check if the file exists on the UI thread to avoid UI
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // yet in the history map. 354 // yet in the history map.
342 DownloadItem* GetActiveDownloadItem(int id); 355 DownloadItem* GetActiveDownloadItem(int id);
343 356
344 // Debugging routine to confirm relationship between below 357 // Debugging routine to confirm relationship between below
345 // containers; no-op if NDEBUG. 358 // containers; no-op if NDEBUG.
346 void AssertContainersConsistent() const; 359 void AssertContainersConsistent() const;
347 360
348 // Add a DownloadItem to history_downloads_. 361 // Add a DownloadItem to history_downloads_.
349 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 362 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
350 363
364 // Remove from internal maps.
365 int RemoveDownloadItems(const DownloadVector& pending_deletes);
366
351 // |downloads_| is the owning set for all downloads known to the 367 // |downloads_| is the owning set for all downloads known to the
352 // DownloadManager. This includes downloads started by the user in 368 // DownloadManager. This includes downloads started by the user in
353 // this session, downloads initialized from the history system, and 369 // this session, downloads initialized from the history system, and
354 // "save page as" downloads. All other DownloadItem containers in 370 // "save page as" downloads. All other DownloadItem containers in
355 // the DownloadManager are maps; they do not own the DownloadItems. 371 // the DownloadManager are maps; they do not own the DownloadItems.
356 // Note that this is the only place (with any functional implications; 372 // Note that this is the only place (with any functional implications;
357 // see save_page_as_downloads_ below) that "save page as" downloads are 373 // see save_page_as_downloads_ below) that "save page as" downloads are
358 // kept, as the DownloadManager's only job is to hold onto those 374 // kept, as the DownloadManager's only job is to hold onto those
359 // until destruction. 375 // until destruction.
360 // 376 //
(...skipping 16 matching lines...) Expand all
377 // When a download is created through a user action, the corresponding 393 // When a download is created through a user action, the corresponding
378 // DownloadItem* is placed in |active_downloads_| and remains there until the 394 // DownloadItem* is placed in |active_downloads_| and remains there until the
379 // download is in a terminal state (COMPLETE or CANCELLED). It is also 395 // download is in a terminal state (COMPLETE or CANCELLED). It is also
380 // placed in |in_progress_| and remains there until it has received a 396 // placed in |in_progress_| and remains there until it has received a
381 // valid handle from the history system. Once it has a valid handle, the 397 // valid handle from the history system. Once it has a valid handle, the
382 // DownloadItem* is placed in the |history_downloads_| map. When the 398 // DownloadItem* is placed in the |history_downloads_| map. When the
383 // download reaches a terminal state, it is removed from |in_progress_|. 399 // download reaches a terminal state, it is removed from |in_progress_|.
384 // Downloads from past sessions read from a persisted state from the 400 // Downloads from past sessions read from a persisted state from the
385 // history system are placed directly into |history_downloads_| since 401 // history system are placed directly into |history_downloads_| since
386 // they have valid handles in the history system. 402 // they have valid handles in the history system.
387 typedef std::set<DownloadItem*> DownloadSet;
388 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
389 403
390 DownloadSet downloads_; 404 DownloadSet downloads_;
391 DownloadMap history_downloads_; 405 DownloadMap history_downloads_;
392 DownloadMap in_progress_; 406 DownloadMap in_progress_;
393 DownloadMap active_downloads_; 407 DownloadMap active_downloads_;
394 #if !defined(NDEBUG) 408 DownloadMap save_page_downloads_;
395 DownloadSet save_page_as_downloads_;
396 #endif
397 409
398 // True if the download manager has been initialized and requires a shutdown. 410 // True if the download manager has been initialized and requires a shutdown.
399 bool shutdown_needed_; 411 bool shutdown_needed_;
400 412
401 // Observers that want to be notified of changes to the set of downloads. 413 // Observers that want to be notified of changes to the set of downloads.
402 ObserverList<Observer> observers_; 414 ObserverList<Observer> observers_;
403 415
404 // The current active profile. 416 // The current active profile.
405 Profile* profile_; 417 Profile* profile_;
406 418
407 scoped_ptr<DownloadHistory> download_history_; 419 scoped_ptr<DownloadHistory> download_history_;
408 420
409 scoped_ptr<DownloadPrefs> download_prefs_; 421 scoped_ptr<DownloadPrefs> download_prefs_;
410 422
411 // Non-owning pointer for handling file writing on the download_thread_. 423 // Non-owning pointer for handling file writing on the download_thread_.
412 DownloadFileManager* file_manager_; 424 DownloadFileManager* file_manager_;
413 425
414 // Non-owning pointer for updating the download status. 426 // Non-owning pointer for updating the download status.
415 base::WeakPtr<DownloadStatusUpdater> status_updater_; 427 base::WeakPtr<DownloadStatusUpdater> status_updater_;
416 428
417 // The user's last choice for download directory. This is only used when the 429 // The user's last choice for download directory. This is only used when the
418 // user wants us to prompt for a save location for each download. 430 // user wants us to prompt for a save location for each download.
419 FilePath last_download_path_; 431 FilePath last_download_path_;
420 432
433 // Save Page Ids.
Paweł Hajdan Jr. 2011/08/01 18:22:59 nit: Hey, please actually see my earlier comment a
achuithb 2011/08/01 21:19:54 Sorry, I changed the comments of the public GetNex
434 int32 next_save_page_id_;
435
421 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 436 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
422 437
423 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 438 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
424 }; 439 };
425 440
426 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 441 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698