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

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 14640020: [Resumption 9/11] Handle filename determination for resumed downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r201622 Created 7 years, 7 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 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 // it's not at all clear what to show--we haven't done filename 1061 // it's not at all clear what to show--we haven't done filename
1062 // determination, so we don't know what name to display. OTOH, 1062 // determination, so we don't know what name to display. OTOH,
1063 // the failure mode of not showing the DI if the file initialization 1063 // the failure mode of not showing the DI if the file initialization
1064 // fails isn't a good one. Can we hack up a name based on the 1064 // fails isn't a good one. Can we hack up a name based on the
1065 // URLRequest? We'll need to make sure that initialization happens 1065 // URLRequest? We'll need to make sure that initialization happens
1066 // properly. Possibly the right thing is to have the UI handle 1066 // properly. Possibly the right thing is to have the UI handle
1067 // this case specially. 1067 // this case specially.
1068 return; 1068 return;
1069 } 1069 }
1070 1070
1071 // If we're resuming an interrupted download, we may already know the download
1072 // target so we can skip target name determination. GetFullPath() is non-empty
1073 // for interrupted downloads where the intermediate file is still present, and
1074 // also for downloads with forced paths.
1075 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) {
1076 // TODO(rdsmith/asanka): Check to confirm that the target path isn't
1077 // present on disk; if it is, we should re-do filename determination to
1078 // give the user a chance not to collide.
1079 MaybeCompleteDownload();
1080 return;
1081 }
1082
1083 delegate_->DetermineDownloadTarget( 1071 delegate_->DetermineDownloadTarget(
1084 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1072 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1085 weak_ptr_factory_.GetWeakPtr())); 1073 weak_ptr_factory_.GetWeakPtr()));
1086 } 1074 }
1087 1075
1088 // Called by delegate_ when the download target path has been 1076 // Called by delegate_ when the download target path has been
1089 // determined. 1077 // determined.
1090 void DownloadItemImpl::OnDownloadTargetDetermined( 1078 void DownloadItemImpl::OnDownloadTargetDetermined(
1091 const base::FilePath& target_path, 1079 const base::FilePath& target_path,
1092 TargetDisposition disposition, 1080 TargetDisposition disposition,
(...skipping 22 matching lines...) Expand all
1115 target_path_ = target_path; 1103 target_path_ = target_path;
1116 target_disposition_ = disposition; 1104 target_disposition_ = disposition;
1117 SetDangerType(danger_type); 1105 SetDangerType(danger_type);
1118 // TODO(asanka): SetDangerType() doesn't need to send a notification here. 1106 // TODO(asanka): SetDangerType() doesn't need to send a notification here.
1119 1107
1120 // We want the intermediate and target paths to refer to the same directory so 1108 // We want the intermediate and target paths to refer to the same directory so
1121 // that they are both on the same device and subject to same 1109 // that they are both on the same device and subject to same
1122 // space/permission/availability constraints. 1110 // space/permission/availability constraints.
1123 DCHECK(intermediate_path.DirName() == target_path.DirName()); 1111 DCHECK(intermediate_path.DirName() == target_path.DirName());
1124 1112
1113 // During resumption, we may choose to proceed with the same intermediate
1114 // file. No rename is necessary if our intermediate file already has the
1115 // correct name.
1116 if (intermediate_path == current_path_) {
1117 OnDownloadRenamedToIntermediateName(DOWNLOAD_INTERRUPT_REASON_NONE,
1118 intermediate_path);
1119 return;
1120 }
1121
1125 // Rename to intermediate name. 1122 // Rename to intermediate name.
1126 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a 1123 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a
1127 // spurious rename when we can just rename to the final 1124 // spurious rename when we can just rename to the final
1128 // filename. Unnecessary renames may cause bugs like 1125 // filename. Unnecessary renames may cause bugs like
1129 // http://crbug.com/74187. 1126 // http://crbug.com/74187.
1130 DCHECK(!is_save_package_download_); 1127 DCHECK(!is_save_package_download_);
1131 DCHECK(download_file_.get()); 1128 DCHECK(download_file_.get());
1132 DownloadFile::RenameCompletionCallback callback = 1129 DownloadFile::RenameCompletionCallback callback =
1133 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, 1130 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
1134 weak_ptr_factory_.GetWeakPtr()); 1131 weak_ptr_factory_.GetWeakPtr());
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 case RESUME_MODE_USER_CONTINUE: 1675 case RESUME_MODE_USER_CONTINUE:
1679 return "USER_CONTINUE"; 1676 return "USER_CONTINUE";
1680 case RESUME_MODE_USER_RESTART: 1677 case RESUME_MODE_USER_RESTART:
1681 return "USER_RESTART"; 1678 return "USER_RESTART";
1682 } 1679 }
1683 NOTREACHED() << "Unknown resume mode " << mode; 1680 NOTREACHED() << "Unknown resume mode " << mode;
1684 return "unknown"; 1681 return "unknown";
1685 } 1682 }
1686 1683
1687 } // namespace content 1684 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698