OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 if (!shutdown_needed_) | 69 if (!shutdown_needed_) |
70 return; | 70 return; |
71 shutdown_needed_ = false; | 71 shutdown_needed_ = false; |
72 | 72 |
73 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); | 73 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); |
74 | 74 |
75 if (file_manager_) { | 75 if (file_manager_) { |
76 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, | 76 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, |
77 NewRunnableMethod(file_manager_, | 77 NewRunnableMethod(file_manager_, |
78 &DownloadFileManager::OnDownloadManagerShutdown, | 78 &DownloadFileManager::OnDownloadManagerShutdown, |
79 make_scoped_refptr(this))); | 79 this)); |
80 } | 80 } |
81 | 81 |
82 // 'in_progress_' may contain DownloadItems that have not finished the start | 82 // 'in_progress_' may contain DownloadItems that have not finished the start |
83 // complete (from the history service) and thus aren't in downloads_. | 83 // complete (from the history service) and thus aren't in downloads_. |
84 DownloadMap::iterator it = in_progress_.begin(); | 84 DownloadMap::iterator it = in_progress_.begin(); |
85 std::set<DownloadItem*> to_remove; | 85 std::set<DownloadItem*> to_remove; |
86 for (; it != in_progress_.end(); ++it) { | 86 for (; it != in_progress_.end(); ++it) { |
87 DownloadItem* download = it->second; | 87 DownloadItem* download = it->second; |
88 if (download->safety_state() == DownloadItem::DANGEROUS) { | 88 if (download->safety_state() == DownloadItem::DANGEROUS) { |
89 // Forget about any download that the user did not approve. | 89 // Forget about any download that the user did not approve. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 bool download_finished = ContainsKey(pending_finished_downloads_, | 430 bool download_finished = ContainsKey(pending_finished_downloads_, |
431 info->download_id); | 431 info->download_id); |
432 | 432 |
433 if (download_finished || info->is_dangerous) { | 433 if (download_finished || info->is_dangerous) { |
434 // The download has already finished or the download is not safe. | 434 // The download has already finished or the download is not safe. |
435 // We can now rename the file to its final name (or its tentative name | 435 // We can now rename the file to its final name (or its tentative name |
436 // in dangerous download cases). | 436 // in dangerous download cases). |
437 ChromeThread::PostTask( | 437 ChromeThread::PostTask( |
438 ChromeThread::FILE, FROM_HERE, | 438 ChromeThread::FILE, FROM_HERE, |
439 NewRunnableMethod( | 439 NewRunnableMethod( |
440 file_manager_, | 440 file_manager_, &DownloadFileManager::OnFinalDownloadName, |
441 &DownloadFileManager::OnFinalDownloadName, | 441 download->id(), target_path, !info->is_dangerous, this)); |
442 download->id(), | |
443 target_path, | |
444 !info->is_dangerous, | |
445 make_scoped_refptr(this))); | |
446 } else { | 442 } else { |
447 // The download hasn't finished and it is a safe download. We need to | 443 // The download hasn't finished and it is a safe download. We need to |
448 // rename it to its intermediate '.crdownload' path. | 444 // rename it to its intermediate '.crdownload' path. |
449 FilePath download_path = download_util::GetCrDownloadPath(target_path); | 445 FilePath download_path = download_util::GetCrDownloadPath(target_path); |
450 ChromeThread::PostTask( | 446 ChromeThread::PostTask( |
451 ChromeThread::FILE, FROM_HERE, | 447 ChromeThread::FILE, FROM_HERE, |
452 NewRunnableMethod( | 448 NewRunnableMethod( |
453 file_manager_, | 449 file_manager_, &DownloadFileManager::OnIntermediateDownloadName, |
454 &DownloadFileManager::OnIntermediateDownloadName, | 450 download->id(), download_path, this)); |
455 download->id(), | |
456 download_path, | |
457 make_scoped_refptr(this))); | |
458 download->set_need_final_rename(true); | 451 download->set_need_final_rename(true); |
459 } | 452 } |
460 | 453 |
461 if (download_finished) { | 454 if (download_finished) { |
462 // If the download already completed by the time we reached this point, then | 455 // If the download already completed by the time we reached this point, then |
463 // notify observers that it did. | 456 // notify observers that it did. |
464 OnAllDataSaved(info->download_id, | 457 OnAllDataSaved(info->download_id, |
465 pending_finished_downloads_[info->download_id]); | 458 pending_finished_downloads_[info->download_id]); |
466 } | 459 } |
467 | 460 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 this, &DownloadManager::ProceedWithFinishedDangerousDownload, | 525 this, &DownloadManager::ProceedWithFinishedDangerousDownload, |
533 download->db_handle(), | 526 download->db_handle(), |
534 download->full_path(), download->original_name())); | 527 download->full_path(), download->original_name())); |
535 return; | 528 return; |
536 } | 529 } |
537 | 530 |
538 if (download->need_final_rename()) { | 531 if (download->need_final_rename()) { |
539 ChromeThread::PostTask( | 532 ChromeThread::PostTask( |
540 ChromeThread::FILE, FROM_HERE, | 533 ChromeThread::FILE, FROM_HERE, |
541 NewRunnableMethod( | 534 NewRunnableMethod( |
542 file_manager_, | 535 file_manager_, &DownloadFileManager::OnFinalDownloadName, |
543 &DownloadFileManager::OnFinalDownloadName, | 536 download->id(), download->full_path(), false, this)); |
544 download->id(), | |
545 download->full_path(), | |
546 false, | |
547 make_scoped_refptr(this))); | |
548 return; | 537 return; |
549 } | 538 } |
550 | 539 |
551 ContinueDownloadFinished(download); | 540 ContinueDownloadFinished(download); |
552 } | 541 } |
553 | 542 |
554 void DownloadManager::DownloadRenamedToFinalName(int download_id, | 543 void DownloadManager::DownloadRenamedToFinalName(int download_id, |
555 const FilePath& full_path) { | 544 const FilePath& full_path) { |
556 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 545 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
557 | 546 |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 observed_download_manager_->RemoveObserver(this); | 1014 observed_download_manager_->RemoveObserver(this); |
1026 } | 1015 } |
1027 | 1016 |
1028 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { | 1017 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { |
1029 observing_download_manager_->NotifyModelChanged(); | 1018 observing_download_manager_->NotifyModelChanged(); |
1030 } | 1019 } |
1031 | 1020 |
1032 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { | 1021 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { |
1033 observed_download_manager_ = NULL; | 1022 observed_download_manager_ = NULL; |
1034 } | 1023 } |
OLD | NEW |