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

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

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment updates Created 4 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 has_user_gesture_(info.has_user_gesture), 185 has_user_gesture_(info.has_user_gesture),
186 content_disposition_(info.content_disposition), 186 content_disposition_(info.content_disposition),
187 mime_type_(info.mime_type), 187 mime_type_(info.mime_type),
188 original_mime_type_(info.original_mime_type), 188 original_mime_type_(info.original_mime_type),
189 remote_address_(info.remote_address), 189 remote_address_(info.remote_address),
190 total_bytes_(info.total_bytes), 190 total_bytes_(info.total_bytes),
191 received_bytes_(0), 191 received_bytes_(0),
192 bytes_per_sec_(0), 192 bytes_per_sec_(0),
193 last_modified_time_(info.last_modified), 193 last_modified_time_(info.last_modified),
194 etag_(info.etag), 194 etag_(info.etag),
195 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 195 last_reason_(info.result),
196 start_tick_(base::TimeTicks::Now()), 196 start_tick_(base::TimeTicks::Now()),
197 state_(INITIAL_INTERNAL), 197 state_(INITIAL_INTERNAL),
198 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 198 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
199 start_time_(info.start_time), 199 start_time_(info.start_time),
200 delegate_(delegate), 200 delegate_(delegate),
201 is_paused_(false), 201 is_paused_(false),
202 auto_resume_count_(0), 202 auto_resume_count_(0),
203 open_when_complete_(false), 203 open_when_complete_(false),
204 file_externally_removed_(false), 204 file_externally_removed_(false),
205 auto_opened_(false), 205 auto_opened_(false),
206 is_temporary_(!info.save_info->file_path.empty()), 206 is_temporary_(!info.save_info->file_path.empty()),
207 all_data_saved_(false), 207 all_data_saved_(false),
208 destination_error_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 208 destination_error_(DOWNLOAD_INTERRUPT_REASON_NONE),
209 opened_(false), 209 opened_(false),
210 delegate_delayed_complete_(false), 210 delegate_delayed_complete_(false),
211 bound_net_log_(bound_net_log), 211 bound_net_log_(bound_net_log),
212 weak_ptr_factory_(this) { 212 weak_ptr_factory_(this) {
213 delegate_->Attach(); 213 delegate_->Attach();
214 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD); 214 Init(true /* actively downloading */, SRC_ACTIVE_DOWNLOAD);
215 215
216 // Link the event sources. 216 // Link the event sources.
217 bound_net_log_.AddEvent( 217 bound_net_log_.AddEvent(
218 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST, 218 net::NetLog::TYPE_DOWNLOAD_URL_REQUEST,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 288 }
289 289
290 void DownloadItemImpl::RemoveObserver(Observer* observer) { 290 void DownloadItemImpl::RemoveObserver(Observer* observer) {
291 DCHECK_CURRENTLY_ON(BrowserThread::UI); 291 DCHECK_CURRENTLY_ON(BrowserThread::UI);
292 292
293 observers_.RemoveObserver(observer); 293 observers_.RemoveObserver(observer);
294 } 294 }
295 295
296 void DownloadItemImpl::UpdateObservers() { 296 void DownloadItemImpl::UpdateObservers() {
297 DCHECK_CURRENTLY_ON(BrowserThread::UI); 297 DCHECK_CURRENTLY_ON(BrowserThread::UI);
298 DVLOG(20) << __FUNCTION__ << "()";
298 299
299 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 300 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
300 } 301 }
301 302
302 void DownloadItemImpl::ValidateDangerousDownload() { 303 void DownloadItemImpl::ValidateDangerousDownload() {
303 DCHECK_CURRENTLY_ON(BrowserThread::UI); 304 DCHECK_CURRENTLY_ON(BrowserThread::UI);
304 DCHECK(!IsDone()); 305 DCHECK(!IsDone());
305 DCHECK(IsDangerous()); 306 DCHECK(IsDangerous());
306 307
307 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 308 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
308 309
309 if (IsDone() || !IsDangerous()) 310 if (IsDone() || !IsDangerous())
310 return; 311 return;
311 312
312 RecordDangerousDownloadAccept(GetDangerType(), 313 RecordDangerousDownloadAccept(GetDangerType(),
313 GetTargetFilePath()); 314 GetTargetFilePath());
314 315
315 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; 316 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED;
316 317
317 bound_net_log_.AddEvent( 318 bound_net_log_.AddEvent(
318 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 319 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
319 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); 320 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
320 321
321 UpdateObservers(); 322 UpdateObservers(); // TODO(asanka): This is potentially unsafe. The download
323 // may not be in a consistent state or around at all after
324 // invoking observers. http://crbug.com/586610
322 325
323 MaybeCompleteDownload(); 326 MaybeCompleteDownload();
324 } 327 }
325 328
326 void DownloadItemImpl::StealDangerousDownload( 329 void DownloadItemImpl::StealDangerousDownload(
327 const AcquireFileCallback& callback) { 330 const AcquireFileCallback& callback) {
328 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 331 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
329 DCHECK_CURRENTLY_ON(BrowserThread::UI); 332 DCHECK_CURRENTLY_ON(BrowserThread::UI);
330 DCHECK(IsDangerous()); 333 DCHECK(IsDangerous());
331 334
(...skipping 19 matching lines...) Expand all
351 return; 354 return;
352 355
353 switch (state_) { 356 switch (state_) {
354 case INITIAL_INTERNAL: 357 case INITIAL_INTERNAL:
355 case COMPLETING_INTERNAL: 358 case COMPLETING_INTERNAL:
356 case COMPLETE_INTERNAL: 359 case COMPLETE_INTERNAL:
357 case INTERRUPTED_INTERNAL: 360 case INTERRUPTED_INTERNAL:
358 case CANCELLED_INTERNAL: 361 case CANCELLED_INTERNAL:
359 case RESUMING_INTERNAL: 362 case RESUMING_INTERNAL:
360 // No active request. 363 // No active request.
364 // TODO(asanka): In the case of RESUMING_INTERNAL, consider setting
365 // is_paused_ even if there's no request currently associated with this
366 // DII. When a request is assigned (due to a resumption, for example) we
367 // can honor the is_paused_ setting.
361 return; 368 return;
362 369
363 case TARGET_PENDING_INTERNAL: 370 case TARGET_PENDING_INTERNAL:
371 case INTERRUPTED_TARGET_PENDING_INTERNAL:
364 case IN_PROGRESS_INTERNAL: 372 case IN_PROGRESS_INTERNAL:
365 request_handle_->PauseRequest(); 373 request_handle_->PauseRequest();
366 is_paused_ = true; 374 is_paused_ = true;
367 UpdateObservers(); 375 UpdateObservers();
368 return; 376 return;
369 377
370 case MAX_DOWNLOAD_INTERNAL_STATE: 378 case MAX_DOWNLOAD_INTERNAL_STATE:
371 case TARGET_RESOLVED_INTERNAL: 379 case TARGET_RESOLVED_INTERNAL:
372 NOTREACHED(); 380 NOTREACHED();
373 } 381 }
374 } 382 }
375 383
376 void DownloadItemImpl::Resume() { 384 void DownloadItemImpl::Resume() {
377 DCHECK_CURRENTLY_ON(BrowserThread::UI); 385 DCHECK_CURRENTLY_ON(BrowserThread::UI);
386 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
378 switch (state_) { 387 switch (state_) {
379 case INITIAL_INTERNAL: 388 case INITIAL_INTERNAL:
380 case COMPLETING_INTERNAL: 389 case COMPLETING_INTERNAL:
381 case COMPLETE_INTERNAL: 390 case COMPLETE_INTERNAL:
382 case CANCELLED_INTERNAL: 391 case CANCELLED_INTERNAL: // Nothing to resume.
383 // Nothing to resume. 392 case RESUMING_INTERNAL: // Resumption in progress.
384 case RESUMING_INTERNAL:
385 // Resumption in progress.
386 DCHECK(!is_paused_);
387 return; 393 return;
388 394
389 case TARGET_PENDING_INTERNAL: 395 case TARGET_PENDING_INTERNAL:
396 case INTERRUPTED_TARGET_PENDING_INTERNAL:
390 case IN_PROGRESS_INTERNAL: 397 case IN_PROGRESS_INTERNAL:
391 if (!is_paused_) 398 if (!is_paused_)
392 return; 399 return;
393 request_handle_->ResumeRequest(); 400 request_handle_->ResumeRequest();
394 is_paused_ = false; 401 is_paused_ = false;
395 UpdateObservers(); 402 UpdateObservers();
396 return; 403 return;
397 404
398 case INTERRUPTED_INTERNAL: 405 case INTERRUPTED_INTERNAL:
399 auto_resume_count_ = 0; // User input resets the counter. 406 auto_resume_count_ = 0; // User input resets the counter.
400 ResumeInterruptedDownload(); 407 ResumeInterruptedDownload();
408 UpdateObservers();
401 return; 409 return;
402 410
403 case MAX_DOWNLOAD_INTERNAL_STATE: 411 case MAX_DOWNLOAD_INTERNAL_STATE:
404 case TARGET_RESOLVED_INTERNAL: 412 case TARGET_RESOLVED_INTERNAL:
405 NOTREACHED(); 413 NOTREACHED();
406 } 414 }
407 } 415 }
408 416
409 void DownloadItemImpl::Cancel(bool user_cancel) { 417 void DownloadItemImpl::Cancel(bool user_cancel) {
410 DCHECK_CURRENTLY_ON(BrowserThread::UI); 418 DCHECK_CURRENTLY_ON(BrowserThread::UI);
411 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 419 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
412 Interrupt(user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED 420 Interrupt(user_cancel ? DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
413 : DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); 421 : DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
422 UpdateObservers();
414 } 423 }
415 424
416 void DownloadItemImpl::Remove() { 425 void DownloadItemImpl::Remove() {
417 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 426 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
418 DCHECK_CURRENTLY_ON(BrowserThread::UI); 427 DCHECK_CURRENTLY_ON(BrowserThread::UI);
419 428
420 delegate_->AssertStateConsistent(this); 429 delegate_->AssertStateConsistent(this);
421 Interrupt(DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); 430 Interrupt(DOWNLOAD_INTERRUPT_REASON_USER_CANCELED);
431 UpdateObservers();
422 delegate_->AssertStateConsistent(this); 432 delegate_->AssertStateConsistent(this);
423 433
424 NotifyRemoved(); 434 NotifyRemoved();
425 delegate_->DownloadRemoved(this); 435 delegate_->DownloadRemoved(this);
426 // We have now been deleted. 436 // We have now been deleted.
427 } 437 }
428 438
429 void DownloadItemImpl::OpenDownload() { 439 void DownloadItemImpl::OpenDownload() {
430 DCHECK_CURRENTLY_ON(BrowserThread::UI); 440 DCHECK_CURRENTLY_ON(BrowserThread::UI);
431 441
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 488 }
479 489
480 bool DownloadItemImpl::CanResume() const { 490 bool DownloadItemImpl::CanResume() const {
481 DCHECK_CURRENTLY_ON(BrowserThread::UI); 491 DCHECK_CURRENTLY_ON(BrowserThread::UI);
482 switch (state_) { 492 switch (state_) {
483 case INITIAL_INTERNAL: 493 case INITIAL_INTERNAL:
484 case COMPLETING_INTERNAL: 494 case COMPLETING_INTERNAL:
485 case COMPLETE_INTERNAL: 495 case COMPLETE_INTERNAL:
486 case CANCELLED_INTERNAL: 496 case CANCELLED_INTERNAL:
487 case RESUMING_INTERNAL: 497 case RESUMING_INTERNAL:
498 case INTERRUPTED_TARGET_PENDING_INTERNAL:
488 return false; 499 return false;
489 500
490 case TARGET_PENDING_INTERNAL: 501 case TARGET_PENDING_INTERNAL:
491 case TARGET_RESOLVED_INTERNAL: 502 case TARGET_RESOLVED_INTERNAL:
492 case IN_PROGRESS_INTERNAL: 503 case IN_PROGRESS_INTERNAL:
493 return is_paused_; 504 return is_paused_;
494 505
495 case INTERRUPTED_INTERNAL: { 506 case INTERRUPTED_INTERNAL: {
496 ResumeMode resume_mode = GetResumeMode(); 507 ResumeMode resume_mode = GetResumeMode();
497 // Only allow Resume() calls if the resumption mode requires a user 508 // Only allow Resume() calls if the resumption mode requires a user
498 // action. 509 // action.
499 return IsDownloadResumptionEnabled() && 510 return IsDownloadResumptionEnabled() &&
500 (resume_mode == RESUME_MODE_USER_RESTART || 511 (resume_mode == RESUME_MODE_USER_RESTART ||
501 resume_mode == RESUME_MODE_USER_CONTINUE); 512 resume_mode == RESUME_MODE_USER_CONTINUE);
502 } 513 }
503 514
504 case MAX_DOWNLOAD_INTERNAL_STATE: 515 case MAX_DOWNLOAD_INTERNAL_STATE:
505 NOTREACHED(); 516 NOTREACHED();
506 } 517 }
507 return false; 518 return false;
508 } 519 }
509 520
510 bool DownloadItemImpl::IsDone() const { 521 bool DownloadItemImpl::IsDone() const {
511 switch (state_) { 522 switch (state_) {
512 case INITIAL_INTERNAL: 523 case INITIAL_INTERNAL:
513 case COMPLETING_INTERNAL: 524 case COMPLETING_INTERNAL:
514 case RESUMING_INTERNAL: 525 case RESUMING_INTERNAL:
515 case TARGET_PENDING_INTERNAL: 526 case TARGET_PENDING_INTERNAL:
527 case INTERRUPTED_TARGET_PENDING_INTERNAL:
516 case TARGET_RESOLVED_INTERNAL: 528 case TARGET_RESOLVED_INTERNAL:
517 case IN_PROGRESS_INTERNAL: 529 case IN_PROGRESS_INTERNAL:
518 return false; 530 return false;
519 531
520 case COMPLETE_INTERNAL: 532 case COMPLETE_INTERNAL:
521 case CANCELLED_INTERNAL: 533 case CANCELLED_INTERNAL:
522 return true; 534 return true;
523 535
524 case INTERRUPTED_INTERNAL: 536 case INTERRUPTED_INTERNAL:
525 return !CanResume(); 537 return !CanResume();
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED: 942 case DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED:
931 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: 943 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM:
932 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN: 944 case DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN:
933 mode = RESUME_MODE_INVALID; 945 mode = RESUME_MODE_INVALID;
934 break; 946 break;
935 } 947 }
936 948
937 return mode; 949 return mode;
938 } 950 }
939 951
940 void DownloadItemImpl::MergeOriginInfoOnResume( 952 void DownloadItemImpl::UpdateValidatorsOnResumption(
941 const DownloadCreateInfo& new_create_info) { 953 const DownloadCreateInfo& new_create_info) {
942 DCHECK_CURRENTLY_ON(BrowserThread::UI); 954 DCHECK_CURRENTLY_ON(BrowserThread::UI);
943 DCHECK_EQ(RESUMING_INTERNAL, state_); 955 DCHECK_EQ(RESUMING_INTERNAL, state_);
944 DCHECK(!new_create_info.url_chain.empty()); 956 DCHECK(!new_create_info.url_chain.empty());
945 957
946 // We are going to tack on any new redirects to our list of redirects. 958 // We are going to tack on any new redirects to our list of redirects.
947 // When a download is resumed, the URL used for the resumption request is the 959 // When a download is resumed, the URL used for the resumption request is the
948 // one at the end of the previous redirect chain. Tacking additional redirects 960 // one at the end of the previous redirect chain. Tacking additional redirects
949 // to the end of this chain ensures that: 961 // to the end of this chain ensures that:
950 // - If the download needs to be resumed again, the ETag/Last-Modified headers 962 // - If the download needs to be resumed again, the ETag/Last-Modified headers
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 hash_state_ = ""; 1027 hash_state_ = "";
1016 1028
1017 UpdateObservers(); 1029 UpdateObservers();
1018 } 1030 }
1019 1031
1020 void DownloadItemImpl::MarkAsComplete() { 1032 void DownloadItemImpl::MarkAsComplete() {
1021 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1033 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1022 1034
1023 DCHECK(all_data_saved_); 1035 DCHECK(all_data_saved_);
1024 end_time_ = base::Time::Now(); 1036 end_time_ = base::Time::Now();
1025 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); 1037 TransitionTo(COMPLETE_INTERNAL);
1038 UpdateObservers();
1026 } 1039 }
1027 1040
1028 void DownloadItemImpl::DestinationUpdate(int64_t bytes_so_far, 1041 void DownloadItemImpl::DestinationUpdate(int64_t bytes_so_far,
1029 int64_t bytes_per_sec, 1042 int64_t bytes_per_sec,
1030 const std::string& hash_state) { 1043 const std::string& hash_state) {
1031 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1044 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1032 // If the download is in any other state we don't expect any 1045 // If the download is in any other state we don't expect any
1033 // DownloadDestinationObserver callbacks. An interruption or a cancellation 1046 // DownloadDestinationObserver callbacks. An interruption or a cancellation
1034 // results in a call to ReleaseDownloadFile which invalidates the weak 1047 // results in a call to ReleaseDownloadFile which invalidates the weak
1035 // reference held by the DownloadFile and hence cuts off any pending 1048 // reference held by the DownloadFile and hence cuts off any pending
(...skipping 28 matching lines...) Expand all
1064 // results in a call to ReleaseDownloadFile which invalidates the weak 1077 // results in a call to ReleaseDownloadFile which invalidates the weak
1065 // reference held by the DownloadFile and hence cuts off any pending 1078 // reference held by the DownloadFile and hence cuts off any pending
1066 // callbacks. 1079 // callbacks.
1067 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); 1080 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL);
1068 DVLOG(20) << __FUNCTION__ 1081 DVLOG(20) << __FUNCTION__
1069 << "() reason:" << DownloadInterruptReasonToString(reason); 1082 << "() reason:" << DownloadInterruptReasonToString(reason);
1070 1083
1071 // Postpone recognition of this error until after file name determination 1084 // Postpone recognition of this error until after file name determination
1072 // has completed and the intermediate file has been renamed to simplify 1085 // has completed and the intermediate file has been renamed to simplify
1073 // resumption conditions. 1086 // resumption conditions.
1074 if (state_ != IN_PROGRESS_INTERNAL) 1087 if (state_ == TARGET_PENDING_INTERNAL) {
1075 destination_error_ = reason; 1088 destination_error_ = reason;
1076 else 1089 return;
1077 Interrupt(reason); 1090 }
1091 Interrupt(reason);
1092 UpdateObservers();
1078 } 1093 }
1079 1094
1080 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) { 1095 void DownloadItemImpl::DestinationCompleted(const std::string& final_hash) {
1081 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1096 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1082 // If the download is in any other state we don't expect any 1097 // If the download is in any other state we don't expect any
1083 // DownloadDestinationObserver callbacks. An interruption or a cancellation 1098 // DownloadDestinationObserver callbacks. An interruption or a cancellation
1084 // results in a call to ReleaseDownloadFile which invalidates the weak 1099 // results in a call to ReleaseDownloadFile which invalidates the weak
1085 // reference held by the DownloadFile and hence cuts off any pending 1100 // reference held by the DownloadFile and hence cuts off any pending
1086 // callbacks. 1101 // callbacks.
1087 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL); 1102 DCHECK(state_ == TARGET_PENDING_INTERNAL || state_ == IN_PROGRESS_INTERNAL);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 bound_net_log_.AddEvent( 1139 bound_net_log_.AddEvent(
1125 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); 1140 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data);
1126 } 1141 }
1127 1142
1128 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); 1143 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true);
1129 } 1144 }
1130 1145
1131 // We're starting the download. 1146 // We're starting the download.
1132 void DownloadItemImpl::Start( 1147 void DownloadItemImpl::Start(
1133 scoped_ptr<DownloadFile> file, 1148 scoped_ptr<DownloadFile> file,
1134 scoped_ptr<DownloadRequestHandleInterface> req_handle) { 1149 scoped_ptr<DownloadRequestHandleInterface> req_handle,
1150 const DownloadCreateInfo& new_create_info) {
1135 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1151 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1136 DCHECK(!download_file_.get()); 1152 DCHECK(!download_file_.get());
1137 DCHECK(file.get());
1138 DCHECK(req_handle.get());
1139 DVLOG(20) << __FUNCTION__ << "() this=" << DebugString(true); 1153 DVLOG(20) << __FUNCTION__ << "() this=" << DebugString(true);
1140 1154
1141 download_file_ = std::move(file); 1155 download_file_ = std::move(file);
1142 request_handle_ = std::move(req_handle); 1156 request_handle_ = std::move(req_handle);
1143 1157
1144 if (state_ == CANCELLED_INTERNAL) { 1158 if (state_ == CANCELLED_INTERNAL) {
1145 // The download was in the process of resuming when it was cancelled. Don't 1159 // The download was in the process of resuming when it was cancelled. Don't
1146 // proceed. 1160 // proceed.
1147 ReleaseDownloadFile(true); 1161 ReleaseDownloadFile(true);
1148 request_handle_->CancelRequest(); 1162 if (request_handle_)
1163 request_handle_->CancelRequest();
1149 return; 1164 return;
1150 } 1165 }
1151 1166
1152 TransitionTo(TARGET_PENDING_INTERNAL, UPDATE_OBSERVERS); 1167 // The state could be one of the following:
1168 //
1169 // INITIAL_INTERNAL: A normal download attempt.
1170 //
1171 // RESUMING_INTERNAL: A resumption attempt. May or may not have been
1172 // successful.
1173 DCHECK(state_ == INITIAL_INTERNAL || state_ == RESUMING_INTERNAL);
1174
1175 // If a resumption attempted failed, or if the download was DOA, then the
1176 // download should go back to being interrupted.
1177 if (new_create_info.result != DOWNLOAD_INTERRUPT_REASON_NONE) {
1178 DCHECK(!download_file_.get());
1179
1180 // For downloads that are interrupted on initiation, or which don't have a
1181 // target, invoke target determination so that we'll end up with a usable
1182 // filename.
1183 if (state_ == INITIAL_INTERNAL || target_path_.empty()) {
1184 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL);
1185 destination_error_ = new_create_info.result;
1186 DetermineDownloadTarget();
1187 return;
1188 }
1189
1190 // Otherwise, this was a resumption attempt which ended with an
1191 // interruption. Continue with current target path.
1192 TransitionTo(TARGET_RESOLVED_INTERNAL);
1193 Interrupt(new_create_info.result);
1194 UpdateObservers();
1195 return;
1196 }
1197
1198 // Successful download start.
1199 DCHECK(download_file_.get());
1200 DCHECK(request_handle_.get());
1201
1202 if (state_ == RESUMING_INTERNAL)
1203 UpdateValidatorsOnResumption(new_create_info);
1204
1205 TransitionTo(TARGET_PENDING_INTERNAL);
1153 1206
1154 BrowserThread::PostTask( 1207 BrowserThread::PostTask(
1155 BrowserThread::FILE, FROM_HERE, 1208 BrowserThread::FILE, FROM_HERE,
1156 base::Bind(&DownloadFile::Initialize, 1209 base::Bind(&DownloadFile::Initialize,
1157 // Safe because we control download file lifetime. 1210 // Safe because we control download file lifetime.
1158 base::Unretained(download_file_.get()), 1211 base::Unretained(download_file_.get()),
1159 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, 1212 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized,
1160 weak_ptr_factory_.GetWeakPtr()))); 1213 weak_ptr_factory_.GetWeakPtr())));
1161 } 1214 }
1162 1215
1163 void DownloadItemImpl::OnDownloadFileInitialized( 1216 void DownloadItemImpl::OnDownloadFileInitialized(
1164 DownloadInterruptReason result) { 1217 DownloadInterruptReason result) {
1165 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1218 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1166 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL); 1219 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL);
1167 DVLOG(20) << __FUNCTION__ 1220 DVLOG(20) << __FUNCTION__
1168 << "() result:" << DownloadInterruptReasonToString(result); 1221 << "() result:" << DownloadInterruptReasonToString(result);
1169 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { 1222 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) {
1170 // Transition out to TARGET_RESOLVED_INTERNAL since this DownloadItem is 1223 // Whoops. That didn't work. Proceed as an interrupted download.
1171 // skipping the download target determination process. 1224 destination_error_ = result;
1172 TransitionTo(TARGET_RESOLVED_INTERNAL, DONT_UPDATE_OBSERVERS); 1225 TransitionTo(INTERRUPTED_TARGET_PENDING_INTERNAL);
1173 Interrupt(result);
1174 // TODO(rdsmith/asanka): Arguably we should show this in the UI, but
1175 // it's not at all clear what to show--we haven't done filename
1176 // determination, so we don't know what name to display. OTOH,
1177 // the failure mode of not showing the DI if the file initialization
1178 // fails isn't a good one. Can we hack up a name based on the
1179 // URLRequest? We'll need to make sure that initialization happens
1180 // properly. Possibly the right thing is to have the UI handle
1181 // this case specially.
1182 return;
1183 } 1226 }
1184 1227
1228 DetermineDownloadTarget();
1229 }
1230
1231 void DownloadItemImpl::DetermineDownloadTarget() {
1232 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1233 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true);
1234
1185 delegate_->DetermineDownloadTarget( 1235 delegate_->DetermineDownloadTarget(
1186 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1236 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1187 weak_ptr_factory_.GetWeakPtr())); 1237 weak_ptr_factory_.GetWeakPtr()));
1188 } 1238 }
1189 1239
1190 // Called by delegate_ when the download target path has been 1240 // Called by delegate_ when the download target path has been determined.
1191 // determined.
1192 void DownloadItemImpl::OnDownloadTargetDetermined( 1241 void DownloadItemImpl::OnDownloadTargetDetermined(
1193 const base::FilePath& target_path, 1242 const base::FilePath& target_path,
1194 TargetDisposition disposition, 1243 TargetDisposition disposition,
1195 DownloadDangerType danger_type, 1244 DownloadDangerType danger_type,
1196 const base::FilePath& intermediate_path) { 1245 const base::FilePath& intermediate_path) {
1197 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1246 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1198 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL); 1247 DCHECK(state_ == TARGET_PENDING_INTERNAL ||
1248 state_ == INTERRUPTED_TARGET_PENDING_INTERNAL);
1199 1249
1200 // If the |target_path| is empty, then we consider this download to be 1250 // If the |target_path| is empty, then we consider this download to be
1201 // canceled. 1251 // canceled.
1202 if (target_path.empty()) { 1252 if (target_path.empty()) {
1203 Cancel(true); 1253 Cancel(true);
1204 return; 1254 return;
1205 } 1255 }
1206 1256
1207 // TODO(rdsmith,asanka): We are ignoring the possibility that the download 1257 DVLOG(20) << __FUNCTION__ << "() target_path:" << target_path.value()
1208 // has been interrupted at this point until we finish the intermediate 1258 << " disposition:" << disposition << " danger_type:" << danger_type
1209 // rename and set the full path. That's dangerous, because we might race 1259 << " this:" << DebugString(true);
1210 // with resumption, either manual (because the interrupt is visible to the
1211 // UI) or automatic. If we keep the "ignore an error on download until file
1212 // name determination complete" semantics, we need to make sure that the
1213 // error is kept completely invisible until that point.
1214
1215 DVLOG(20) << __FUNCTION__ << " " << target_path.value() << " " << disposition
1216 << " " << danger_type << " " << DebugString(true);
1217 1260
1218 target_path_ = target_path; 1261 target_path_ = target_path;
1219 target_disposition_ = disposition; 1262 target_disposition_ = disposition;
1220 SetDangerType(danger_type); 1263 SetDangerType(danger_type);
1221 1264
1265 // This was an interrupted download that was looking for a filename. Now that
1266 // it has one, transition to interrupted.
1267 if (state_ == INTERRUPTED_TARGET_PENDING_INTERNAL) {
1268 Interrupt(destination_error_);
1269 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
1270 UpdateObservers();
1271 return;
1272 }
1273
1222 // We want the intermediate and target paths to refer to the same directory so 1274 // We want the intermediate and target paths to refer to the same directory so
1223 // that they are both on the same device and subject to same 1275 // that they are both on the same device and subject to same
1224 // space/permission/availability constraints. 1276 // space/permission/availability constraints.
1225 DCHECK(intermediate_path.DirName() == target_path.DirName()); 1277 DCHECK(intermediate_path.DirName() == target_path.DirName());
1226 1278
1227 // During resumption, we may choose to proceed with the same intermediate 1279 // During resumption, we may choose to proceed with the same intermediate
1228 // file. No rename is necessary if our intermediate file already has the 1280 // file. No rename is necessary if our intermediate file already has the
1229 // correct name. 1281 // correct name.
1230 // 1282 //
1231 // The intermediate name may change from its original value during filename 1283 // The intermediate name may change from its original value during filename
(...skipping 22 matching lines...) Expand all
1254 base::Unretained(download_file_.get()), 1306 base::Unretained(download_file_.get()),
1255 intermediate_path, callback)); 1307 intermediate_path, callback));
1256 } 1308 }
1257 1309
1258 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( 1310 void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
1259 DownloadInterruptReason reason, 1311 DownloadInterruptReason reason,
1260 const base::FilePath& full_path) { 1312 const base::FilePath& full_path) {
1261 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1313 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1262 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL); 1314 DCHECK_EQ(state_, TARGET_PENDING_INTERNAL);
1263 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 1315 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
1264 TransitionTo(TARGET_RESOLVED_INTERNAL, DONT_UPDATE_OBSERVERS); 1316 TransitionTo(TARGET_RESOLVED_INTERNAL);
1265 1317
1266 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) { 1318 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) {
1267 // Process destination error. If both |reason| and |destination_error_| 1319 // Process destination error. If both |reason| and |destination_error_|
1268 // refer to actual errors, we want to use the |destination_error_| as the 1320 // refer to actual errors, we want to use the |destination_error_| as the
1269 // argument to the Interrupt() routine, as it happened first. 1321 // argument to the Interrupt() routine, as it happened first.
1270 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) 1322 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE)
1271 SetFullPath(full_path); 1323 SetFullPath(full_path);
1272 Interrupt(destination_error_); 1324 Interrupt(destination_error_);
1273 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; 1325 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
1326 UpdateObservers();
1274 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { 1327 } else if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1275 Interrupt(reason); 1328 Interrupt(reason);
1276 // All file errors result in file deletion above; no need to cleanup. The 1329 // All file errors result in file deletion above; no need to cleanup. The
1277 // current_path_ should be empty. Resuming this download will force a 1330 // current_path_ should be empty. Resuming this download will force a
1278 // restart and a re-doing of filename determination. 1331 // restart and a re-doing of filename determination.
1279 DCHECK(current_path_.empty()); 1332 DCHECK(current_path_.empty());
1333 UpdateObservers();
1280 } else { 1334 } else {
1281 SetFullPath(full_path); 1335 SetFullPath(full_path);
1282 TransitionTo(IN_PROGRESS_INTERNAL, UPDATE_OBSERVERS); 1336 TransitionTo(IN_PROGRESS_INTERNAL);
1337 // TODO(asanka): Calling UpdateObservers() prior to MaybeCompleteDownload()
1338 // is not safe. The download could be in an underminate state after invoking
1339 // observers. http://crbug.com/586610
1340 UpdateObservers();
1283 MaybeCompleteDownload(); 1341 MaybeCompleteDownload();
1284 } 1342 }
1285 } 1343 }
1286 1344
1287 // When SavePackage downloads MHTML to GData (see 1345 // When SavePackage downloads MHTML to GData (see
1288 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it 1346 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it
1289 // does for non-SavePackage downloads, but SavePackage downloads never satisfy 1347 // does for non-SavePackage downloads, but SavePackage downloads never satisfy
1290 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls 1348 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls
1291 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage 1349 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage
1292 // notices that the upload has completed and runs its normal Finish() pathway. 1350 // notices that the upload has completed and runs its normal Finish() pathway.
(...skipping 27 matching lines...) Expand all
1320 return; 1378 return;
1321 1379
1322 DVLOG(20) << __FUNCTION__ << "()" 1380 DVLOG(20) << __FUNCTION__ << "()"
1323 << " " << DebugString(true); 1381 << " " << DebugString(true);
1324 DCHECK(!GetTargetFilePath().empty()); 1382 DCHECK(!GetTargetFilePath().empty());
1325 DCHECK(!IsDangerous()); 1383 DCHECK(!IsDangerous());
1326 1384
1327 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. 1385 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration.
1328 if (is_save_package_download_) { 1386 if (is_save_package_download_) {
1329 // Avoid doing anything on the file thread; there's nothing we control 1387 // Avoid doing anything on the file thread; there's nothing we control
1330 // there. 1388 // there. Strictly speaking, this skips giving the embedder a chance to
1331 // Strictly speaking, this skips giving the embedder a chance to open 1389 // open the download. But on a save package download, there's no real
1332 // the download. But on a save package download, there's no real
1333 // concept of opening. 1390 // concept of opening.
1334 Completed(); 1391 Completed();
1335 return; 1392 return;
1336 } 1393 }
1337 1394
1338 DCHECK(download_file_.get()); 1395 DCHECK(download_file_.get());
1339 // Unilaterally rename; even if it already has the right name, 1396 // Unilaterally rename; even if it already has the right name,
1340 // we need theannotation. 1397 // we need theannotation.
1341 DownloadFile::RenameCompletionCallback callback = 1398 DownloadFile::RenameCompletionCallback callback =
1342 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName, 1399 base::Bind(&DownloadItemImpl::OnDownloadRenamedToFinalName,
(...skipping 20 matching lines...) Expand all
1363 DVLOG(20) << __FUNCTION__ << "()" 1420 DVLOG(20) << __FUNCTION__ << "()"
1364 << " full_path = \"" << full_path.value() << "\"" 1421 << " full_path = \"" << full_path.value() << "\""
1365 << " " << DebugString(false); 1422 << " " << DebugString(false);
1366 1423
1367 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) { 1424 if (DOWNLOAD_INTERRUPT_REASON_NONE != reason) {
1368 Interrupt(reason); 1425 Interrupt(reason);
1369 1426
1370 // All file errors should have resulted in in file deletion above. On 1427 // All file errors should have resulted in in file deletion above. On
1371 // resumption we will need to re-do filename determination. 1428 // resumption we will need to re-do filename determination.
1372 DCHECK(current_path_.empty()); 1429 DCHECK(current_path_.empty());
1430 UpdateObservers();
1373 return; 1431 return;
1374 } 1432 }
1375 1433
1376 DCHECK(target_path_ == full_path); 1434 DCHECK(target_path_ == full_path);
1377 1435
1378 if (full_path != current_path_) { 1436 if (full_path != current_path_) {
1379 // full_path is now the current and target file path. 1437 // full_path is now the current and target file path.
1380 DCHECK(!full_path.empty()); 1438 DCHECK(!full_path.empty());
1381 SetFullPath(full_path); 1439 SetFullPath(full_path);
1382 } 1440 }
1383 1441
1384 // Complete the download and release the DownloadFile. 1442 // Complete the download and release the DownloadFile.
1385 DCHECK(download_file_); 1443 DCHECK(download_file_);
1386 ReleaseDownloadFile(false); 1444 ReleaseDownloadFile(false);
1387 1445
1388 // We're not completely done with the download item yet, but at this 1446 // We're not completely done with the download item yet, but at this
1389 // point we're committed to complete the download. Cancels (or Interrupts, 1447 // point we're committed to complete the download. Cancels (or Interrupts,
1390 // though it's not clear how they could happen) after this point will be 1448 // though it's not clear how they could happen) after this point will be
1391 // ignored. 1449 // ignored.
1392 TransitionTo(COMPLETING_INTERNAL, DONT_UPDATE_OBSERVERS); 1450 TransitionTo(COMPLETING_INTERNAL);
1393 1451
1394 if (delegate_->ShouldOpenDownload( 1452 if (delegate_->ShouldOpenDownload(
1395 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened, 1453 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened,
1396 weak_ptr_factory_.GetWeakPtr()))) { 1454 weak_ptr_factory_.GetWeakPtr()))) {
1397 Completed(); 1455 Completed();
1398 } else { 1456 } else {
1399 delegate_delayed_complete_ = true; 1457 delegate_delayed_complete_ = true;
1400 UpdateObservers(); 1458 UpdateObservers();
1401 } 1459 }
1402 } 1460 }
1403 1461
1404 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { 1462 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) {
1405 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1463 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1406 1464
1407 auto_opened_ = auto_opened; 1465 auto_opened_ = auto_opened;
1408 Completed(); 1466 Completed();
1409 } 1467 }
1410 1468
1411 void DownloadItemImpl::Completed() { 1469 void DownloadItemImpl::Completed() {
1412 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1470 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1413 1471
1414 DVLOG(20) << __FUNCTION__ << "() " << DebugString(false); 1472 DVLOG(20) << __FUNCTION__ << "() " << DebugString(false);
1415 1473
1416 DCHECK(all_data_saved_); 1474 DCHECK(all_data_saved_);
1417 end_time_ = base::Time::Now(); 1475 end_time_ = base::Time::Now();
1418 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); 1476 TransitionTo(COMPLETE_INTERNAL);
1419 RecordDownloadCompleted(start_tick_, received_bytes_); 1477 RecordDownloadCompleted(start_tick_, received_bytes_);
1420 1478
1421 if (auto_opened_) { 1479 if (auto_opened_) {
1422 // If it was already handled by the delegate, do nothing. 1480 // If it was already handled by the delegate, do nothing.
1423 } else if (GetOpenWhenComplete() || 1481 } else if (GetOpenWhenComplete() ||
1424 ShouldOpenFileBasedOnExtension() || 1482 ShouldOpenFileBasedOnExtension() ||
1425 IsTemporary()) { 1483 IsTemporary()) {
1426 // If the download is temporary, like in drag-and-drop, do not open it but 1484 // If the download is temporary, like in drag-and-drop, do not open it but
1427 // we still need to set it auto-opened so that it can be removed from the 1485 // we still need to set it auto-opened so that it can be removed from the
1428 // download shelf. 1486 // download shelf.
1429 if (!IsTemporary()) 1487 if (!IsTemporary())
1430 OpenDownload(); 1488 OpenDownload();
1431 1489
1432 auto_opened_ = true; 1490 auto_opened_ = true;
1433 UpdateObservers();
1434 } 1491 }
1435 } 1492 UpdateObservers();
1436
1437 void DownloadItemImpl::OnResumeRequestStarted(
1438 DownloadItem* item,
1439 DownloadInterruptReason interrupt_reason) {
1440 // If |item| is not NULL, then Start() has been called already, and nothing
1441 // more needs to be done here.
1442 if (item) {
1443 DCHECK_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1444 DCHECK_EQ(static_cast<DownloadItem*>(this), item);
1445 return;
1446 }
1447 // Otherwise, the request failed without passing through
1448 // DownloadResourceHandler::OnResponseStarted.
1449 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1450 Interrupt(interrupt_reason);
1451 } 1493 }
1452 1494
1453 // **** End of Download progression cascade 1495 // **** End of Download progression cascade
1454 1496
1455 // An error occurred somewhere. 1497 // An error occurred somewhere.
1456 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { 1498 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) {
Randy Smith (Not in Mondays) 2016/02/12 21:57:19 nit, suggestion: I couldn't find any place in the
asanka 2016/02/12 23:34:47 Yeah. It seems we can move the UpdateObservers() i
Randy Smith (Not in Mondays) 2016/02/13 00:16:31 SG.
1457 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1499 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1458 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason); 1500 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason);
1459 DVLOG(20) << __FUNCTION__ 1501 DVLOG(20) << __FUNCTION__
1460 << "() reason:" << DownloadInterruptReasonToString(reason) 1502 << "() reason:" << DownloadInterruptReasonToString(reason)
1461 << " this=" << DebugString(true); 1503 << " this=" << DebugString(true);
1462 1504
1463 // Somewhat counter-intuitively, it is possible for us to receive an 1505 // Somewhat counter-intuitively, it is possible for us to receive an
1464 // interrupt after we've already been interrupted. The generation of 1506 // interrupt after we've already been interrupted. The generation of
1465 // interrupts from the file thread Renames and the generation of 1507 // interrupts from the file thread Renames and the generation of
1466 // interrupts from disk writes go through two different mechanisms (driven 1508 // interrupts from disk writes go through two different mechanisms (driven
1467 // by rename requests from UI thread and by write requests from IO thread, 1509 // by rename requests from UI thread and by write requests from IO thread,
1468 // respectively), and since we choose not to keep state on the File thread, 1510 // respectively), and since we choose not to keep state on the File thread,
1469 // this is the place where the races collide. It's also possible for 1511 // this is the place where the races collide. It's also possible for
1470 // interrupts to race with cancels. 1512 // interrupts to race with cancels.
1471 switch (state_) { 1513 switch (state_) {
1472 case CANCELLED_INTERNAL: 1514 case CANCELLED_INTERNAL:
1473 // If the download is already cancelled, then there's no point in 1515 // If the download is already cancelled, then there's no point in
1474 // transitioning out to interrupted. 1516 // transitioning out to interrupted.
1475 case COMPLETING_INTERNAL: 1517 case COMPLETING_INTERNAL:
1476 case COMPLETE_INTERNAL: 1518 case COMPLETE_INTERNAL:
1477 // Already complete. 1519 // Already complete.
1478 return; 1520 return;
1479 1521
1480 case INITIAL_INTERNAL: 1522 case INITIAL_INTERNAL:
1481 case MAX_DOWNLOAD_INTERNAL_STATE: 1523 case MAX_DOWNLOAD_INTERNAL_STATE:
1482 NOTREACHED(); 1524 NOTREACHED();
1483 return; 1525 return;
1484 1526
1527 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1528 case IN_PROGRESS_INTERNAL:
1485 case TARGET_PENDING_INTERNAL: 1529 case TARGET_PENDING_INTERNAL:
1486 case TARGET_RESOLVED_INTERNAL: 1530 case TARGET_RESOLVED_INTERNAL:
1487 case IN_PROGRESS_INTERNAL:
1488 // last_reason_ needs to be set for GetResumeMode() to work. 1531 // last_reason_ needs to be set for GetResumeMode() to work.
1489 last_reason_ = reason; 1532 last_reason_ = reason;
1490 1533
1491 if (download_file_) { 1534 if (download_file_) {
1492 ResumeMode resume_mode = GetResumeMode(); 1535 ResumeMode resume_mode = GetResumeMode();
1493 ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE && 1536 ReleaseDownloadFile(resume_mode != RESUME_MODE_IMMEDIATE_CONTINUE &&
1494 resume_mode != RESUME_MODE_USER_CONTINUE); 1537 resume_mode != RESUME_MODE_USER_CONTINUE);
1495 } 1538 }
1496 break; 1539 break;
1497 1540
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) { 1578 reason == DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN) {
1536 if (IsDangerous()) { 1579 if (IsDangerous()) {
1537 RecordDangerousDownloadDiscard( 1580 RecordDangerousDownloadDiscard(
1538 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED 1581 reason == DOWNLOAD_INTERRUPT_REASON_USER_CANCELED
1539 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION 1582 ? DOWNLOAD_DISCARD_DUE_TO_USER_ACTION
1540 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN, 1583 : DOWNLOAD_DISCARD_DUE_TO_SHUTDOWN,
1541 GetDangerType(), GetTargetFilePath()); 1584 GetDangerType(), GetTargetFilePath());
1542 } 1585 }
1543 1586
1544 RecordDownloadCount(CANCELLED_COUNT); 1587 RecordDownloadCount(CANCELLED_COUNT);
1545 TransitionTo(CANCELLED_INTERNAL, DONT_UPDATE_OBSERVERS); 1588 TransitionTo(CANCELLED_INTERNAL);
1546 } else { 1589 return;
1547 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1548 if (!GetWebContents())
1549 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS);
1550 TransitionTo(INTERRUPTED_INTERNAL, DONT_UPDATE_OBSERVERS);
1551 AutoResumeIfValid();
1552 } 1590 }
1553 1591
1554 UpdateObservers(); 1592 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1593 if (!GetWebContents())
1594 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS);
1595
1596 TransitionTo(INTERRUPTED_INTERNAL);
1597 AutoResumeIfValid();
1555 } 1598 }
1556 1599
1557 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { 1600 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) {
1558 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1601 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1559 DVLOG(20) << __FUNCTION__ << "() destroy_file:" << destroy_file; 1602 DVLOG(20) << __FUNCTION__ << "() destroy_file:" << destroy_file;
1560 1603
1561 if (destroy_file) { 1604 if (destroy_file) {
1562 BrowserThread::PostTask( 1605 BrowserThread::PostTask(
1563 BrowserThread::FILE, FROM_HERE, 1606 BrowserThread::FILE, FROM_HERE,
1564 // Will be deleted at end of task execution. 1607 // Will be deleted at end of task execution.
(...skipping 25 matching lines...) Expand all
1590 // If we don't have all the data, the download is not ready for 1633 // If we don't have all the data, the download is not ready for
1591 // completion. 1634 // completion.
1592 if (!AllDataSaved()) 1635 if (!AllDataSaved())
1593 return false; 1636 return false;
1594 1637
1595 // If the download is dangerous, but not yet validated, it's not ready for 1638 // If the download is dangerous, but not yet validated, it's not ready for
1596 // completion. 1639 // completion.
1597 if (IsDangerous()) 1640 if (IsDangerous())
1598 return false; 1641 return false;
1599 1642
1600 // Invariants for the IN_PROGRESS state. DCHECKs here verify that the 1643 // Check for consistency before invoking delegate. Since there are no pending
1601 // invariants are still true. 1644 // target determination calls and the download is in progress, both the target
1645 // and current paths should be non-empty and they should point to the same
1646 // directory.
1602 DCHECK(!target_path_.empty()); 1647 DCHECK(!target_path_.empty());
1603 DCHECK(!current_path_.empty()); 1648 DCHECK(!current_path_.empty());
1604 DCHECK(target_path_.DirName() == current_path_.DirName()); 1649 DCHECK(target_path_.DirName() == current_path_.DirName());
1605 1650
1606 // Give the delegate a chance to hold up a stop sign. It'll call 1651 // Give the delegate a chance to hold up a stop sign. It'll call
1607 // use back through the passed callback if it does and that state changes. 1652 // use back through the passed callback if it does and that state changes.
1608 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) 1653 if (!delegate_->ShouldCompleteDownload(this, state_change_notification))
1609 return false; 1654 return false;
1610 1655
1611 return true; 1656 return true;
1612 } 1657 }
1613 1658
1614 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, 1659 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state) {
1615 ShouldUpdateObservers notify_action) {
1616 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1660 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1617 1661
1618 if (state_ == new_state) 1662 if (state_ == new_state)
1619 return; 1663 return;
1620 1664
1621 DownloadInternalState old_state = state_; 1665 DownloadInternalState old_state = state_;
1622 state_ = new_state; 1666 state_ = new_state;
1623 1667
1624 DCHECK(is_save_package_download_ 1668 DCHECK(is_save_package_download_
1625 ? IsValidSavePackageStateTransition(old_state, new_state) 1669 ? IsValidSavePackageStateTransition(old_state, new_state)
1626 : IsValidStateTransition(old_state, new_state)) 1670 : IsValidStateTransition(old_state, new_state))
1627 << "Invalid state transition from:" << DebugDownloadStateString(old_state) 1671 << "Invalid state transition from:" << DebugDownloadStateString(old_state)
1628 << " to:" << DebugDownloadStateString(new_state); 1672 << " to:" << DebugDownloadStateString(new_state);
1629 1673
1630 switch (state_) { 1674 switch (state_) {
1631 case INITIAL_INTERNAL: 1675 case INITIAL_INTERNAL:
1632 NOTREACHED(); 1676 NOTREACHED();
1633 break; 1677 break;
1634 1678
1635 case TARGET_PENDING_INTERNAL: 1679 case TARGET_PENDING_INTERNAL:
1636 case TARGET_RESOLVED_INTERNAL: 1680 case TARGET_RESOLVED_INTERNAL:
1681 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1637 break; 1682 break;
1638 1683
1639 case IN_PROGRESS_INTERNAL: 1684 case IN_PROGRESS_INTERNAL:
1640 DCHECK(!current_path_.empty()) << "Current output path must be known."; 1685 DCHECK(!current_path_.empty()) << "Current output path must be known.";
1641 DCHECK(!target_path_.empty()) << "Target path must be known."; 1686 DCHECK(!target_path_.empty()) << "Target path must be known.";
1642 DCHECK(current_path_.DirName() == target_path_.DirName()) 1687 DCHECK(current_path_.DirName() == target_path_.DirName())
1643 << "Current output directory must match target directory."; 1688 << "Current output directory must match target directory.";
1644 DCHECK(download_file_) << "Output file must be owned by download item."; 1689 DCHECK(download_file_) << "Output file must be owned by download item.";
1645 DCHECK(request_handle_) << "Download source must be active."; 1690 DCHECK(request_handle_) << "Download source must be active.";
1646 DCHECK(!is_paused_) << "At the time a download enters IN_PROGRESS state, " 1691 DCHECK(!is_paused_) << "At the time a download enters IN_PROGRESS state, "
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); 1753 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
1709 1754
1710 // Resumption 1755 // Resumption
1711 if (was_done && !is_done) { 1756 if (was_done && !is_done) {
1712 std::string file_name(target_path_.BaseName().AsUTF8Unsafe()); 1757 std::string file_name(target_path_.BaseName().AsUTF8Unsafe());
1713 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, 1758 bound_net_log_.BeginEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE,
1714 base::Bind(&ItemActivatedNetLogCallback, 1759 base::Bind(&ItemActivatedNetLogCallback,
1715 this, SRC_ACTIVE_DOWNLOAD, 1760 this, SRC_ACTIVE_DOWNLOAD,
1716 &file_name)); 1761 &file_name));
1717 } 1762 }
1718
1719 if (notify_action == UPDATE_OBSERVERS)
1720 UpdateObservers();
1721 } 1763 }
1722 1764
1723 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) { 1765 void DownloadItemImpl::SetDangerType(DownloadDangerType danger_type) {
1724 if (danger_type != danger_type_) { 1766 if (danger_type != danger_type_) {
1725 bound_net_log_.AddEvent( 1767 bound_net_log_.AddEvent(
1726 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 1768 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
1727 base::Bind(&ItemCheckedNetLogCallback, danger_type)); 1769 base::Bind(&ItemCheckedNetLogCallback, danger_type));
1728 } 1770 }
1729 // Only record the Malicious UMA stat if it's going from {not malicious} -> 1771 // Only record the Malicious UMA stat if it's going from {not malicious} ->
1730 // {malicious}. 1772 // {malicious}.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 1814
1773 void DownloadItemImpl::ResumeInterruptedDownload() { 1815 void DownloadItemImpl::ResumeInterruptedDownload() {
1774 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1816 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1775 if (!IsDownloadResumptionEnabled()) 1817 if (!IsDownloadResumptionEnabled())
1776 return; 1818 return;
1777 1819
1778 // If we're not interrupted, ignore the request; our caller is drunk. 1820 // If we're not interrupted, ignore the request; our caller is drunk.
1779 if (state_ != INTERRUPTED_INTERNAL) 1821 if (state_ != INTERRUPTED_INTERNAL)
1780 return; 1822 return;
1781 1823
1824 // We are starting a new request. Shake off all pending operations.
1825 DCHECK(!download_file_);
1826 weak_ptr_factory_.InvalidateWeakPtrs();
1827
1782 // Reset the appropriate state if restarting. 1828 // Reset the appropriate state if restarting.
1783 ResumeMode mode = GetResumeMode(); 1829 ResumeMode mode = GetResumeMode();
1784 if (mode == RESUME_MODE_IMMEDIATE_RESTART || 1830 if (mode == RESUME_MODE_IMMEDIATE_RESTART ||
1785 mode == RESUME_MODE_USER_RESTART) { 1831 mode == RESUME_MODE_USER_RESTART) {
1786 received_bytes_ = 0; 1832 received_bytes_ = 0;
1787 hash_state_ = ""; 1833 hash_state_ = "";
1788 last_modified_time_ = ""; 1834 last_modified_time_ = "";
1789 etag_ = ""; 1835 etag_ = "";
1790 } 1836 }
1791 1837
1792 scoped_ptr<DownloadUrlParameters> download_params; 1838 // Avoid using the WebContents even if it's still around. Resumption requests
1793 if (GetWebContents()) { 1839 // are consistently routed through the no-renderer code paths so that the
1794 download_params = 1840 // request will not be dropped if the WebContents (and by extension, the
1795 DownloadUrlParameters::FromWebContents(GetWebContents(), GetURL()); 1841 // associated renderer) goes away before a response is received.
1796 } else { 1842 scoped_ptr<DownloadUrlParameters> download_params(new DownloadUrlParameters(
1797 download_params = make_scoped_ptr(new DownloadUrlParameters( 1843 GetURL(), -1, -1, -1, GetBrowserContext()->GetResourceContext()));
1798 GetURL(), -1, -1, -1, GetBrowserContext()->GetResourceContext()));
1799 }
1800
1801 download_params->set_file_path(GetFullPath()); 1844 download_params->set_file_path(GetFullPath());
1802 download_params->set_offset(GetReceivedBytes()); 1845 download_params->set_offset(GetReceivedBytes());
1803 download_params->set_hash_state(GetHashState()); 1846 download_params->set_hash_state(GetHashState());
1804 download_params->set_last_modified(GetLastModifiedTime()); 1847 download_params->set_last_modified(GetLastModifiedTime());
1805 download_params->set_etag(GetETag()); 1848 download_params->set_etag(GetETag());
1806 download_params->set_callback(
1807 base::Bind(&DownloadItemImpl::OnResumeRequestStarted,
1808 weak_ptr_factory_.GetWeakPtr()));
1809 1849
1810 TransitionTo(RESUMING_INTERNAL, DONT_UPDATE_OBSERVERS); 1850 TransitionTo(RESUMING_INTERNAL);
1811 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId()); 1851 delegate_->ResumeInterruptedDownload(std::move(download_params), GetId());
1812 // Just in case we were interrupted while paused. 1852 // Just in case we were interrupted while paused.
1813 is_paused_ = false; 1853 is_paused_ = false;
1814 } 1854 }
1815 1855
1816 // static 1856 // static
1817 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState( 1857 DownloadItem::DownloadState DownloadItemImpl::InternalToExternalState(
1818 DownloadInternalState internal_state) { 1858 DownloadInternalState internal_state) {
1819 switch (internal_state) { 1859 switch (internal_state) {
1820 case INITIAL_INTERNAL: 1860 case INITIAL_INTERNAL:
1821 case TARGET_PENDING_INTERNAL: 1861 case TARGET_PENDING_INTERNAL:
1822 case TARGET_RESOLVED_INTERNAL: 1862 case TARGET_RESOLVED_INTERNAL:
1863 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1823 // TODO(asanka): Introduce an externally visible state to distinguish 1864 // TODO(asanka): Introduce an externally visible state to distinguish
1824 // between the above states and IN_PROGRESS_INTERNAL. The latter (the 1865 // between the above states and IN_PROGRESS_INTERNAL. The latter (the
1825 // state where the download is active and has a known target) is the state 1866 // state where the download is active and has a known target) is the state
1826 // that most external users are interested in. 1867 // that most external users are interested in.
1827 case IN_PROGRESS_INTERNAL: 1868 case IN_PROGRESS_INTERNAL:
1828 return IN_PROGRESS; 1869 return IN_PROGRESS;
1829 case COMPLETING_INTERNAL: 1870 case COMPLETING_INTERNAL:
1830 return IN_PROGRESS; 1871 return IN_PROGRESS;
1831 case COMPLETE_INTERNAL: 1872 case COMPLETE_INTERNAL:
1832 return COMPLETE; 1873 return COMPLETE;
(...skipping 30 matching lines...) Expand all
1863 } 1904 }
1864 1905
1865 // static 1906 // static
1866 bool DownloadItemImpl::IsValidSavePackageStateTransition( 1907 bool DownloadItemImpl::IsValidSavePackageStateTransition(
1867 DownloadInternalState from, 1908 DownloadInternalState from,
1868 DownloadInternalState to) { 1909 DownloadInternalState to) {
1869 #if DCHECK_IS_ON() 1910 #if DCHECK_IS_ON()
1870 switch (from) { 1911 switch (from) {
1871 case INITIAL_INTERNAL: 1912 case INITIAL_INTERNAL:
1872 case TARGET_PENDING_INTERNAL: 1913 case TARGET_PENDING_INTERNAL:
1914 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1873 case TARGET_RESOLVED_INTERNAL: 1915 case TARGET_RESOLVED_INTERNAL:
1874 case COMPLETING_INTERNAL: 1916 case COMPLETING_INTERNAL:
1875 case COMPLETE_INTERNAL: 1917 case COMPLETE_INTERNAL:
1876 case INTERRUPTED_INTERNAL: 1918 case INTERRUPTED_INTERNAL:
1877 case RESUMING_INTERNAL: 1919 case RESUMING_INTERNAL:
1878 case CANCELLED_INTERNAL: 1920 case CANCELLED_INTERNAL:
1879 return false; 1921 return false;
1880 1922
1881 case IN_PROGRESS_INTERNAL: 1923 case IN_PROGRESS_INTERNAL:
1882 return to == CANCELLED_INTERNAL || to == COMPLETE_INTERNAL; 1924 return to == CANCELLED_INTERNAL || to == COMPLETE_INTERNAL;
1883 1925
1884 case MAX_DOWNLOAD_INTERNAL_STATE: 1926 case MAX_DOWNLOAD_INTERNAL_STATE:
1885 NOTREACHED(); 1927 NOTREACHED();
1886 } 1928 }
1887 return false; 1929 return false;
1888 #else 1930 #else
1889 return true; 1931 return true;
1890 #endif 1932 #endif
1891 } 1933 }
1892 1934
1893 // static 1935 // static
1894 bool DownloadItemImpl::IsValidStateTransition(DownloadInternalState from, 1936 bool DownloadItemImpl::IsValidStateTransition(DownloadInternalState from,
1895 DownloadInternalState to) { 1937 DownloadInternalState to) {
1896 #if DCHECK_IS_ON() 1938 #if DCHECK_IS_ON()
1897 switch (from) { 1939 switch (from) {
1898 case INITIAL_INTERNAL: 1940 case INITIAL_INTERNAL:
1899 return to == TARGET_PENDING_INTERNAL || to == INTERRUPTED_INTERNAL; 1941 return to == TARGET_PENDING_INTERNAL ||
1942 to == INTERRUPTED_TARGET_PENDING_INTERNAL;
1900 1943
1901 case TARGET_PENDING_INTERNAL: 1944 case TARGET_PENDING_INTERNAL:
1902 return to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL; 1945 return to == INTERRUPTED_TARGET_PENDING_INTERNAL ||
1946 to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL;
1947
1948 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1949 return to == INTERRUPTED_INTERNAL || to == CANCELLED_INTERNAL;
1903 1950
1904 case TARGET_RESOLVED_INTERNAL: 1951 case TARGET_RESOLVED_INTERNAL:
1905 return to == IN_PROGRESS_INTERNAL || to == INTERRUPTED_INTERNAL || 1952 return to == IN_PROGRESS_INTERNAL || to == INTERRUPTED_INTERNAL ||
1906 to == CANCELLED_INTERNAL; 1953 to == CANCELLED_INTERNAL;
1907 1954
1908 case IN_PROGRESS_INTERNAL: 1955 case IN_PROGRESS_INTERNAL:
1909 return to == COMPLETING_INTERNAL || to == CANCELLED_INTERNAL || 1956 return to == COMPLETING_INTERNAL || to == CANCELLED_INTERNAL ||
1910 to == INTERRUPTED_INTERNAL; 1957 to == INTERRUPTED_INTERNAL;
1911 1958
1912 case COMPLETING_INTERNAL: 1959 case COMPLETING_INTERNAL:
1913 return to == COMPLETE_INTERNAL; 1960 return to == COMPLETE_INTERNAL;
1914 1961
1915 case COMPLETE_INTERNAL: 1962 case COMPLETE_INTERNAL:
1916 return false; 1963 return false;
1917 1964
1918 case INTERRUPTED_INTERNAL: 1965 case INTERRUPTED_INTERNAL:
1919 return to == RESUMING_INTERNAL || to == CANCELLED_INTERNAL; 1966 return to == RESUMING_INTERNAL || to == CANCELLED_INTERNAL;
1920 1967
1921 case RESUMING_INTERNAL: 1968 case RESUMING_INTERNAL:
1922 return to == TARGET_PENDING_INTERNAL || to == CANCELLED_INTERNAL; 1969 return to == TARGET_PENDING_INTERNAL ||
1970 to == INTERRUPTED_TARGET_PENDING_INTERNAL ||
1971 to == TARGET_RESOLVED_INTERNAL || to == CANCELLED_INTERNAL;
1923 1972
1924 case CANCELLED_INTERNAL: 1973 case CANCELLED_INTERNAL:
1925 return false; 1974 return false;
1926 1975
1927 case MAX_DOWNLOAD_INTERNAL_STATE: 1976 case MAX_DOWNLOAD_INTERNAL_STATE:
1928 NOTREACHED(); 1977 NOTREACHED();
1929 } 1978 }
1930 return false; 1979 return false;
1931 #else 1980 #else
1932 return true; 1981 return true;
1933 #endif // DCHECK_IS_ON() 1982 #endif // DCHECK_IS_ON()
1934 } 1983 }
1935 1984
1936 const char* DownloadItemImpl::DebugDownloadStateString( 1985 const char* DownloadItemImpl::DebugDownloadStateString(
1937 DownloadInternalState state) { 1986 DownloadInternalState state) {
1938 switch (state) { 1987 switch (state) {
1939 case INITIAL_INTERNAL: 1988 case INITIAL_INTERNAL:
1940 return "INITIAL"; 1989 return "INITIAL";
1941 case TARGET_PENDING_INTERNAL: 1990 case TARGET_PENDING_INTERNAL:
1942 return "TARGET_PENDING"; 1991 return "TARGET_PENDING";
1992 case INTERRUPTED_TARGET_PENDING_INTERNAL:
1993 return "INTERRUPTED_TARGET_PENDING";
1943 case TARGET_RESOLVED_INTERNAL: 1994 case TARGET_RESOLVED_INTERNAL:
1944 return "TARGET_RESOLVED"; 1995 return "TARGET_RESOLVED";
1945 case IN_PROGRESS_INTERNAL: 1996 case IN_PROGRESS_INTERNAL:
1946 return "IN_PROGRESS"; 1997 return "IN_PROGRESS";
1947 case COMPLETING_INTERNAL: 1998 case COMPLETING_INTERNAL:
1948 return "COMPLETING"; 1999 return "COMPLETING";
1949 case COMPLETE_INTERNAL: 2000 case COMPLETE_INTERNAL:
1950 return "COMPLETE"; 2001 return "COMPLETE";
1951 case CANCELLED_INTERNAL: 2002 case CANCELLED_INTERNAL:
1952 return "CANCELLED"; 2003 return "CANCELLED";
(...skipping 19 matching lines...) Expand all
1972 case RESUME_MODE_USER_CONTINUE: 2023 case RESUME_MODE_USER_CONTINUE:
1973 return "USER_CONTINUE"; 2024 return "USER_CONTINUE";
1974 case RESUME_MODE_USER_RESTART: 2025 case RESUME_MODE_USER_RESTART:
1975 return "USER_RESTART"; 2026 return "USER_RESTART";
1976 } 2027 }
1977 NOTREACHED() << "Unknown resume mode " << mode; 2028 NOTREACHED() << "Unknown resume mode " << mode;
1978 return "unknown"; 2029 return "unknown";
1979 } 2030 }
1980 2031
1981 } // namespace content 2032 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698