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

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

Issue 3347018: GTTF: Clean up DownloadFileManager (Closed)
Patch Set: shutdowns Created 10 years, 3 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 } // namespace 59 } // namespace
60 60
61 DownloadManager::DownloadManager() 61 DownloadManager::DownloadManager()
62 : shutdown_needed_(false), 62 : shutdown_needed_(false),
63 profile_(NULL), 63 profile_(NULL),
64 file_manager_(NULL) { 64 file_manager_(NULL) {
65 } 65 }
66 66
67 DownloadManager::~DownloadManager() { 67 DownloadManager::~DownloadManager() {
68 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); 68 DCHECK(!shutdown_needed_);
69
70 if (shutdown_needed_)
71 Shutdown();
72 } 69 }
73 70
74 void DownloadManager::Shutdown() { 71 void DownloadManager::Shutdown() {
75 DCHECK(shutdown_needed_) << "Shutdown called when not needed."; 72 if (!shutdown_needed_)
73 return;
74 shutdown_needed_ = false;
76 75
77 // Stop receiving download updates 76 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown());
78 if (file_manager_) 77
79 file_manager_->RemoveDownloadManager(this); 78 if (file_manager_) {
79 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
80 NewRunnableMethod(file_manager_,
81 &DownloadFileManager::OnDownloadManagerShutdown,
82 this));
83 }
80 84
81 // 'in_progress_' may contain DownloadItems that have not finished the start 85 // 'in_progress_' may contain DownloadItems that have not finished the start
82 // complete (from the history service) and thus aren't in downloads_. 86 // complete (from the history service) and thus aren't in downloads_.
83 DownloadMap::iterator it = in_progress_.begin(); 87 DownloadMap::iterator it = in_progress_.begin();
84 std::set<DownloadItem*> to_remove; 88 std::set<DownloadItem*> to_remove;
85 for (; it != in_progress_.end(); ++it) { 89 for (; it != in_progress_.end(); ++it) {
86 DownloadItem* download = it->second; 90 DownloadItem* download = it->second;
87 if (download->safety_state() == DownloadItem::DANGEROUS) { 91 if (download->safety_state() == DownloadItem::DANGEROUS) {
88 // Forget about any download that the user did not approve. 92 // Forget about any download that the user did not approve.
89 // Note that we cannot call download->Remove() this would invalidate our 93 // Note that we cannot call download->Remove() this would invalidate our
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 int render_process_id, 659 int render_process_id,
656 int request_id) { 660 int request_id) {
657 // Cancel the network request. RDH is guaranteed to outlive the IO thread. 661 // Cancel the network request. RDH is guaranteed to outlive the IO thread.
658 ChromeThread::PostTask( 662 ChromeThread::PostTask(
659 ChromeThread::IO, FROM_HERE, 663 ChromeThread::IO, FROM_HERE,
660 NewRunnableFunction(&download_util::CancelDownloadRequest, 664 NewRunnableFunction(&download_util::CancelDownloadRequest,
661 g_browser_process->resource_dispatcher_host(), 665 g_browser_process->resource_dispatcher_host(),
662 render_process_id, 666 render_process_id,
663 request_id)); 667 request_id));
664 668
665 // Tell the file manager to cancel the download.
666 file_manager_->RemoveDownload(download_id, this); // On the UI thread
667 ChromeThread::PostTask( 669 ChromeThread::PostTask(
668 ChromeThread::FILE, FROM_HERE, 670 ChromeThread::FILE, FROM_HERE,
669 NewRunnableMethod( 671 NewRunnableMethod(
670 file_manager_, &DownloadFileManager::CancelDownload, download_id)); 672 file_manager_, &DownloadFileManager::CancelDownload, download_id));
671 } 673 }
672 674
673 void DownloadManager::PauseDownload(int32 download_id, bool pause) { 675 void DownloadManager::PauseDownload(int32 download_id, bool pause) {
674 DownloadMap::iterator it = in_progress_.find(download_id); 676 DownloadMap::iterator it = in_progress_.find(download_id);
675 if (it == in_progress_.end()) 677 if (it == in_progress_.end())
676 return; 678 return;
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 observed_download_manager_->RemoveObserver(this); 1064 observed_download_manager_->RemoveObserver(this);
1063 } 1065 }
1064 1066
1065 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1067 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1066 observing_download_manager_->NotifyModelChanged(); 1068 observing_download_manager_->NotifyModelChanged();
1067 } 1069 }
1068 1070
1069 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1071 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1070 observed_download_manager_ = NULL; 1072 observed_download_manager_ = NULL;
1071 } 1073 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_manager.h ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698