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_; } |
Paweł Hajdan Jr.
2011/07/27 16:53:51
Why? It is risky (in terms of hard to misuse API)
Randy Smith (Not in Mondays)
2011/07/27 21:08:35
This was my fault; an earlier patchset was exposin
achuithb
2011/07/28 00:45:58
If you are saying that the const does nothing of v
| |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); | 252 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); |
257 | 253 |
258 // Assert the named download item is on the correct queues | 254 // Assert the named download item is on the correct queues |
259 // in the DownloadManager. For debugging. | 255 // in the DownloadManager. For debugging. |
260 void AssertQueueStateConsistent(DownloadItem* download); | 256 void AssertQueueStateConsistent(DownloadItem* download); |
261 | 257 |
262 // Get the download item from the history map. Useful after the item has | 258 // 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. | 259 // been removed from the active map, or was retrieved from the history DB. |
264 DownloadItem* GetDownloadItem(int id); | 260 DownloadItem* GetDownloadItem(int id); |
265 | 261 |
262 // Called when Save Page download starts. Transfers ownership of |download| | |
263 // to the DownloadManager. | |
264 void SavePageDownloadStarted(DownloadItem* download); | |
265 | |
266 // Callback when Save Page As entry is commited to the history system. | |
267 void OnSavePageDownloadEntryAdded(int32 download_id, int64 db_handle); | |
268 | |
269 // Called when Save Page download is done. | |
270 void SavePageDownloadFinished(DownloadItem* download); | |
271 | |
272 // Save Page Ids. | |
273 int32 GetNextSavePageId(); | |
274 | |
266 private: | 275 private: |
267 // For testing. | 276 // For testing. |
268 friend class DownloadManagerTest; | 277 friend class DownloadManagerTest; |
269 friend class MockDownloadManager; | 278 friend class MockDownloadManager; |
279 friend class SavePageBrowserTest; | |
270 | 280 |
271 // This class is used to let an incognito DownloadManager observe changes to | 281 // This class is used to let an incognito DownloadManager observe changes to |
272 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 282 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
273 // DownloadManager to the observers of the incognito DownloadManager. | 283 // DownloadManager to the observers of the incognito DownloadManager. |
274 class OtherDownloadManagerObserver : public Observer { | 284 class OtherDownloadManagerObserver : public Observer { |
275 public: | 285 public: |
276 explicit OtherDownloadManagerObserver( | 286 explicit OtherDownloadManagerObserver( |
277 DownloadManager* observing_download_manager); | 287 DownloadManager* observing_download_manager); |
278 virtual ~OtherDownloadManagerObserver(); | 288 virtual ~OtherDownloadManagerObserver(); |
279 | 289 |
280 // Observer interface. | 290 // Observer interface. |
281 virtual void ModelChanged(); | 291 virtual void ModelChanged(); |
282 virtual void ManagerGoingDown(); | 292 virtual void ManagerGoingDown(); |
283 | 293 |
284 private: | 294 private: |
285 // The incognito download manager. | 295 // The incognito download manager. |
286 DownloadManager* observing_download_manager_; | 296 DownloadManager* observing_download_manager_; |
287 | 297 |
288 // The original profile's download manager. | 298 // The original profile's download manager. |
289 DownloadManager* observed_download_manager_; | 299 DownloadManager* observed_download_manager_; |
290 }; | 300 }; |
291 | 301 |
292 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; | 302 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; |
293 friend class DeleteTask<DownloadManager>; | 303 friend class DeleteTask<DownloadManager>; |
294 friend class OtherDownloadManagerObserver; | 304 friend class OtherDownloadManagerObserver; |
295 | 305 |
296 virtual ~DownloadManager(); | 306 virtual ~DownloadManager(); |
297 | 307 |
308 DownloadHistory* download_history() const { return download_history_.get(); } | |
Randy Smith (Not in Mondays)
2011/07/27 21:08:35
I don't think this is used anymore; can we remove
achuithb
2011/07/28 00:45:58
It is used in SavePageBrowserTest::QueryDownloadHi
Randy Smith (Not in Mondays)
2011/07/28 21:16:04
Nope, that makes sense. I don't care a lot about
| |
309 | |
298 // Called on the FILE thread to check the existence of a downloaded file. | 310 // Called on the FILE thread to check the existence of a downloaded file. |
299 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 311 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
300 | 312 |
301 // Called on the UI thread if the FILE thread detects the removal of | 313 // 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 | 314 // the downloaded file. The UI thread updates the state of the file |
303 // and then notifies this update to the file's observer. | 315 // and then notifies this update to the file's observer. |
304 void OnFileRemovalDetected(int64 db_handle); | 316 void OnFileRemovalDetected(int64 db_handle); |
305 | 317 |
306 // Called on the download thread to check whether the suggested file path | 318 // 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 | 319 // 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 Loading... | |
343 // yet in the history map. | 355 // yet in the history map. |
344 DownloadItem* GetActiveDownloadItem(int id); | 356 DownloadItem* GetActiveDownloadItem(int id); |
345 | 357 |
346 // Debugging routine to confirm relationship between below | 358 // Debugging routine to confirm relationship between below |
347 // containers; no-op if NDEBUG. | 359 // containers; no-op if NDEBUG. |
348 void AssertContainersConsistent() const; | 360 void AssertContainersConsistent() const; |
349 | 361 |
350 // Add a DownloadItem to history_downloads_. | 362 // Add a DownloadItem to history_downloads_. |
351 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | 363 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); |
352 | 364 |
365 typedef std::vector<DownloadItem*> DownloadVec; | |
Paweł Hajdan Jr.
2011/07/27 16:53:51
nit: Please avoid abbreviations like Vec. Use Vect
Randy Smith (Not in Mondays)
2011/07/27 21:08:35
I don't think we have a typedef for this--before t
achuithb
2011/07/28 00:45:58
I created a public typedef for DownloadVector and
| |
366 int RemoveDownloadItems(const DownloadVec& items); | |
367 | |
353 // |downloads_| is the owning set for all downloads known to the | 368 // |downloads_| is the owning set for all downloads known to the |
354 // DownloadManager. This includes downloads started by the user in | 369 // DownloadManager. This includes downloads started by the user in |
355 // this session, downloads initialized from the history system, and | 370 // this session, downloads initialized from the history system, and |
356 // "save page as" downloads. All other DownloadItem containers in | 371 // "save page as" downloads. All other DownloadItem containers in |
357 // the DownloadManager are maps; they do not own the DownloadItems. | 372 // the DownloadManager are maps; they do not own the DownloadItems. |
358 // Note that this is the only place (with any functional implications; | 373 // Note that this is the only place (with any functional implications; |
359 // see save_page_as_downloads_ below) that "save page as" downloads are | 374 // 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 | 375 // kept, as the DownloadManager's only job is to hold onto those |
361 // until destruction. | 376 // until destruction. |
362 // | 377 // |
(...skipping 23 matching lines...) Expand all Loading... | |
386 // Downloads from past sessions read from a persisted state from the | 401 // Downloads from past sessions read from a persisted state from the |
387 // history system are placed directly into |history_downloads_| since | 402 // history system are placed directly into |history_downloads_| since |
388 // they have valid handles in the history system. | 403 // they have valid handles in the history system. |
389 typedef std::set<DownloadItem*> DownloadSet; | 404 typedef std::set<DownloadItem*> DownloadSet; |
390 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 405 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
391 | 406 |
392 DownloadSet downloads_; | 407 DownloadSet downloads_; |
393 DownloadMap history_downloads_; | 408 DownloadMap history_downloads_; |
394 DownloadMap in_progress_; | 409 DownloadMap in_progress_; |
395 DownloadMap active_downloads_; | 410 DownloadMap active_downloads_; |
396 #if !defined(NDEBUG) | 411 DownloadMap save_page_downloads_; |
397 DownloadSet save_page_as_downloads_; | |
398 #endif | |
399 | 412 |
400 // 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. |
401 bool shutdown_needed_; | 414 bool shutdown_needed_; |
402 | 415 |
403 // 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. |
404 ObserverList<Observer> observers_; | 417 ObserverList<Observer> observers_; |
405 | 418 |
406 // The current active profile. | 419 // The current active profile. |
407 Profile* profile_; | 420 Profile* profile_; |
408 | 421 |
409 scoped_ptr<DownloadHistory> download_history_; | 422 scoped_ptr<DownloadHistory> download_history_; |
410 | 423 |
411 scoped_ptr<DownloadPrefs> download_prefs_; | 424 scoped_ptr<DownloadPrefs> download_prefs_; |
412 | 425 |
413 // Non-owning pointer for handling file writing on the download_thread_. | 426 // Non-owning pointer for handling file writing on the download_thread_. |
414 DownloadFileManager* file_manager_; | 427 DownloadFileManager* file_manager_; |
415 | 428 |
416 // Non-owning pointer for updating the download status. | 429 // Non-owning pointer for updating the download status. |
417 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 430 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
418 | 431 |
419 // 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 |
420 // 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. |
421 FilePath last_download_path_; | 434 FilePath last_download_path_; |
422 | 435 |
436 // Save Page Ids. | |
437 int32 next_save_page_id_; | |
438 | |
423 // 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 |
424 // saved. | 440 // saved. |
425 scoped_refptr<SelectFileDialog> select_file_dialog_; | 441 scoped_refptr<SelectFileDialog> select_file_dialog_; |
426 | 442 |
427 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 443 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
428 | 444 |
429 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 445 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
430 }; | 446 }; |
431 | 447 |
432 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 448 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |