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

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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // Called immediately after the DownloadManager puts up a select file 87 // Called immediately after the DownloadManager puts up a select file
88 // dialog. 88 // dialog.
89 // |id| indicates which download opened the dialog. 89 // |id| indicates which download opened the dialog.
90 virtual void SelectFileDialogDisplayed(int32 id) {} 90 virtual void SelectFileDialogDisplayed(int32 id) {}
91 91
92 protected: 92 protected:
93 virtual ~Observer() {} 93 virtual ~Observer() {}
94 }; 94 };
95 95
96 typedef std::vector<DownloadItem*> DownloadVector;
96 // Return all temporary downloads that reside in the specified directory. 97 // Return all temporary downloads that reside in the specified directory.
97 void GetTemporaryDownloads(const FilePath& dir_path, 98 void GetTemporaryDownloads(const FilePath& dir_path,
98 std::vector<DownloadItem*>* result); 99 DownloadVector* result);
99 100
100 // Return all non-temporary downloads in the specified directory that are 101 // Return all non-temporary downloads in the specified directory that are
101 // are in progress or have completed. 102 // are in progress or have completed.
102 void GetAllDownloads(const FilePath& dir_path, 103 void GetAllDownloads(const FilePath& dir_path,
103 std::vector<DownloadItem*>* result); 104 DownloadVector* result);
104 105
105 // Return all non-temporary downloads in the specified directory that are 106 // Return all non-temporary downloads in the specified directory that are
106 // in-progress (including dangerous downloads waiting for user confirmation). 107 // in-progress (including dangerous downloads waiting for user confirmation).
107 void GetCurrentDownloads(const FilePath& dir_path, 108 void GetCurrentDownloads(const FilePath& dir_path,
108 std::vector<DownloadItem*>* result); 109 DownloadVector* result);
109 110
110 // Returns all non-temporary downloads matching |query|. Empty query matches 111 // Returns all non-temporary downloads matching |query|. Empty query matches
111 // everything. 112 // everything.
112 void SearchDownloads(const string16& query, 113 void SearchDownloads(const string16& query,
113 std::vector<DownloadItem*>* result); 114 DownloadVector* result);
114 115
115 // Returns true if initialized properly. 116 // Returns true if initialized properly.
116 bool Init(Profile* profile); 117 bool Init(Profile* profile);
117 118
118 // Notifications sent from the download thread to the UI thread 119 // Notifications sent from the download thread to the UI thread
119 void StartDownload(int32 id); 120 void StartDownload(int32 id);
120 void UpdateDownload(int32 download_id, int64 size); 121 void UpdateDownload(int32 download_id, int64 size);
121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 122 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
122 // is not available. 123 // is not available.
123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, 124 void OnResponseCompleted(int32 download_id, int64 size, int os_error,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 int RemoveDownloads(const base::Time remove_begin); 158 int RemoveDownloads(const base::Time remove_begin);
158 159
159 // Remove all downloads will delete all downloads. The number of downloads 160 // Remove all downloads will delete all downloads. The number of downloads
160 // deleted is returned back to the caller. 161 // deleted is returned back to the caller.
161 int RemoveAllDownloads(); 162 int RemoveAllDownloads();
162 163
163 // Final download manager transition for download: Update the download 164 // Final download manager transition for download: Update the download
164 // history and remove the download from |active_downloads_|. 165 // history and remove the download from |active_downloads_|.
165 void DownloadCompleted(int32 download_id); 166 void DownloadCompleted(int32 download_id);
166 167
167 // Called when a Save Page As download is started. Transfers ownership
168 // of |download_item| to the DownloadManager.
169 void SavePageAsDownloadStarted(DownloadItem* download_item);
170
171 // Download the object at the URL. Used in cases such as "Save Link As..." 168 // Download the object at the URL. Used in cases such as "Save Link As..."
172 void DownloadUrl(const GURL& url, 169 void DownloadUrl(const GURL& url,
173 const GURL& referrer, 170 const GURL& referrer,
174 const std::string& referrer_encoding, 171 const std::string& referrer_encoding,
175 TabContents* tab_contents); 172 TabContents* tab_contents);
176 173
177 // Download the object at the URL and save it to the specified path. The 174 // Download the object at the URL and save it to the specified path. The
178 // download is treated as the temporary download and thus will not appear 175 // download is treated as the temporary download and thus will not appear
179 // in the download history. Used in cases such as drag and drop. 176 // in the download history. Used in cases such as drag and drop.
180 void DownloadUrlToFile(const GURL& url, 177 void DownloadUrlToFile(const GURL& url,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); 253 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
257 254
258 // Assert the named download item is on the correct queues 255 // Assert the named download item is on the correct queues
259 // in the DownloadManager. For debugging. 256 // in the DownloadManager. For debugging.
260 void AssertQueueStateConsistent(DownloadItem* download); 257 void AssertQueueStateConsistent(DownloadItem* download);
261 258
262 // Get the download item from the history map. Useful after the item has 259 // Get the download item from the history map. Useful after the item has
263 // been removed from the active map, or was retrieved from the history DB. 260 // been removed from the active map, or was retrieved from the history DB.
264 DownloadItem* GetDownloadItem(int id); 261 DownloadItem* GetDownloadItem(int id);
265 262
263 // Called when Save Page download starts. Transfers ownership of |download|
264 // to the DownloadManager.
265 void SavePageDownloadStarted(DownloadItem* download);
266
267 // Callback when Save Page As entry is commited to the history system.
268 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle);
269
270 // Called when Save Page download is done.
271 void SavePageDownloadFinished(DownloadItem* download);
272
273 // Save Page Ids.
274 int32 GetNextSavePageId();
275
266 private: 276 private:
267 // For testing. 277 // For testing.
268 friend class DownloadManagerTest; 278 friend class DownloadManagerTest;
269 friend class MockDownloadManager; 279 friend class MockDownloadManager;
280 friend class SavePageBrowserTest;
270 281
271 // This class is used to let an incognito DownloadManager observe changes to 282 // This class is used to let an incognito DownloadManager observe changes to
272 // a normal DownloadManager, to propagate ModelChanged() calls from the parent 283 // a normal DownloadManager, to propagate ModelChanged() calls from the parent
273 // DownloadManager to the observers of the incognito DownloadManager. 284 // DownloadManager to the observers of the incognito DownloadManager.
274 class OtherDownloadManagerObserver : public Observer { 285 class OtherDownloadManagerObserver : public Observer {
275 public: 286 public:
276 explicit OtherDownloadManagerObserver( 287 explicit OtherDownloadManagerObserver(
277 DownloadManager* observing_download_manager); 288 DownloadManager* observing_download_manager);
278 virtual ~OtherDownloadManagerObserver(); 289 virtual ~OtherDownloadManagerObserver();
279 290
280 // Observer interface. 291 // Observer interface.
281 virtual void ModelChanged(); 292 virtual void ModelChanged();
282 virtual void ManagerGoingDown(); 293 virtual void ManagerGoingDown();
283 294
284 private: 295 private:
285 // The incognito download manager. 296 // The incognito download manager.
286 DownloadManager* observing_download_manager_; 297 DownloadManager* observing_download_manager_;
287 298
288 // The original profile's download manager. 299 // The original profile's download manager.
289 DownloadManager* observed_download_manager_; 300 DownloadManager* observed_download_manager_;
290 }; 301 };
291 302
292 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 303 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
293 friend class DeleteTask<DownloadManager>; 304 friend class DeleteTask<DownloadManager>;
294 friend class OtherDownloadManagerObserver; 305 friend class OtherDownloadManagerObserver;
295 306
296 virtual ~DownloadManager(); 307 virtual ~DownloadManager();
297 308
309 DownloadHistory* download_history() const { return download_history_.get(); }
310
298 // Called on the FILE thread to check the existence of a downloaded file. 311 // Called on the FILE thread to check the existence of a downloaded file.
299 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); 312 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path);
300 313
301 // Called on the UI thread if the FILE thread detects the removal of 314 // Called on the UI thread if the FILE thread detects the removal of
302 // the downloaded file. The UI thread updates the state of the file 315 // the downloaded file. The UI thread updates the state of the file
303 // and then notifies this update to the file's observer. 316 // and then notifies this update to the file's observer.
304 void OnFileRemovalDetected(int64 db_handle); 317 void OnFileRemovalDetected(int64 db_handle);
305 318
306 // Called on the download thread to check whether the suggested file path 319 // Called on the download thread to check whether the suggested file path
307 // exists. We don't check if the file exists on the UI thread to avoid UI 320 // 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
343 // yet in the history map. 356 // yet in the history map.
344 DownloadItem* GetActiveDownloadItem(int id); 357 DownloadItem* GetActiveDownloadItem(int id);
345 358
346 // Debugging routine to confirm relationship between below 359 // Debugging routine to confirm relationship between below
347 // containers; no-op if NDEBUG. 360 // containers; no-op if NDEBUG.
348 void AssertContainersConsistent() const; 361 void AssertContainersConsistent() const;
349 362
350 // Add a DownloadItem to history_downloads_. 363 // Add a DownloadItem to history_downloads_.
351 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 364 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
352 365
366 typedef std::set<DownloadItem*> DownloadSet;
367 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
368
369 int RemoveDownloadItems(const DownloadSet& items);
Randy Smith (Not in Mondays) 2011/07/28 21:16:04 Actually, thinking a bit more about this function,
achuithb 2011/07/28 22:23:27 I can't get this to work. In addition to removing
Randy Smith (Not in Mondays) 2011/07/28 23:24:05 Good points. The way that you've got it LGTM.
370
353 // |downloads_| is the owning set for all downloads known to the 371 // |downloads_| is the owning set for all downloads known to the
354 // DownloadManager. This includes downloads started by the user in 372 // DownloadManager. This includes downloads started by the user in
355 // this session, downloads initialized from the history system, and 373 // this session, downloads initialized from the history system, and
356 // "save page as" downloads. All other DownloadItem containers in 374 // "save page as" downloads. All other DownloadItem containers in
357 // the DownloadManager are maps; they do not own the DownloadItems. 375 // the DownloadManager are maps; they do not own the DownloadItems.
358 // Note that this is the only place (with any functional implications; 376 // Note that this is the only place (with any functional implications;
359 // see save_page_as_downloads_ below) that "save page as" downloads are 377 // see save_page_as_downloads_ below) that "save page as" downloads are
360 // kept, as the DownloadManager's only job is to hold onto those 378 // kept, as the DownloadManager's only job is to hold onto those
361 // until destruction. 379 // until destruction.
362 // 380 //
(...skipping 16 matching lines...) Expand all
379 // When a download is created through a user action, the corresponding 397 // When a download is created through a user action, the corresponding
380 // DownloadItem* is placed in |active_downloads_| and remains there until the 398 // DownloadItem* is placed in |active_downloads_| and remains there until the
381 // download is in a terminal state (COMPLETE or CANCELLED). It is also 399 // download is in a terminal state (COMPLETE or CANCELLED). It is also
382 // placed in |in_progress_| and remains there until it has received a 400 // placed in |in_progress_| and remains there until it has received a
383 // valid handle from the history system. Once it has a valid handle, the 401 // valid handle from the history system. Once it has a valid handle, the
384 // DownloadItem* is placed in the |history_downloads_| map. When the 402 // DownloadItem* is placed in the |history_downloads_| map. When the
385 // download reaches a terminal state, it is removed from |in_progress_|. 403 // download reaches a terminal state, it is removed from |in_progress_|.
386 // Downloads from past sessions read from a persisted state from the 404 // Downloads from past sessions read from a persisted state from the
387 // history system are placed directly into |history_downloads_| since 405 // history system are placed directly into |history_downloads_| since
388 // they have valid handles in the history system. 406 // they have valid handles in the history system.
389 typedef std::set<DownloadItem*> DownloadSet;
390 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
391 407
392 DownloadSet downloads_; 408 DownloadSet downloads_;
393 DownloadMap history_downloads_; 409 DownloadMap history_downloads_;
394 DownloadMap in_progress_; 410 DownloadMap in_progress_;
395 DownloadMap active_downloads_; 411 DownloadMap active_downloads_;
396 #if !defined(NDEBUG) 412 DownloadMap save_page_downloads_;
397 DownloadSet save_page_as_downloads_;
398 #endif
399 413
400 // True if the download manager has been initialized and requires a shutdown. 414 // True if the download manager has been initialized and requires a shutdown.
401 bool shutdown_needed_; 415 bool shutdown_needed_;
402 416
403 // Observers that want to be notified of changes to the set of downloads. 417 // Observers that want to be notified of changes to the set of downloads.
404 ObserverList<Observer> observers_; 418 ObserverList<Observer> observers_;
405 419
406 // The current active profile. 420 // The current active profile.
407 Profile* profile_; 421 Profile* profile_;
408 422
409 scoped_ptr<DownloadHistory> download_history_; 423 scoped_ptr<DownloadHistory> download_history_;
410 424
411 scoped_ptr<DownloadPrefs> download_prefs_; 425 scoped_ptr<DownloadPrefs> download_prefs_;
412 426
413 // Non-owning pointer for handling file writing on the download_thread_. 427 // Non-owning pointer for handling file writing on the download_thread_.
414 DownloadFileManager* file_manager_; 428 DownloadFileManager* file_manager_;
415 429
416 // Non-owning pointer for updating the download status. 430 // Non-owning pointer for updating the download status.
417 base::WeakPtr<DownloadStatusUpdater> status_updater_; 431 base::WeakPtr<DownloadStatusUpdater> status_updater_;
418 432
419 // The user's last choice for download directory. This is only used when the 433 // The user's last choice for download directory. This is only used when the
420 // user wants us to prompt for a save location for each download. 434 // user wants us to prompt for a save location for each download.
421 FilePath last_download_path_; 435 FilePath last_download_path_;
422 436
437 // Save Page Ids.
438 int32 next_save_page_id_;
439
423 // The "Save As" dialog box used to ask the user where a file should be 440 // The "Save As" dialog box used to ask the user where a file should be
424 // saved. 441 // saved.
425 scoped_refptr<SelectFileDialog> select_file_dialog_; 442 scoped_refptr<SelectFileDialog> select_file_dialog_;
426 443
427 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 444 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
428 445
429 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 446 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
430 }; 447 };
431 448
432 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 449 #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