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

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

Issue 5721007: Reland part of r62043 that got reverted. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (!shutdown_needed_) 73 if (!shutdown_needed_)
74 return; 74 return;
75 shutdown_needed_ = false; 75 shutdown_needed_ = false;
76 76
77 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown()); 77 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown());
78 78
79 if (file_manager_) { 79 if (file_manager_) {
80 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 80 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
81 NewRunnableMethod(file_manager_, 81 NewRunnableMethod(file_manager_,
82 &DownloadFileManager::OnDownloadManagerShutdown, 82 &DownloadFileManager::OnDownloadManagerShutdown,
83 this)); 83 make_scoped_refptr(this)));
84 } 84 }
85 85
86 AssertContainersConsistent(); 86 AssertContainersConsistent();
87 87
88 // Go through all downloads in downloads_. Dangerous ones we need to 88 // Go through all downloads in downloads_. Dangerous ones we need to
89 // remove on disk, and in progress ones we need to cancel. 89 // remove on disk, and in progress ones we need to cancel.
90 for (std::set<DownloadItem*>::iterator it = downloads_.begin(); 90 for (std::set<DownloadItem*>::iterator it = downloads_.begin();
91 it != downloads_.end();) { 91 it != downloads_.end();) {
92 DownloadItem* download = *it; 92 DownloadItem* download = *it;
93 93
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 << " info = " << info->DebugString(); 441 << " info = " << info->DebugString();
442 442
443 if (download_finished || info->is_dangerous) { 443 if (download_finished || info->is_dangerous) {
444 // The download has already finished or the download is not safe. 444 // The download has already finished or the download is not safe.
445 // We can now rename the file to its final name (or its tentative name 445 // We can now rename the file to its final name (or its tentative name
446 // in dangerous download cases). 446 // in dangerous download cases).
447 BrowserThread::PostTask( 447 BrowserThread::PostTask(
448 BrowserThread::FILE, FROM_HERE, 448 BrowserThread::FILE, FROM_HERE,
449 NewRunnableMethod( 449 NewRunnableMethod(
450 file_manager_, &DownloadFileManager::OnFinalDownloadName, 450 file_manager_, &DownloadFileManager::OnFinalDownloadName,
451 download->id(), target_path, !info->is_dangerous, this)); 451 download->id(), target_path, !info->is_dangerous,
452 make_scoped_refptr(this)));
452 } else { 453 } else {
453 // The download hasn't finished and it is a safe download. We need to 454 // The download hasn't finished and it is a safe download. We need to
454 // rename it to its intermediate '.crdownload' path. 455 // rename it to its intermediate '.crdownload' path.
455 FilePath download_path = download_util::GetCrDownloadPath(target_path); 456 FilePath download_path = download_util::GetCrDownloadPath(target_path);
456 BrowserThread::PostTask( 457 BrowserThread::PostTask(
457 BrowserThread::FILE, FROM_HERE, 458 BrowserThread::FILE, FROM_HERE,
458 NewRunnableMethod( 459 NewRunnableMethod(
459 file_manager_, &DownloadFileManager::OnIntermediateDownloadName, 460 file_manager_, &DownloadFileManager::OnIntermediateDownloadName,
460 download->id(), download_path, this)); 461 download->id(), download_path, make_scoped_refptr(this)));
461 download->Rename(download_path); 462 download->Rename(download_path);
462 } 463 }
463 464
464 if (download_finished) { 465 if (download_finished) {
465 // If the download already completed by the time we reached this point, then 466 // If the download already completed by the time we reached this point, then
466 // notify observers that it did. 467 // notify observers that it did.
467 OnAllDataSaved(info->download_id, 468 OnAllDataSaved(info->download_id,
468 pending_finished_downloads_[info->download_id]); 469 pending_finished_downloads_[info->download_id]);
469 } 470 }
470 471
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 observed_download_manager_->RemoveObserver(this); 1033 observed_download_manager_->RemoveObserver(this);
1033 } 1034 }
1034 1035
1035 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() { 1036 void DownloadManager::OtherDownloadManagerObserver::ModelChanged() {
1036 observing_download_manager_->NotifyModelChanged(); 1037 observing_download_manager_->NotifyModelChanged();
1037 } 1038 }
1038 1039
1039 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() { 1040 void DownloadManager::OtherDownloadManagerObserver::ManagerGoingDown() {
1040 observed_download_manager_ = NULL; 1041 observed_download_manager_ = NULL;
1041 } 1042 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698