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(); } |
208 | 204 |
209 // Creates the download item. Must be called on the UI thread. | 205 // Creates the download item. Must be called on the UI thread. |
210 void CreateDownloadItem(DownloadCreateInfo* info); | 206 void CreateDownloadItem(DownloadCreateInfo* info); |
211 | 207 |
212 // Clears the last download path, used to initialize "save as" dialogs. | 208 // Clears the last download path, used to initialize "save as" dialogs. |
213 void ClearLastDownloadPath(); | 209 void ClearLastDownloadPath(); |
214 | 210 |
215 // Tests if a file type should be opened automatically. | 211 // Tests if a file type should be opened automatically. |
216 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; | 212 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; |
217 | 213 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); | 255 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); |
260 | 256 |
261 // Assert the named download item is on the correct queues | 257 // Assert the named download item is on the correct queues |
262 // in the DownloadManager. For debugging. | 258 // in the DownloadManager. For debugging. |
263 void AssertQueueStateConsistent(DownloadItem* download); | 259 void AssertQueueStateConsistent(DownloadItem* download); |
264 | 260 |
265 // Get the download item from the history map. Useful after the item has | 261 // 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. | 262 // been removed from the active map, or was retrieved from the history DB. |
267 DownloadItem* GetDownloadItem(int id); | 263 DownloadItem* GetDownloadItem(int id); |
268 | 264 |
| 265 // Called when Save Page download starts. Transfers ownership of |download| |
| 266 // to the DownloadManager. |
| 267 void SavePageDownloadStarted(DownloadItem* download); |
| 268 |
| 269 // Callback when Save Page As entry is commited to the history system. |
| 270 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle); |
| 271 |
| 272 // Called when Save Page download is done. |
| 273 void SavePageDownloadFinished(DownloadItem* download); |
| 274 |
| 275 // Save Page Ids. |
| 276 int32 GetNextSavePageId(); |
| 277 |
269 private: | 278 private: |
270 // For testing. | 279 // For testing. |
271 friend class DownloadManagerTest; | 280 friend class DownloadManagerTest; |
272 friend class MockDownloadManager; | 281 friend class MockDownloadManager; |
| 282 friend class SavePageBrowserTest; |
273 | 283 |
274 // 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 |
275 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 285 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
276 // DownloadManager to the observers of the incognito DownloadManager. | 286 // DownloadManager to the observers of the incognito DownloadManager. |
277 class OtherDownloadManagerObserver : public Observer { | 287 class OtherDownloadManagerObserver : public Observer { |
278 public: | 288 public: |
279 explicit OtherDownloadManagerObserver( | 289 explicit OtherDownloadManagerObserver( |
280 DownloadManager* observing_download_manager); | 290 DownloadManager* observing_download_manager); |
281 virtual ~OtherDownloadManagerObserver(); | 291 virtual ~OtherDownloadManagerObserver(); |
282 | 292 |
283 // Observer interface. | 293 // Observer interface. |
284 virtual void ModelChanged(); | 294 virtual void ModelChanged(); |
285 virtual void ManagerGoingDown(); | 295 virtual void ManagerGoingDown(); |
286 | 296 |
287 private: | 297 private: |
288 // The incognito download manager. | 298 // The incognito download manager. |
289 DownloadManager* observing_download_manager_; | 299 DownloadManager* observing_download_manager_; |
290 | 300 |
291 // The original profile's download manager. | 301 // The original profile's download manager. |
292 DownloadManager* observed_download_manager_; | 302 DownloadManager* observed_download_manager_; |
293 }; | 303 }; |
294 | 304 |
295 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 305 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
296 friend class DeleteTask<DownloadManager>; | 306 friend class DeleteTask<DownloadManager>; |
297 friend class OtherDownloadManagerObserver; | 307 friend class OtherDownloadManagerObserver; |
298 | 308 |
299 virtual ~DownloadManager(); | 309 virtual ~DownloadManager(); |
300 | 310 |
| 311 DownloadHistory* download_history() const { return download_history_.get(); } |
| 312 |
301 // 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. |
302 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 314 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
303 | 315 |
304 // 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 |
305 // 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 |
306 // and then notifies this update to the file's observer. | 318 // and then notifies this update to the file's observer. |
307 void OnFileRemovalDetected(int64 db_handle); | 319 void OnFileRemovalDetected(int64 db_handle); |
308 | 320 |
309 // 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 |
310 // 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Downloads from past sessions read from a persisted state from the | 401 // Downloads from past sessions read from a persisted state from the |
390 // history system are placed directly into |history_downloads_| since | 402 // history system are placed directly into |history_downloads_| since |
391 // they have valid handles in the history system. | 403 // they have valid handles in the history system. |
392 typedef std::set<DownloadItem*> DownloadSet; | 404 typedef std::set<DownloadItem*> DownloadSet; |
393 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 405 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
394 | 406 |
395 DownloadSet downloads_; | 407 DownloadSet downloads_; |
396 DownloadMap history_downloads_; | 408 DownloadMap history_downloads_; |
397 DownloadMap in_progress_; | 409 DownloadMap in_progress_; |
398 DownloadMap active_downloads_; | 410 DownloadMap active_downloads_; |
399 #if !defined(NDEBUG) | 411 DownloadMap save_page_downloads_; |
400 DownloadSet save_page_as_downloads_; | |
401 #endif | |
402 | 412 |
403 // True if the download manager has been initialized and requires a shutdown. | 413 // True if the download manager has been initialized and requires a shutdown. |
404 bool shutdown_needed_; | 414 bool shutdown_needed_; |
405 | 415 |
406 // Observers that want to be notified of changes to the set of downloads. | 416 // Observers that want to be notified of changes to the set of downloads. |
407 ObserverList<Observer> observers_; | 417 ObserverList<Observer> observers_; |
408 | 418 |
409 // The current active profile. | 419 // The current active profile. |
410 Profile* profile_; | 420 Profile* profile_; |
411 | 421 |
412 scoped_ptr<DownloadHistory> download_history_; | 422 scoped_ptr<DownloadHistory> download_history_; |
413 | 423 |
414 scoped_ptr<DownloadPrefs> download_prefs_; | 424 scoped_ptr<DownloadPrefs> download_prefs_; |
415 | 425 |
416 // Non-owning pointer for handling file writing on the download_thread_. | 426 // Non-owning pointer for handling file writing on the download_thread_. |
417 DownloadFileManager* file_manager_; | 427 DownloadFileManager* file_manager_; |
418 | 428 |
419 // Non-owning pointer for updating the download status. | 429 // Non-owning pointer for updating the download status. |
420 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 430 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
421 | 431 |
422 // The user's last choice for download directory. This is only used when the | 432 // 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. | 433 // user wants us to prompt for a save location for each download. |
424 FilePath last_download_path_; | 434 FilePath last_download_path_; |
425 | 435 |
| 436 // Save Page Ids. |
| 437 int32 next_save_page_id_; |
| 438 |
426 // The "Save As" dialog box used to ask the user where a file should be | 439 // The "Save As" dialog box used to ask the user where a file should be |
427 // saved. | 440 // saved. |
428 scoped_refptr<SelectFileDialog> select_file_dialog_; | 441 scoped_refptr<SelectFileDialog> select_file_dialog_; |
429 | 442 |
430 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 443 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
431 | 444 |
432 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 445 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
433 }; | 446 }; |
434 | 447 |
435 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 448 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |