OLD | NEW |
---|---|
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 int RemoveDownloads(const base::Time remove_begin); | 157 int RemoveDownloads(const base::Time remove_begin); |
158 | 158 |
159 // Remove all downloads will delete all downloads. The number of downloads | 159 // Remove all downloads will delete all downloads. The number of downloads |
160 // deleted is returned back to the caller. | 160 // deleted is returned back to the caller. |
161 int RemoveAllDownloads(); | 161 int RemoveAllDownloads(); |
162 | 162 |
163 // Final download manager transition for download: Update the download | 163 // Final download manager transition for download: Update the download |
164 // history and remove the download from |active_downloads_|. | 164 // history and remove the download from |active_downloads_|. |
165 void DownloadCompleted(int32 download_id); | 165 void DownloadCompleted(int32 download_id); |
166 | 166 |
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..." | 167 // Download the object at the URL. Used in cases such as "Save Link As..." |
172 void DownloadUrl(const GURL& url, | 168 void DownloadUrl(const GURL& url, |
173 const GURL& referrer, | 169 const GURL& referrer, |
174 const std::string& referrer_encoding, | 170 const std::string& referrer_encoding, |
175 TabContents* tab_contents); | 171 TabContents* tab_contents); |
176 | 172 |
177 // Download the object at the URL and save it to the specified path. The | 173 // 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 | 174 // 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. | 175 // in the download history. Used in cases such as drag and drop. |
180 void DownloadUrlToFile(const GURL& url, | 176 void DownloadUrlToFile(const GURL& url, |
(...skipping 14 matching lines...) Expand all Loading... | |
195 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle); | 191 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle); |
196 | 192 |
197 // Display a new download in the appropriate browser UI. | 193 // Display a new download in the appropriate browser UI. |
198 void ShowDownloadInBrowser(DownloadItem* download); | 194 void ShowDownloadInBrowser(DownloadItem* download); |
199 | 195 |
200 // The number of in progress (including paused) downloads. | 196 // The number of in progress (including paused) downloads. |
201 int in_progress_count() const { | 197 int in_progress_count() const { |
202 return static_cast<int>(in_progress_.size()); | 198 return static_cast<int>(in_progress_.size()); |
203 } | 199 } |
204 | 200 |
205 Profile* profile() { return profile_; } | 201 Profile* profile() const { return profile_; } |
206 | 202 |
207 DownloadPrefs* download_prefs() { return download_prefs_.get(); } | 203 DownloadPrefs* download_prefs() const { return download_prefs_.get(); } |
204 | |
205 DownloadHistory* download_history() const { return download_history_.get(); } | |
Randy Smith (Not in Mondays)
2011/07/15 17:58:39
If this is now only used by the browsertest, can y
achuithb
2011/07/16 20:15:32
Done.
| |
208 | 206 |
209 // Creates the download item. Must be called on the UI thread. | 207 // Creates the download item. Must be called on the UI thread. |
210 void CreateDownloadItem(DownloadCreateInfo* info); | 208 void CreateDownloadItem(DownloadCreateInfo* info); |
211 | 209 |
212 // Clears the last download path, used to initialize "save as" dialogs. | 210 // Clears the last download path, used to initialize "save as" dialogs. |
213 void ClearLastDownloadPath(); | 211 void ClearLastDownloadPath(); |
214 | 212 |
215 // Tests if a file type should be opened automatically. | 213 // Tests if a file type should be opened automatically. |
216 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; | 214 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; |
217 | 215 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); | 257 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); |
260 | 258 |
261 // Assert the named download item is on the correct queues | 259 // Assert the named download item is on the correct queues |
262 // in the DownloadManager. For debugging. | 260 // in the DownloadManager. For debugging. |
263 void AssertQueueStateConsistent(DownloadItem* download); | 261 void AssertQueueStateConsistent(DownloadItem* download); |
264 | 262 |
265 // Get the download item from the history map. Useful after the item has | 263 // Get the download item from the history map. Useful after the item has |
266 // been removed from the active map, or was retrieved from the history DB. | 264 // been removed from the active map, or was retrieved from the history DB. |
267 DownloadItem* GetDownloadItem(int id); | 265 DownloadItem* GetDownloadItem(int id); |
268 | 266 |
267 // Called when Save Page download starts. Transfers ownership of |download| | |
268 // to the DownloadManager. | |
269 void SavePageDownloadStarted(DownloadItem* download); | |
270 | |
271 // Callback when Save Page As entry is commited to the history system. | |
272 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle); | |
273 | |
274 // Called when Save Page download is done. | |
275 void SavePageDownloadFinished(DownloadItem* download); | |
276 | |
277 // Save Page Ids. | |
278 int32 GetNextSavePageId(); | |
279 | |
269 private: | 280 private: |
270 // For testing. | 281 // For testing. |
271 friend class DownloadManagerTest; | 282 friend class DownloadManagerTest; |
272 friend class MockDownloadManager; | 283 friend class MockDownloadManager; |
273 | 284 |
274 // This class is used to let an incognito DownloadManager observe changes to | 285 // This class is used to let an incognito DownloadManager observe changes to |
275 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 286 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
276 // DownloadManager to the observers of the incognito DownloadManager. | 287 // DownloadManager to the observers of the incognito DownloadManager. |
277 class OtherDownloadManagerObserver : public Observer { | 288 class OtherDownloadManagerObserver : public Observer { |
278 public: | 289 public: |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 // Downloads from past sessions read from a persisted state from the | 400 // Downloads from past sessions read from a persisted state from the |
390 // history system are placed directly into |history_downloads_| since | 401 // history system are placed directly into |history_downloads_| since |
391 // they have valid handles in the history system. | 402 // they have valid handles in the history system. |
392 typedef std::set<DownloadItem*> DownloadSet; | 403 typedef std::set<DownloadItem*> DownloadSet; |
393 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 404 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
394 | 405 |
395 DownloadSet downloads_; | 406 DownloadSet downloads_; |
396 DownloadMap history_downloads_; | 407 DownloadMap history_downloads_; |
397 DownloadMap in_progress_; | 408 DownloadMap in_progress_; |
398 DownloadMap active_downloads_; | 409 DownloadMap active_downloads_; |
410 DownloadMap save_page_downloads_; | |
Randy Smith (Not in Mondays)
2011/07/15 17:58:39
There's no point to having both this and save_page
achuithb
2011/07/16 20:15:32
Done.
| |
399 #if !defined(NDEBUG) | 411 #if !defined(NDEBUG) |
400 DownloadSet save_page_as_downloads_; | 412 DownloadSet save_page_as_downloads_; |
401 #endif | 413 #endif |
402 | 414 |
403 // True if the download manager has been initialized and requires a shutdown. | 415 // True if the download manager has been initialized and requires a shutdown. |
404 bool shutdown_needed_; | 416 bool shutdown_needed_; |
405 | 417 |
406 // Observers that want to be notified of changes to the set of downloads. | 418 // Observers that want to be notified of changes to the set of downloads. |
407 ObserverList<Observer> observers_; | 419 ObserverList<Observer> observers_; |
408 | 420 |
409 // The current active profile. | 421 // The current active profile. |
410 Profile* profile_; | 422 Profile* profile_; |
411 | 423 |
412 scoped_ptr<DownloadHistory> download_history_; | 424 scoped_ptr<DownloadHistory> download_history_; |
413 | 425 |
414 scoped_ptr<DownloadPrefs> download_prefs_; | 426 scoped_ptr<DownloadPrefs> download_prefs_; |
415 | 427 |
416 // Non-owning pointer for handling file writing on the download_thread_. | 428 // Non-owning pointer for handling file writing on the download_thread_. |
417 DownloadFileManager* file_manager_; | 429 DownloadFileManager* file_manager_; |
418 | 430 |
419 // Non-owning pointer for updating the download status. | 431 // Non-owning pointer for updating the download status. |
420 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 432 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
421 | 433 |
422 // The user's last choice for download directory. This is only used when the | 434 // The user's last choice for download directory. This is only used when the |
423 // user wants us to prompt for a save location for each download. | 435 // user wants us to prompt for a save location for each download. |
424 FilePath last_download_path_; | 436 FilePath last_download_path_; |
425 | 437 |
438 // Save Page Ids. | |
439 int32 next_save_page_id_; | |
440 | |
426 // The "Save As" dialog box used to ask the user where a file should be | 441 // The "Save As" dialog box used to ask the user where a file should be |
427 // saved. | 442 // saved. |
428 scoped_refptr<SelectFileDialog> select_file_dialog_; | 443 scoped_refptr<SelectFileDialog> select_file_dialog_; |
429 | 444 |
430 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 445 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
431 | 446 |
432 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 447 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
433 }; | 448 }; |
434 | 449 |
435 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 450 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |