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

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: Address comments Created 7 years, 6 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 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 // it's not at all clear what to show--we haven't done filename 1057 // it's not at all clear what to show--we haven't done filename
1058 // determination, so we don't know what name to display. OTOH, 1058 // determination, so we don't know what name to display. OTOH,
1059 // the failure mode of not showing the DI if the file initialization 1059 // the failure mode of not showing the DI if the file initialization
1060 // fails isn't a good one. Can we hack up a name based on the 1060 // fails isn't a good one. Can we hack up a name based on the
1061 // URLRequest? We'll need to make sure that initialization happens 1061 // URLRequest? We'll need to make sure that initialization happens
1062 // properly. Possibly the right thing is to have the UI handle 1062 // properly. Possibly the right thing is to have the UI handle
1063 // this case specially. 1063 // this case specially.
1064 return; 1064 return;
1065 } 1065 }
1066 1066
1067 // If we're resuming an interrupted download, we may already know the download
1068 // target so we can skip target name determination. GetFullPath() is non-empty
1069 // for interrupted downloads where the intermediate file is still present, and
1070 // also for downloads with forced paths.
1071 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) {
1072 // TODO(rdsmith/asanka): Check to confirm that the target path isn't
1073 // present on disk; if it is, we should re-do filename determination to
1074 // give the user a chance not to collide.
1075 MaybeCompleteDownload();
1076 return;
1077 }
1078
1079 delegate_->DetermineDownloadTarget( 1067 delegate_->DetermineDownloadTarget(
1080 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1068 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1081 weak_ptr_factory_.GetWeakPtr())); 1069 weak_ptr_factory_.GetWeakPtr()));
1082 } 1070 }
1083 1071
1084 // Called by delegate_ when the download target path has been 1072 // Called by delegate_ when the download target path has been
1085 // determined. 1073 // determined.
1086 void DownloadItemImpl::OnDownloadTargetDetermined( 1074 void DownloadItemImpl::OnDownloadTargetDetermined(
1087 const base::FilePath& target_path, 1075 const base::FilePath& target_path,
1088 TargetDisposition disposition, 1076 TargetDisposition disposition,
(...skipping 22 matching lines...) Expand all
1111 target_path_ = target_path; 1099 target_path_ = target_path;
1112 target_disposition_ = disposition; 1100 target_disposition_ = disposition;
1113 SetDangerType(danger_type); 1101 SetDangerType(danger_type);
1114 // TODO(asanka): SetDangerType() doesn't need to send a notification here. 1102 // TODO(asanka): SetDangerType() doesn't need to send a notification here.
1115 1103
1116 // We want the intermediate and target paths to refer to the same directory so 1104 // We want the intermediate and target paths to refer to the same directory so
1117 // that they are both on the same device and subject to same 1105 // that they are both on the same device and subject to same
1118 // space/permission/availability constraints. 1106 // space/permission/availability constraints.
1119 DCHECK(intermediate_path.DirName() == target_path.DirName()); 1107 DCHECK(intermediate_path.DirName() == target_path.DirName());
1120 1108
1109 // During resumption, we may choose to proceed with the same intermediate
1110 // file. No rename is necessary if our intermediate file already has the
1111 // correct name.
1112 //
1113 // The intermediate name may change from its original value during filename
1114 // determination on resumption, for example if the reason for the interruption
1115 // was the download target running out space, resulting in a user prompt.
1116 if (intermediate_path == current_path_) {
1117 OnDownloadRenamedToIntermediateName(DOWNLOAD_INTERRUPT_REASON_NONE,
1118 intermediate_path);
1119 return;
1120 }
1121
1121 // Rename to intermediate name. 1122 // Rename to intermediate name.
1122 // 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
1123 // spurious rename when we can just rename to the final 1124 // spurious rename when we can just rename to the final
1124 // filename. Unnecessary renames may cause bugs like 1125 // filename. Unnecessary renames may cause bugs like
1125 // http://crbug.com/74187. 1126 // http://crbug.com/74187.
1126 DCHECK(!is_save_package_download_); 1127 DCHECK(!is_save_package_download_);
1127 DCHECK(download_file_.get()); 1128 DCHECK(download_file_.get());
1128 DownloadFile::RenameCompletionCallback callback = 1129 DownloadFile::RenameCompletionCallback callback =
1129 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, 1130 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName,
1130 weak_ptr_factory_.GetWeakPtr()); 1131 weak_ptr_factory_.GetWeakPtr());
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 case RESUME_MODE_USER_CONTINUE: 1677 case RESUME_MODE_USER_CONTINUE:
1677 return "USER_CONTINUE"; 1678 return "USER_CONTINUE";
1678 case RESUME_MODE_USER_RESTART: 1679 case RESUME_MODE_USER_RESTART:
1679 return "USER_RESTART"; 1680 return "USER_RESTART";
1680 } 1681 }
1681 NOTREACHED() << "Unknown resume mode " << mode; 1682 NOTREACHED() << "Unknown resume mode " << mode;
1682 return "unknown"; 1683 return "unknown";
1683 } 1684 }
1684 1685
1685 } // namespace content 1686 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner_unittest.cc ('k') | content/public/browser/download_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698