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

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

Issue 3245005: GTTF: Clean up DownloadFileManager (Closed)
Patch Set: fixes 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DownloadManager::~DownloadManager() { 98 DownloadManager::~DownloadManager() {
99 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); 99 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown());
100 100
101 if (shutdown_needed_) 101 if (shutdown_needed_)
102 Shutdown(); 102 Shutdown();
103 } 103 }
104 104
105 void DownloadManager::Shutdown() { 105 void DownloadManager::Shutdown() {
106 DCHECK(shutdown_needed_) << "Shutdown called when not needed."; 106 DCHECK(shutdown_needed_) << "Shutdown called when not needed.";
107 107
108 // Stop receiving download updates 108 if (file_manager_) {
109 if (file_manager_) 109 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE,
110 file_manager_->RemoveDownloadManager(this); 110 NewRunnableMethod(file_manager_,
111 &DownloadFileManager::OnDownloadManagerShutdown,
112 this));
113 }
111 114
112 // 'in_progress_' may contain DownloadItems that have not finished the start 115 // 'in_progress_' may contain DownloadItems that have not finished the start
113 // complete (from the history service) and thus aren't in downloads_. 116 // complete (from the history service) and thus aren't in downloads_.
114 DownloadMap::iterator it = in_progress_.begin(); 117 DownloadMap::iterator it = in_progress_.begin();
115 std::set<DownloadItem*> to_remove; 118 std::set<DownloadItem*> to_remove;
116 for (; it != in_progress_.end(); ++it) { 119 for (; it != in_progress_.end(); ++it) {
117 DownloadItem* download = it->second; 120 DownloadItem* download = it->second;
118 if (download->safety_state() == DownloadItem::DANGEROUS) { 121 if (download->safety_state() == DownloadItem::DANGEROUS) {
119 // Forget about any download that the user did not approve. 122 // Forget about any download that the user did not approve.
120 // Note that we cannot call download->Remove() this would invalidate our 123 // Note that we cannot call download->Remove() this would invalidate our
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 int render_process_id, 718 int render_process_id,
716 int request_id) { 719 int request_id) {
717 // Cancel the network request. RDH is guaranteed to outlive the IO thread. 720 // Cancel the network request. RDH is guaranteed to outlive the IO thread.
718 ChromeThread::PostTask( 721 ChromeThread::PostTask(
719 ChromeThread::IO, FROM_HERE, 722 ChromeThread::IO, FROM_HERE,
720 NewRunnableFunction(&download_util::CancelDownloadRequest, 723 NewRunnableFunction(&download_util::CancelDownloadRequest,
721 g_browser_process->resource_dispatcher_host(), 724 g_browser_process->resource_dispatcher_host(),
722 render_process_id, 725 render_process_id,
723 request_id)); 726 request_id));
724 727
725 // Tell the file manager to cancel the download.
726 file_manager_->RemoveDownload(download_id, this); // On the UI thread
727 ChromeThread::PostTask( 728 ChromeThread::PostTask(
728 ChromeThread::FILE, FROM_HERE, 729 ChromeThread::FILE, FROM_HERE,
729 NewRunnableMethod( 730 NewRunnableMethod(
730 file_manager_, &DownloadFileManager::CancelDownload, download_id)); 731 file_manager_, &DownloadFileManager::CancelDownload, download_id));
731 } 732 }
732 733
733 // DownloadManager is owned by RDH, no need for reference counting. 734 // DownloadManager is owned by RDH, no need for reference counting.
734 DISABLE_RUNNABLE_METHOD_REFCOUNT(ResourceDispatcherHost); 735 DISABLE_RUNNABLE_METHOD_REFCOUNT(ResourceDispatcherHost);
735 736
736 void DownloadManager::PauseDownload(int32 download_id, bool pause) { 737 void DownloadManager::PauseDownload(int32 download_id, bool pause) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 observed_download_manager_->RemoveObserver(this); 1167 observed_download_manager_->RemoveObserver(this);
1167 } 1168 }
1168 1169
1169 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1170 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1170 observing_download_manager_->NotifyModelChanged(); 1171 observing_download_manager_->NotifyModelChanged();
1171 } 1172 }
1172 1173
1173 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1174 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1174 observed_download_manager_ = NULL; 1175 observed_download_manager_ = NULL;
1175 } 1176 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file_manager.cc ('k') | chrome/browser/download/download_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698