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: content/browser/download/download_item_impl.cc

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // File method ordering: Methods in this file are in the same order as 5 // File method ordering: Methods in this file are in the same order as
6 // in download_item_impl.h, with the following exception: The public 6 // in download_item_impl.h, with the following exception: The public
7 // interface Start is placed in chronological order with the other 7 // interface Start is placed in chronological order with the other
8 // (private) routines that together define a DownloadItem's state 8 // (private) routines that together define a DownloadItem's state
9 // transitions as the download progresses. See "Download progression 9 // transitions as the download progresses. See "Download progression
10 // cascade" later in this file. 10 // cascade" later in this file.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "content/public/browser/download_interrupt_reasons.h" 50 #include "content/public/browser/download_interrupt_reasons.h"
51 #include "content/public/browser/download_url_parameters.h" 51 #include "content/public/browser/download_url_parameters.h"
52 #include "content/public/common/content_switches.h" 52 #include "content/public/common/content_switches.h"
53 #include "content/public/common/referrer.h" 53 #include "content/public/common/referrer.h"
54 #include "net/base/net_util.h" 54 #include "net/base/net_util.h"
55 55
56 namespace content { 56 namespace content {
57 57
58 namespace { 58 namespace {
59 59
60 void DeleteDownloadedFile(const FilePath& path) { 60 void DeleteDownloadedFile(const base::FilePath& path) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
62 62
63 // Make sure we only delete files. 63 // Make sure we only delete files.
64 if (!file_util::DirectoryExists(path)) 64 if (!file_util::DirectoryExists(path))
65 file_util::Delete(path, false); 65 file_util::Delete(path, false);
66 } 66 }
67 67
68 // Classes to null out request handle calls (for SavePage DownloadItems, which 68 // Classes to null out request handle calls (for SavePage DownloadItems, which
69 // may have, e.g., Cancel() called on them without it doing anything) 69 // may have, e.g., Cancel() called on them without it doing anything)
70 // and to DCHECK on them (for history DownloadItems, which should never have 70 // and to DCHECK on them (for history DownloadItems, which should never have
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } // namespace 105 } // namespace
106 106
107 const char DownloadItem::kEmptyFileHash[] = ""; 107 const char DownloadItem::kEmptyFileHash[] = "";
108 108
109 // The maximum number of attempts we will make to resume automatically. 109 // The maximum number of attempts we will make to resume automatically.
110 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5; 110 const int DownloadItemImpl::kMaxAutoResumeAttempts = 5;
111 111
112 // Constructor for reading from the history service. 112 // Constructor for reading from the history service.
113 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 113 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
114 DownloadId download_id, 114 DownloadId download_id,
115 const FilePath& current_path, 115 const base::FilePath& current_path,
116 const FilePath& target_path, 116 const base::FilePath& target_path,
117 const std::vector<GURL>& url_chain, 117 const std::vector<GURL>& url_chain,
118 const GURL& referrer_url, 118 const GURL& referrer_url,
119 const base::Time& start_time, 119 const base::Time& start_time,
120 const base::Time& end_time, 120 const base::Time& end_time,
121 int64 received_bytes, 121 int64 received_bytes,
122 int64 total_bytes, 122 int64 total_bytes,
123 DownloadItem::DownloadState state, 123 DownloadItem::DownloadState state,
124 DownloadDangerType danger_type, 124 DownloadDangerType danger_type,
125 DownloadInterruptReason interrupt_reason, 125 DownloadInterruptReason interrupt_reason,
126 bool opened, 126 bool opened,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, 211 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST,
212 info.request_bound_net_log.source().ToEventParametersCallback()); 212 info.request_bound_net_log.source().ToEventParametersCallback());
213 213
214 info.request_bound_net_log.AddEvent( 214 info.request_bound_net_log.AddEvent(
215 net::NetLog::TYPE_DOWNLOAD_STARTED, 215 net::NetLog::TYPE_DOWNLOAD_STARTED,
216 bound_net_log_.source().ToEventParametersCallback()); 216 bound_net_log_.source().ToEventParametersCallback());
217 } 217 }
218 218
219 // Constructing for the "Save Page As..." feature: 219 // Constructing for the "Save Page As..." feature:
220 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate, 220 DownloadItemImpl::DownloadItemImpl(DownloadItemImplDelegate* delegate,
221 const FilePath& path, 221 const base::FilePath& path,
222 const GURL& url, 222 const GURL& url,
223 DownloadId download_id, 223 DownloadId download_id,
224 const std::string& mime_type, 224 const std::string& mime_type,
225 const net::BoundNetLog& bound_net_log) 225 const net::BoundNetLog& bound_net_log)
226 : is_save_package_download_(true), 226 : is_save_package_download_(true),
227 request_handle_(new NullDownloadRequestHandle()), 227 request_handle_(new NullDownloadRequestHandle()),
228 download_id_(download_id), 228 download_id_(download_id),
229 current_path_(path), 229 current_path_(path),
230 target_path_(path), 230 target_path_(path),
231 target_disposition_(TARGET_DISPOSITION_OVERWRITE), 231 target_disposition_(TARGET_DISPOSITION_OVERWRITE),
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 545 }
546 546
547 const std::string& DownloadItemImpl::GetETag() const { 547 const std::string& DownloadItemImpl::GetETag() const {
548 return etag_; 548 return etag_;
549 } 549 }
550 550
551 bool DownloadItemImpl::IsSavePackageDownload() const { 551 bool DownloadItemImpl::IsSavePackageDownload() const {
552 return is_save_package_download_; 552 return is_save_package_download_;
553 } 553 }
554 554
555 const FilePath& DownloadItemImpl::GetFullPath() const { 555 const base::FilePath& DownloadItemImpl::GetFullPath() const {
556 return current_path_; 556 return current_path_;
557 } 557 }
558 558
559 const FilePath& DownloadItemImpl::GetTargetFilePath() const { 559 const base::FilePath& DownloadItemImpl::GetTargetFilePath() const {
560 return target_path_; 560 return target_path_;
561 } 561 }
562 562
563 const FilePath& DownloadItemImpl::GetForcedFilePath() const { 563 const base::FilePath& DownloadItemImpl::GetForcedFilePath() const {
564 // TODO(asanka): Get rid of GetForcedFilePath(). We should instead just 564 // TODO(asanka): Get rid of GetForcedFilePath(). We should instead just
565 // require that clients respect GetTargetFilePath() if it is already set. 565 // require that clients respect GetTargetFilePath() if it is already set.
566 return forced_file_path_; 566 return forced_file_path_;
567 } 567 }
568 568
569 // TODO(asanka): Get rid of GetUserVerifiedFilePath(). http://crbug.com/134237. 569 // TODO(asanka): Get rid of GetUserVerifiedFilePath(). http://crbug.com/134237.
570 FilePath DownloadItemImpl::GetUserVerifiedFilePath() const { 570 base::FilePath DownloadItemImpl::GetUserVerifiedFilePath() const {
571 return (IsDangerous() || 571 return (IsDangerous() ||
572 danger_type_ == DOWNLOAD_DANGER_TYPE_USER_VALIDATED) ? 572 danger_type_ == DOWNLOAD_DANGER_TYPE_USER_VALIDATED) ?
573 GetFullPath() : GetTargetFilePath(); 573 GetFullPath() : GetTargetFilePath();
574 } 574 }
575 575
576 FilePath DownloadItemImpl::GetFileNameToReportUser() const { 576 base::FilePath DownloadItemImpl::GetFileNameToReportUser() const {
577 if (!display_name_.empty()) 577 if (!display_name_.empty())
578 return display_name_; 578 return display_name_;
579 return target_path_.BaseName(); 579 return target_path_.BaseName();
580 } 580 }
581 581
582 DownloadItem::TargetDisposition DownloadItemImpl::GetTargetDisposition() const { 582 DownloadItem::TargetDisposition DownloadItemImpl::GetTargetDisposition() const {
583 return target_disposition_; 583 return target_disposition_;
584 } 584 }
585 585
586 const std::string& DownloadItemImpl::GetHash() const { 586 const std::string& DownloadItemImpl::GetHash() const {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 720 }
721 721
722 void DownloadItemImpl::SetIsTemporary(bool temporary) { 722 void DownloadItemImpl::SetIsTemporary(bool temporary) {
723 is_temporary_ = temporary; 723 is_temporary_ = temporary;
724 } 724 }
725 725
726 void DownloadItemImpl::SetOpened(bool opened) { 726 void DownloadItemImpl::SetOpened(bool opened) {
727 opened_ = opened; 727 opened_ = opened;
728 } 728 }
729 729
730 void DownloadItemImpl::SetDisplayName(const FilePath& name) { 730 void DownloadItemImpl::SetDisplayName(const base::FilePath& name) {
731 display_name_ = name; 731 display_name_ = name;
732 } 732 }
733 733
734 std::string DownloadItemImpl::DebugString(bool verbose) const { 734 std::string DownloadItemImpl::DebugString(bool verbose) const {
735 std::string description = 735 std::string description =
736 base::StringPrintf("{ id = %d" 736 base::StringPrintf("{ id = %d"
737 " state = %s", 737 " state = %s",
738 download_id_.local(), 738 download_id_.local(),
739 DebugDownloadStateString(state_)); 739 DebugDownloadStateString(state_));
740 740
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 // the download target so we can skip target name determination. 1125 // the download target so we can skip target name determination.
1126 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) { 1126 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) {
1127 delegate_->ShowDownloadInBrowser(this); 1127 delegate_->ShowDownloadInBrowser(this);
1128 MaybeCompleteDownload(); 1128 MaybeCompleteDownload();
1129 return; 1129 return;
1130 } 1130 }
1131 1131
1132 // The target path might be set and the full path empty if we failed 1132 // The target path might be set and the full path empty if we failed
1133 // the intermediate rename--re-do file name determination in this case. 1133 // the intermediate rename--re-do file name determination in this case.
1134 // TODO(rdsmith,asanka): Clean up this logic. 1134 // TODO(rdsmith,asanka): Clean up this logic.
1135 target_path_ = FilePath(); 1135 target_path_ = base::FilePath();
1136 1136
1137 delegate_->DetermineDownloadTarget( 1137 delegate_->DetermineDownloadTarget(
1138 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1138 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1139 weak_ptr_factory_.GetWeakPtr())); 1139 weak_ptr_factory_.GetWeakPtr()));
1140 } 1140 }
1141 1141
1142 // Called by delegate_ when the download target path has been 1142 // Called by delegate_ when the download target path has been
1143 // determined. 1143 // determined.
1144 void DownloadItemImpl::OnDownloadTargetDetermined( 1144 void DownloadItemImpl::OnDownloadTargetDetermined(
1145 const FilePath& target_path, 1145 const base::FilePath& target_path,
1146 TargetDisposition disposition, 1146 TargetDisposition disposition,
1147 DownloadDangerType danger_type, 1147 DownloadDangerType danger_type,
1148 const FilePath& intermediate_path) { 1148 const base::FilePath& intermediate_path) {
1149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1150 1150
1151 // If the |target_path| is empty, then we consider this download to be 1151 // If the |target_path| is empty, then we consider this download to be
1152 // canceled. 1152 // canceled.
1153 if (target_path.empty()) { 1153 if (target_path.empty()) {
1154 Cancel(true); 1154 Cancel(true);
1155 return; 1155 return;
1156 } 1156 }
1157 1157
1158 // TODO(rdsmith,asanka): We are ignoring the possibility that the download 1158 // TODO(rdsmith,asanka): We are ignoring the possibility that the download
(...skipping 30 matching lines...) Expand all
1189 BrowserThread::PostTask( 1189 BrowserThread::PostTask(
1190 BrowserThread::FILE, FROM_HERE, 1190 BrowserThread::FILE, FROM_HERE,
1191 base::Bind(&DownloadFile::RenameAndUniquify, 1191 base::Bind(&DownloadFile::RenameAndUniquify,
1192 // Safe because we control download file lifetime. 1192 // Safe because we control download file lifetime.
1193 base::Unretained(download_file_.get()), 1193 base::Unretained(download_file_.get()),
1194 intermediate_path, callback)); 1194 intermediate_path, callback));
1195 } 1195 }
1196 1196
1197 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( 1197 void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
1198 DownloadInterruptReason reason, 1198 DownloadInterruptReason reason,
1199 const FilePath& full_path) { 1199 const base::FilePath& full_path) {
1200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1201 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 1201 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
1202 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) 1202 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason)
1203 Interrupt(reason); 1203 Interrupt(reason);
1204 else 1204 else
1205 SetFullPath(full_path); 1205 SetFullPath(full_path);
1206 delegate_->ShowDownloadInBrowser(this); 1206 delegate_->ShowDownloadInBrowser(this);
1207 1207
1208 MaybeCompleteDownload(); 1208 MaybeCompleteDownload();
1209 } 1209 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 weak_ptr_factory_.GetWeakPtr()); 1271 weak_ptr_factory_.GetWeakPtr());
1272 BrowserThread::PostTask( 1272 BrowserThread::PostTask(
1273 BrowserThread::FILE, FROM_HERE, 1273 BrowserThread::FILE, FROM_HERE,
1274 base::Bind(&DownloadFile::RenameAndAnnotate, 1274 base::Bind(&DownloadFile::RenameAndAnnotate,
1275 base::Unretained(download_file_.get()), 1275 base::Unretained(download_file_.get()),
1276 GetTargetFilePath(), callback)); 1276 GetTargetFilePath(), callback));
1277 } 1277 }
1278 1278
1279 void DownloadItemImpl::OnDownloadRenamedToFinalName( 1279 void DownloadItemImpl::OnDownloadRenamedToFinalName(
1280 DownloadInterruptReason reason, 1280 DownloadInterruptReason reason,
1281 const FilePath& full_path) { 1281 const base::FilePath& full_path) {
1282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1283 DCHECK(!is_save_package_download_); 1283 DCHECK(!is_save_package_download_);
1284 1284
1285 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which 1285 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which
1286 // will result in deleting the file on the file thread. So we don't 1286 // will result in deleting the file on the file thread. So we don't
1287 // care about the name having been changed. 1287 // care about the name having been changed.
1288 if (state_ != IN_PROGRESS_INTERNAL) 1288 if (state_ != IN_PROGRESS_INTERNAL)
1289 return; 1289 return;
1290 1290
1291 VLOG(20) << __FUNCTION__ << "()" 1291 VLOG(20) << __FUNCTION__ << "()"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 1524
1525 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { 1525 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) {
1526 if (danger_type != danger_type_) { 1526 if (danger_type != danger_type_) {
1527 bound_net_log_.AddEvent( 1527 bound_net_log_.AddEvent(
1528 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 1528 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
1529 base::Bind(&ItemCheckedNetLogCallback, danger_type)); 1529 base::Bind(&ItemCheckedNetLogCallback, danger_type));
1530 } 1530 }
1531 danger_type_ = danger_type; 1531 danger_type_ = danger_type;
1532 } 1532 }
1533 1533
1534 void DownloadItemImpl::SetFullPath(const FilePath& new_path) { 1534 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) {
1535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1535 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1536 VLOG(20) << __FUNCTION__ << "()" 1536 VLOG(20) << __FUNCTION__ << "()"
1537 << " new_path = \"" << new_path.value() << "\"" 1537 << " new_path = \"" << new_path.value() << "\""
1538 << " " << DebugString(true); 1538 << " " << DebugString(true);
1539 DCHECK(!new_path.empty()); 1539 DCHECK(!new_path.empty());
1540 1540
1541 bound_net_log_.AddEvent( 1541 bound_net_log_.AddEvent(
1542 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1542 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
1543 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path)); 1543 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path));
1544 1544
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1630 case RESUME_MODE_USER_CONTINUE: 1630 case RESUME_MODE_USER_CONTINUE:
1631 return "USER_CONTINUE"; 1631 return "USER_CONTINUE";
1632 case RESUME_MODE_USER_RESTART: 1632 case RESUME_MODE_USER_RESTART:
1633 return "USER_RESTART"; 1633 return "USER_RESTART";
1634 } 1634 }
1635 NOTREACHED() << "Unknown resume mode " << mode; 1635 NOTREACHED() << "Unknown resume mode " << mode;
1636 return "unknown"; 1636 return "unknown";
1637 } 1637 }
1638 1638
1639 } // namespace content 1639 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698