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

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 3581008: Fix instances of passing raw pointers to RefCounted objects in tasks. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Merge Created 10 years, 2 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
OLDNEW
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
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 this)); 79 make_scoped_refptr(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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 bool download_finished = ContainsKey(pending_finished_downloads_, 439 bool download_finished = ContainsKey(pending_finished_downloads_,
440 info->download_id); 440 info->download_id);
441 441
442 if (download_finished || info->is_dangerous) { 442 if (download_finished || info->is_dangerous) {
443 // The download has already finished or the download is not safe. 443 // The download has already finished or the download is not safe.
444 // We can now rename the file to its final name (or its tentative name 444 // We can now rename the file to its final name (or its tentative name
445 // in dangerous download cases). 445 // in dangerous download cases).
446 ChromeThread::PostTask( 446 ChromeThread::PostTask(
447 ChromeThread::FILE, FROM_HERE, 447 ChromeThread::FILE, FROM_HERE,
448 NewRunnableMethod( 448 NewRunnableMethod(
449 file_manager_, &DownloadFileManager::OnFinalDownloadName, 449 file_manager_,
450 download->id(), target_path, !info->is_dangerous, this)); 450 &DownloadFileManager::OnFinalDownloadName,
451 download->id(),
452 target_path,
453 !info->is_dangerous,
454 make_scoped_refptr(this)));
451 } else { 455 } else {
452 // The download hasn't finished and it is a safe download. We need to 456 // The download hasn't finished and it is a safe download. We need to
453 // rename it to its intermediate '.crdownload' path. 457 // rename it to its intermediate '.crdownload' path.
454 FilePath download_path = download_util::GetCrDownloadPath(target_path); 458 FilePath download_path = download_util::GetCrDownloadPath(target_path);
455 ChromeThread::PostTask( 459 ChromeThread::PostTask(
456 ChromeThread::FILE, FROM_HERE, 460 ChromeThread::FILE, FROM_HERE,
457 NewRunnableMethod( 461 NewRunnableMethod(
458 file_manager_, &DownloadFileManager::OnIntermediateDownloadName, 462 file_manager_,
459 download->id(), download_path, this)); 463 &DownloadFileManager::OnIntermediateDownloadName,
464 download->id(),
465 download_path,
466 make_scoped_refptr(this)));
460 download->set_need_final_rename(true); 467 download->set_need_final_rename(true);
461 } 468 }
462 469
463 if (download_finished) { 470 if (download_finished) {
464 // If the download already completed by the time we reached this point, then 471 // If the download already completed by the time we reached this point, then
465 // notify observers that it did. 472 // notify observers that it did.
466 OnAllDataSaved(info->download_id, 473 OnAllDataSaved(info->download_id,
467 pending_finished_downloads_[info->download_id]); 474 pending_finished_downloads_[info->download_id]);
468 } 475 }
469 476
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 this, &DownloadManager::ProceedWithFinishedDangerousDownload, 541 this, &DownloadManager::ProceedWithFinishedDangerousDownload,
535 download->db_handle(), 542 download->db_handle(),
536 download->full_path(), download->original_name())); 543 download->full_path(), download->original_name()));
537 return; 544 return;
538 } 545 }
539 546
540 if (download->need_final_rename()) { 547 if (download->need_final_rename()) {
541 ChromeThread::PostTask( 548 ChromeThread::PostTask(
542 ChromeThread::FILE, FROM_HERE, 549 ChromeThread::FILE, FROM_HERE,
543 NewRunnableMethod( 550 NewRunnableMethod(
544 file_manager_, &DownloadFileManager::OnFinalDownloadName, 551 file_manager_,
545 download->id(), download->full_path(), false, this)); 552 &DownloadFileManager::OnFinalDownloadName,
553 download->id(),
554 download->full_path(),
555 false,
556 make_scoped_refptr(this)));
546 return; 557 return;
547 } 558 }
548 559
549 ContinueDownloadFinished(download); 560 ContinueDownloadFinished(download);
550 } 561 }
551 562
552 void DownloadManager::DownloadRenamedToFinalName(int download_id, 563 void DownloadManager::DownloadRenamedToFinalName(int download_id,
553 const FilePath& full_path) { 564 const FilePath& full_path) {
554 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 565 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
555 566
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 observed_download_manager_->RemoveObserver(this); 1034 observed_download_manager_->RemoveObserver(this);
1024 } 1035 }
1025 1036
1026 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1037 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1027 observing_download_manager_->NotifyModelChanged(); 1038 observing_download_manager_->NotifyModelChanged();
1028 } 1039 }
1029 1040
1030 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1041 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1031 observed_download_manager_ = NULL; 1042 observed_download_manager_ = NULL;
1032 } 1043 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file_manager.cc ('k') | chrome/browser/download/save_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698