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

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;
97
96 // Return all temporary downloads that reside in the specified directory. 98 // Return all temporary downloads that reside in the specified directory.
97 void GetTemporaryDownloads(const FilePath& dir_path, 99 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result);
98 std::vector<DownloadItem*>* 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, DownloadVector* result);
103 std::vector<DownloadItem*>* result);
104 104
105 // Return all non-temporary downloads in the specified directory that are 105 // Return all non-temporary downloads in the specified directory that are
106 // in-progress (including dangerous downloads waiting for user confirmation). 106 // in-progress (including dangerous downloads waiting for user confirmation).
107 void GetCurrentDownloads(const FilePath& dir_path, 107 void GetCurrentDownloads(const FilePath& dir_path, DownloadVector* result);
108 std::vector<DownloadItem*>* result);
109 108
110 // Returns all non-temporary downloads matching |query|. Empty query matches 109 // Returns all non-temporary downloads matching |query|. Empty query matches
111 // everything. 110 // everything.
112 void SearchDownloads(const string16& query, 111 void SearchDownloads(const string16& query, DownloadVector* result);
113 std::vector<DownloadItem*>* result);
114 112
115 // Returns true if initialized properly. 113 // Returns true if initialized properly.
116 bool Init(Profile* profile); 114 bool Init(Profile* profile);
117 115
118 // Notifications sent from the download thread to the UI thread 116 // Notifications sent from the download thread to the UI thread
119 void StartDownload(int32 id); 117 void StartDownload(int32 id);
120 void UpdateDownload(int32 download_id, int64 size); 118 void UpdateDownload(int32 download_id, int64 size);
121 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 119 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
122 // is not available. 120 // is not available.
123 void OnResponseCompleted(int32 download_id, int64 size, int os_error, 121 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); 155 int RemoveDownloads(const base::Time remove_begin);
158 156
159 // Remove all downloads will delete all downloads. The number of downloads 157 // Remove all downloads will delete all downloads. The number of downloads
160 // deleted is returned back to the caller. 158 // deleted is returned back to the caller.
161 int RemoveAllDownloads(); 159 int RemoveAllDownloads();
162 160
163 // Final download manager transition for download: Update the download 161 // Final download manager transition for download: Update the download
164 // history and remove the download from |active_downloads_|. 162 // history and remove the download from |active_downloads_|.
165 void DownloadCompleted(int32 download_id); 163 void DownloadCompleted(int32 download_id);
166 164
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..." 165 // Download the object at the URL. Used in cases such as "Save Link As..."
172 void DownloadUrl(const GURL& url, 166 void DownloadUrl(const GURL& url,
173 const GURL& referrer, 167 const GURL& referrer,
174 const std::string& referrer_encoding, 168 const std::string& referrer_encoding,
175 TabContents* tab_contents); 169 TabContents* tab_contents);
176 170
177 // Download the object at the URL and save it to the specified path. The 171 // 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 172 // 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. 173 // in the download history. Used in cases such as drag and drop.
180 void DownloadUrlToFile(const GURL& url, 174 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); 250 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
257 251
258 // Assert the named download item is on the correct queues 252 // Assert the named download item is on the correct queues
259 // in the DownloadManager. For debugging. 253 // in the DownloadManager. For debugging.
260 void AssertQueueStateConsistent(DownloadItem* download); 254 void AssertQueueStateConsistent(DownloadItem* download);
261 255
262 // Get the download item from the history map. Useful after the item has 256 // 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. 257 // been removed from the active map, or was retrieved from the history DB.
264 DownloadItem* GetDownloadItem(int id); 258 DownloadItem* GetDownloadItem(int id);
265 259
260 // Called when Save Page download starts. Transfers ownership of |download|
261 // to the DownloadManager.
262 void SavePageDownloadStarted(DownloadItem* download);
263
264 // Callback when Save Page As entry is commited to the history system.
265 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle);
266
267 // Called when Save Page download is done.
268 void SavePageDownloadFinished(DownloadItem* download);
269
270 // Download Id for next Save Page.
271 int32 GetNextSavePageId();
272
266 DownloadManagerDelegate* delegate() const { return delegate_; } 273 DownloadManagerDelegate* delegate() const { return delegate_; }
267 274
268 private: 275 private:
276 typedef std::set<DownloadItem*> DownloadSet;
277 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
278
269 // For testing. 279 // For testing.
270 friend class DownloadManagerTest; 280 friend class DownloadManagerTest;
271 friend class MockDownloadManager; 281 friend class MockDownloadManager;
282 friend class SavePageBrowserTest;
272 283
273 // This class is used to let an incognito DownloadManager observe changes to 284 // This class is used to let an incognito DownloadManager observe changes to
274 // a normal DownloadManager, to propagate ModelChanged() calls from the parent 285 // a normal DownloadManager, to propagate ModelChanged() calls from the parent
275 // DownloadManager to the observers of the incognito DownloadManager. 286 // DownloadManager to the observers of the incognito DownloadManager.
276 class OtherDownloadManagerObserver : public Observer { 287 class OtherDownloadManagerObserver : public Observer {
277 public: 288 public:
278 explicit OtherDownloadManagerObserver( 289 explicit OtherDownloadManagerObserver(
279 DownloadManager* observing_download_manager); 290 DownloadManager* observing_download_manager);
280 virtual ~OtherDownloadManagerObserver(); 291 virtual ~OtherDownloadManagerObserver();
281 292
282 // Observer interface. 293 // Observer interface.
283 virtual void ModelChanged(); 294 virtual void ModelChanged();
284 virtual void ManagerGoingDown(); 295 virtual void ManagerGoingDown();
285 296
286 private: 297 private:
287 // The incognito download manager. 298 // The incognito download manager.
288 DownloadManager* observing_download_manager_; 299 DownloadManager* observing_download_manager_;
289 300
290 // The original profile's download manager. 301 // The original profile's download manager.
291 DownloadManager* observed_download_manager_; 302 DownloadManager* observed_download_manager_;
292 }; 303 };
293 304
294 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 305 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
295 friend class DeleteTask<DownloadManager>; 306 friend class DeleteTask<DownloadManager>;
296 friend class OtherDownloadManagerObserver; 307 friend class OtherDownloadManagerObserver;
297 308
298 virtual ~DownloadManager(); 309 virtual ~DownloadManager();
299 310
311 DownloadHistory* download_history() { return download_history_.get(); }
Paweł Hajdan Jr. 2011/08/03 19:07:46 Bleh, still private.
achuithb 2011/08/03 19:52:43 It was public briefly in patchset 44. I've made it
312
300 // Called on the FILE thread to check the existence of a downloaded file. 313 // Called on the FILE thread to check the existence of a downloaded file.
301 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); 314 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path);
302 315
303 // Called on the UI thread if the FILE thread detects the removal of 316 // Called on the UI thread if the FILE thread detects the removal of
304 // the downloaded file. The UI thread updates the state of the file 317 // the downloaded file. The UI thread updates the state of the file
305 // and then notifies this update to the file's observer. 318 // and then notifies this update to the file's observer.
306 void OnFileRemovalDetected(int64 db_handle); 319 void OnFileRemovalDetected(int64 db_handle);
307 320
308 // Called on the download thread to check whether the suggested file path 321 // Called on the download thread to check whether the suggested file path
309 // exists. We don't check if the file exists on the UI thread to avoid UI 322 // 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
345 // yet in the history map. 358 // yet in the history map.
346 DownloadItem* GetActiveDownloadItem(int id); 359 DownloadItem* GetActiveDownloadItem(int id);
347 360
348 // Debugging routine to confirm relationship between below 361 // Debugging routine to confirm relationship between below
349 // containers; no-op if NDEBUG. 362 // containers; no-op if NDEBUG.
350 void AssertContainersConsistent() const; 363 void AssertContainersConsistent() const;
351 364
352 // Add a DownloadItem to history_downloads_. 365 // Add a DownloadItem to history_downloads_.
353 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 366 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
354 367
368 // Remove from internal maps.
369 int RemoveDownloadItems(const DownloadVector& pending_deletes);
370
355 // |downloads_| is the owning set for all downloads known to the 371 // |downloads_| is the owning set for all downloads known to the
356 // DownloadManager. This includes downloads started by the user in 372 // DownloadManager. This includes downloads started by the user in
357 // this session, downloads initialized from the history system, and 373 // this session, downloads initialized from the history system, and
358 // "save page as" downloads. All other DownloadItem containers in 374 // "save page as" downloads. All other DownloadItem containers in
359 // the DownloadManager are maps; they do not own the DownloadItems. 375 // the DownloadManager are maps; they do not own the DownloadItems.
360 // Note that this is the only place (with any functional implications; 376 // Note that this is the only place (with any functional implications;
361 // 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
362 // 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
363 // until destruction. 379 // until destruction.
364 // 380 //
(...skipping 16 matching lines...) Expand all
381 // When a download is created through a user action, the corresponding 397 // When a download is created through a user action, the corresponding
382 // DownloadItem* is placed in |active_downloads_| and remains there until the 398 // DownloadItem* is placed in |active_downloads_| and remains there until the
383 // 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
384 // 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
385 // 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
386 // DownloadItem* is placed in the |history_downloads_| map. When the 402 // DownloadItem* is placed in the |history_downloads_| map. When the
387 // download reaches a terminal state, it is removed from |in_progress_|. 403 // download reaches a terminal state, it is removed from |in_progress_|.
388 // Downloads from past sessions read from a persisted state from the 404 // Downloads from past sessions read from a persisted state from the
389 // history system are placed directly into |history_downloads_| since 405 // history system are placed directly into |history_downloads_| since
390 // they have valid handles in the history system. 406 // they have valid handles in the history system.
391 typedef std::set<DownloadItem*> DownloadSet;
392 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
393 407
394 DownloadSet downloads_; 408 DownloadSet downloads_;
395 DownloadMap history_downloads_; 409 DownloadMap history_downloads_;
396 DownloadMap in_progress_; 410 DownloadMap in_progress_;
397 DownloadMap active_downloads_; 411 DownloadMap active_downloads_;
398 #if !defined(NDEBUG) 412 DownloadMap save_page_downloads_;
399 DownloadSet save_page_as_downloads_;
400 #endif
401 413
402 // 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.
403 bool shutdown_needed_; 415 bool shutdown_needed_;
404 416
405 // 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.
406 ObserverList<Observer> observers_; 418 ObserverList<Observer> observers_;
407 419
408 // The current active profile. 420 // The current active profile.
409 Profile* profile_; 421 Profile* profile_;
410 422
411 scoped_ptr<DownloadHistory> download_history_; 423 scoped_ptr<DownloadHistory> download_history_;
412 424
413 scoped_ptr<DownloadPrefs> download_prefs_; 425 scoped_ptr<DownloadPrefs> download_prefs_;
414 426
415 // Non-owning pointer for handling file writing on the download_thread_. 427 // Non-owning pointer for handling file writing on the download_thread_.
416 DownloadFileManager* file_manager_; 428 DownloadFileManager* file_manager_;
417 429
418 // Non-owning pointer for updating the download status. 430 // Non-owning pointer for updating the download status.
419 base::WeakPtr<DownloadStatusUpdater> status_updater_; 431 base::WeakPtr<DownloadStatusUpdater> status_updater_;
420 432
421 // 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
422 // 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.
423 FilePath last_download_path_; 435 FilePath last_download_path_;
424 436
437 // Download Id for next Save Page.
438 int32 next_save_page_id_;
439
425 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 440 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
426 441
427 // Allows an embedder to control behavior. Guaranteed to outlive this object. 442 // Allows an embedder to control behavior. Guaranteed to outlive this object.
428 DownloadManagerDelegate* delegate_; 443 DownloadManagerDelegate* delegate_;
429 444
430 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 445 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
431 }; 446 };
432 447
433 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 448 #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