OLD | NEW |
---|---|
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 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1120 // it's not at all clear what to show--we haven't done filename | 1120 // it's not at all clear what to show--we haven't done filename |
1121 // determination, so we don't know what name to display. OTOH, | 1121 // determination, so we don't know what name to display. OTOH, |
1122 // the failure mode of not showing the DI if the file initialization | 1122 // the failure mode of not showing the DI if the file initialization |
1123 // fails isn't a good one. Can we hack up a name based on the | 1123 // fails isn't a good one. Can we hack up a name based on the |
1124 // URLRequest? We'll need to make sure that initialization happens | 1124 // URLRequest? We'll need to make sure that initialization happens |
1125 // properly. Possibly the right thing is to have the UI handle | 1125 // properly. Possibly the right thing is to have the UI handle |
1126 // this case specially. | 1126 // this case specially. |
1127 return; | 1127 return; |
1128 } | 1128 } |
1129 | 1129 |
1130 // If we're resuming an interrupted download, we may already know the download | |
1131 // target so we can skip target name determination. GetFullPath() is non-empty | |
1132 // for interrupted downloads where the intermediate file is still present, and | |
1133 // also for downloads with forced paths. | |
1134 if (!GetTargetFilePath().empty() && !GetFullPath().empty()) { | |
1135 // TODO(rdsmith/asanka): Check to confirm that the target path isn't | |
1136 // present on disk; if it is, we should re-do filename determination to | |
1137 // give the user a chance not to collide. | |
1138 MaybeCompleteDownload(); | |
1139 return; | |
1140 } | |
1141 | |
1142 delegate_->DetermineDownloadTarget( | 1130 delegate_->DetermineDownloadTarget( |
1143 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, | 1131 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, |
1144 weak_ptr_factory_.GetWeakPtr())); | 1132 weak_ptr_factory_.GetWeakPtr())); |
1145 } | 1133 } |
1146 | 1134 |
1147 // Called by delegate_ when the download target path has been | 1135 // Called by delegate_ when the download target path has been |
1148 // determined. | 1136 // determined. |
1149 void DownloadItemImpl::OnDownloadTargetDetermined( | 1137 void DownloadItemImpl::OnDownloadTargetDetermined( |
1150 const base::FilePath& target_path, | 1138 const base::FilePath& target_path, |
1151 TargetDisposition disposition, | 1139 TargetDisposition disposition, |
(...skipping 22 matching lines...) Expand all Loading... | |
1174 target_path_ = target_path; | 1162 target_path_ = target_path; |
1175 target_disposition_ = disposition; | 1163 target_disposition_ = disposition; |
1176 SetDangerType(danger_type); | 1164 SetDangerType(danger_type); |
1177 // TODO(asanka): SetDangerType() doesn't need to send a notification here. | 1165 // TODO(asanka): SetDangerType() doesn't need to send a notification here. |
1178 | 1166 |
1179 // We want the intermediate and target paths to refer to the same directory so | 1167 // We want the intermediate and target paths to refer to the same directory so |
1180 // that they are both on the same device and subject to same | 1168 // that they are both on the same device and subject to same |
1181 // space/permission/availability constraints. | 1169 // space/permission/availability constraints. |
1182 DCHECK(intermediate_path.DirName() == target_path.DirName()); | 1170 DCHECK(intermediate_path.DirName() == target_path.DirName()); |
1183 | 1171 |
1172 // During resumption, we may choose to proceed with the same intermediate | |
1173 // file. No rename is necessary if our intermediate file already has the | |
1174 // correct name. | |
1175 if (intermediate_path == current_path_) { | |
1176 OnDownloadRenamedToIntermediateName(DOWNLOAD_INTERRUPT_REASON_NONE, | |
1177 intermediate_path); | |
1178 return; | |
1179 } | |
1180 | |
Randy Smith (Not in Mondays)
2013/05/15 19:00:18
Why aren't we always using the current_path_ as ou
asanka
2013/05/23 20:30:37
At this point the delegate has requested an interm
Randy Smith (Not in Mondays)
2013/05/24 01:53:55
It just seems a bit weird to have this code here.
asanka
2013/05/29 22:30:11
Can you explain why skipping a rename if the new n
Randy Smith (Not in Mondays)
2013/05/30 21:26:24
Well, no, but I *did* back off from calling it "my
asanka
2013/05/31 19:23:59
Ah. Cool. I added a comment as suggested. I should
| |
1184 // Rename to intermediate name. | 1181 // Rename to intermediate name. |
1185 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a | 1182 // TODO(asanka): Skip this rename if AllDataSaved() is true. This avoids a |
1186 // spurious rename when we can just rename to the final | 1183 // spurious rename when we can just rename to the final |
1187 // filename. Unnecessary renames may cause bugs like | 1184 // filename. Unnecessary renames may cause bugs like |
1188 // http://crbug.com/74187. | 1185 // http://crbug.com/74187. |
1189 DCHECK(!is_save_package_download_); | 1186 DCHECK(!is_save_package_download_); |
1190 DCHECK(download_file_.get()); | 1187 DCHECK(download_file_.get()); |
1191 DownloadFile::RenameCompletionCallback callback = | 1188 DownloadFile::RenameCompletionCallback callback = |
1192 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, | 1189 base::Bind(&DownloadItemImpl::OnDownloadRenamedToIntermediateName, |
1193 weak_ptr_factory_.GetWeakPtr()); | 1190 weak_ptr_factory_.GetWeakPtr()); |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1737 case RESUME_MODE_USER_CONTINUE: | 1734 case RESUME_MODE_USER_CONTINUE: |
1738 return "USER_CONTINUE"; | 1735 return "USER_CONTINUE"; |
1739 case RESUME_MODE_USER_RESTART: | 1736 case RESUME_MODE_USER_RESTART: |
1740 return "USER_RESTART"; | 1737 return "USER_RESTART"; |
1741 } | 1738 } |
1742 NOTREACHED() << "Unknown resume mode " << mode; | 1739 NOTREACHED() << "Unknown resume mode " << mode; |
1743 return "unknown"; | 1740 return "unknown"; |
1744 } | 1741 } |
1745 | 1742 |
1746 } // namespace content | 1743 } // namespace content |
OLD | NEW |