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

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

Issue 1008613002: favor DCHECK_CURRENTLY_ON for better logs in content/browser/[a-d]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool DeleteDownloadedFile(const base::FilePath& path) { 60 bool DeleteDownloadedFile(const base::FilePath& path) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 61 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
62 62
63 // Make sure we only delete files. 63 // Make sure we only delete files.
64 if (base::DirectoryExists(path)) 64 if (base::DirectoryExists(path))
65 return true; 65 return true;
66 return base::DeleteFile(path, false); 66 return base::DeleteFile(path, false);
67 } 67 }
68 68
69 void DeleteDownloadedFileDone( 69 void DeleteDownloadedFileDone(
70 base::WeakPtr<DownloadItemImpl> item, 70 base::WeakPtr<DownloadItemImpl> item,
71 const base::Callback<void(bool)>& callback, 71 const base::Callback<void(bool)>& callback,
72 bool success) { 72 bool success) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 73 DCHECK_CURRENTLY_ON(BrowserThread::UI);
74 if (success && item.get()) 74 if (success && item.get())
75 item->OnDownloadedFileRemoved(); 75 item->OnDownloadedFileRemoved();
76 callback.Run(success); 76 callback.Run(success);
77 } 77 }
78 78
79 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that 79 // Wrapper around DownloadFile::Detach and DownloadFile::Cancel that
80 // takes ownership of the DownloadFile and hence implicitly destroys it 80 // takes ownership of the DownloadFile and hence implicitly destroys it
81 // at the end of the function. 81 // at the end of the function.
82 static base::FilePath DownloadFileDetach( 82 static base::FilePath DownloadFileDetach(
83 scoped_ptr<DownloadFile> download_file) { 83 scoped_ptr<DownloadFile> download_file) {
84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 84 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
85 base::FilePath full_path = download_file->FullPath(); 85 base::FilePath full_path = download_file->FullPath();
86 download_file->Detach(); 86 download_file->Detach();
87 return full_path; 87 return full_path;
88 } 88 }
89 89
90 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) { 90 static void DownloadFileCancel(scoped_ptr<DownloadFile> download_file) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 91 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
92 download_file->Cancel(); 92 download_file->Cancel();
93 } 93 }
94 94
95 bool IsDownloadResumptionEnabled() { 95 bool IsDownloadResumptionEnabled() {
96 return base::CommandLine::ForCurrentProcess()->HasSwitch( 96 return base::CommandLine::ForCurrentProcess()->HasSwitch(
97 switches::kEnableDownloadResumption); 97 switches::kEnableDownloadResumption);
98 } 98 }
99 99
100 } // namespace 100 } // namespace
101 101
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 destination_error_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 265 destination_error_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
266 opened_(false), 266 opened_(false),
267 delegate_delayed_complete_(false), 267 delegate_delayed_complete_(false),
268 bound_net_log_(bound_net_log), 268 bound_net_log_(bound_net_log),
269 weak_ptr_factory_(this) { 269 weak_ptr_factory_(this) {
270 delegate_->Attach(); 270 delegate_->Attach();
271 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS); 271 Init(true /* actively downloading */, SRC_SAVE_PAGE_AS);
272 } 272 }
273 273
274 DownloadItemImpl::~DownloadItemImpl() { 274 DownloadItemImpl::~DownloadItemImpl() {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 275 DCHECK_CURRENTLY_ON(BrowserThread::UI);
276 276
277 // Should always have been nuked before now, at worst in 277 // Should always have been nuked before now, at worst in
278 // DownloadManager shutdown. 278 // DownloadManager shutdown.
279 DCHECK(!download_file_.get()); 279 DCHECK(!download_file_.get());
280 280
281 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this)); 281 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this));
282 delegate_->AssertStateConsistent(this); 282 delegate_->AssertStateConsistent(this);
283 delegate_->Detach(); 283 delegate_->Detach();
284 } 284 }
285 285
286 void DownloadItemImpl::AddObserver(Observer* observer) { 286 void DownloadItemImpl::AddObserver(Observer* observer) {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK_CURRENTLY_ON(BrowserThread::UI);
288 288
289 observers_.AddObserver(observer); 289 observers_.AddObserver(observer);
290 } 290 }
291 291
292 void DownloadItemImpl::RemoveObserver(Observer* observer) { 292 void DownloadItemImpl::RemoveObserver(Observer* observer) {
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 293 DCHECK_CURRENTLY_ON(BrowserThread::UI);
294 294
295 observers_.RemoveObserver(observer); 295 observers_.RemoveObserver(observer);
296 } 296 }
297 297
298 void DownloadItemImpl::UpdateObservers() { 298 void DownloadItemImpl::UpdateObservers() {
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 299 DCHECK_CURRENTLY_ON(BrowserThread::UI);
300 300
301 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this)); 301 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
302 } 302 }
303 303
304 void DownloadItemImpl::ValidateDangerousDownload() { 304 void DownloadItemImpl::ValidateDangerousDownload() {
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 DCHECK_CURRENTLY_ON(BrowserThread::UI);
306 DCHECK(!IsDone()); 306 DCHECK(!IsDone());
307 DCHECK(IsDangerous()); 307 DCHECK(IsDangerous());
308 308
309 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 309 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
310 310
311 if (IsDone() || !IsDangerous()) 311 if (IsDone() || !IsDangerous())
312 return; 312 return;
313 313
314 RecordDangerousDownloadAccept(GetDangerType(), 314 RecordDangerousDownloadAccept(GetDangerType(),
315 GetTargetFilePath()); 315 GetTargetFilePath());
316 316
317 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED; 317 danger_type_ = DOWNLOAD_DANGER_TYPE_USER_VALIDATED;
318 318
319 bound_net_log_.AddEvent( 319 bound_net_log_.AddEvent(
320 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED, 320 net::NetLog::TYPE_DOWNLOAD_ITEM_SAFETY_STATE_UPDATED,
321 base::Bind(&ItemCheckedNetLogCallback, GetDangerType())); 321 base::Bind(&ItemCheckedNetLogCallback, GetDangerType()));
322 322
323 UpdateObservers(); 323 UpdateObservers();
324 324
325 MaybeCompleteDownload(); 325 MaybeCompleteDownload();
326 } 326 }
327 327
328 void DownloadItemImpl::StealDangerousDownload( 328 void DownloadItemImpl::StealDangerousDownload(
329 const AcquireFileCallback& callback) { 329 const AcquireFileCallback& callback) {
330 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 330 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK_CURRENTLY_ON(BrowserThread::UI);
332 DCHECK(IsDangerous()); 332 DCHECK(IsDangerous());
333 if (download_file_) { 333 if (download_file_) {
334 BrowserThread::PostTaskAndReplyWithResult( 334 BrowserThread::PostTaskAndReplyWithResult(
335 BrowserThread::FILE, 335 BrowserThread::FILE,
336 FROM_HERE, 336 FROM_HERE,
337 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)), 337 base::Bind(&DownloadFileDetach, base::Passed(&download_file_)),
338 callback); 338 callback);
339 } else { 339 } else {
340 callback.Run(current_path_); 340 callback.Run(current_path_);
341 } 341 }
342 current_path_.clear(); 342 current_path_.clear();
343 Remove(); 343 Remove();
344 // We have now been deleted. 344 // We have now been deleted.
345 } 345 }
346 346
347 void DownloadItemImpl::Pause() { 347 void DownloadItemImpl::Pause() {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 348 DCHECK_CURRENTLY_ON(BrowserThread::UI);
349 349
350 // Ignore irrelevant states. 350 // Ignore irrelevant states.
351 if (state_ != IN_PROGRESS_INTERNAL || is_paused_) 351 if (state_ != IN_PROGRESS_INTERNAL || is_paused_)
352 return; 352 return;
353 353
354 request_handle_->PauseRequest(); 354 request_handle_->PauseRequest();
355 is_paused_ = true; 355 is_paused_ = true;
356 UpdateObservers(); 356 UpdateObservers();
357 } 357 }
358 358
359 void DownloadItemImpl::Resume() { 359 void DownloadItemImpl::Resume() {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 360 DCHECK_CURRENTLY_ON(BrowserThread::UI);
361 switch (state_) { 361 switch (state_) {
362 case IN_PROGRESS_INTERNAL: 362 case IN_PROGRESS_INTERNAL:
363 if (!is_paused_) 363 if (!is_paused_)
364 return; 364 return;
365 request_handle_->ResumeRequest(); 365 request_handle_->ResumeRequest();
366 is_paused_ = false; 366 is_paused_ = false;
367 UpdateObservers(); 367 UpdateObservers();
368 return; 368 return;
369 369
370 case COMPLETING_INTERNAL: 370 case COMPLETING_INTERNAL:
371 case COMPLETE_INTERNAL: 371 case COMPLETE_INTERNAL:
372 case CANCELLED_INTERNAL: 372 case CANCELLED_INTERNAL:
373 case RESUMING_INTERNAL: 373 case RESUMING_INTERNAL:
374 return; 374 return;
375 375
376 case INTERRUPTED_INTERNAL: 376 case INTERRUPTED_INTERNAL:
377 auto_resume_count_ = 0; // User input resets the counter. 377 auto_resume_count_ = 0; // User input resets the counter.
378 ResumeInterruptedDownload(); 378 ResumeInterruptedDownload();
379 return; 379 return;
380 380
381 case MAX_DOWNLOAD_INTERNAL_STATE: 381 case MAX_DOWNLOAD_INTERNAL_STATE:
382 NOTREACHED(); 382 NOTREACHED();
383 } 383 }
384 } 384 }
385 385
386 void DownloadItemImpl::Cancel(bool user_cancel) { 386 void DownloadItemImpl::Cancel(bool user_cancel) {
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 387 DCHECK_CURRENTLY_ON(BrowserThread::UI);
388 388
389 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 389 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
390 if (state_ != IN_PROGRESS_INTERNAL && 390 if (state_ != IN_PROGRESS_INTERNAL &&
391 state_ != INTERRUPTED_INTERNAL && 391 state_ != INTERRUPTED_INTERNAL &&
392 state_ != RESUMING_INTERNAL) { 392 state_ != RESUMING_INTERNAL) {
393 // Small downloads might be complete before this method has a chance to run. 393 // Small downloads might be complete before this method has a chance to run.
394 return; 394 return;
395 } 395 }
396 396
397 if (IsDangerous()) { 397 if (IsDangerous()) {
(...skipping 30 matching lines...) Expand all
428 BrowserThread::FILE, FROM_HERE, 428 BrowserThread::FILE, FROM_HERE,
429 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_)); 429 base::Bind(base::IgnoreResult(&DeleteDownloadedFile), current_path_));
430 current_path_.clear(); 430 current_path_.clear();
431 } 431 }
432 432
433 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS); 433 TransitionTo(CANCELLED_INTERNAL, UPDATE_OBSERVERS);
434 } 434 }
435 435
436 void DownloadItemImpl::Remove() { 436 void DownloadItemImpl::Remove() {
437 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true); 437 DVLOG(20) << __FUNCTION__ << "() download = " << DebugString(true);
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 438 DCHECK_CURRENTLY_ON(BrowserThread::UI);
439 439
440 delegate_->AssertStateConsistent(this); 440 delegate_->AssertStateConsistent(this);
441 Cancel(true); 441 Cancel(true);
442 delegate_->AssertStateConsistent(this); 442 delegate_->AssertStateConsistent(this);
443 443
444 NotifyRemoved(); 444 NotifyRemoved();
445 delegate_->DownloadRemoved(this); 445 delegate_->DownloadRemoved(this);
446 // We have now been deleted. 446 // We have now been deleted.
447 } 447 }
448 448
449 void DownloadItemImpl::OpenDownload() { 449 void DownloadItemImpl::OpenDownload() {
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 450 DCHECK_CURRENTLY_ON(BrowserThread::UI);
451 451
452 if (!IsDone()) { 452 if (!IsDone()) {
453 // We don't honor the open_when_complete_ flag for temporary 453 // We don't honor the open_when_complete_ flag for temporary
454 // downloads. Don't set it because it shows up in the UI. 454 // downloads. Don't set it because it shows up in the UI.
455 if (!IsTemporary()) 455 if (!IsTemporary())
456 open_when_complete_ = !open_when_complete_; 456 open_when_complete_ = !open_when_complete_;
457 return; 457 return;
458 } 458 }
459 459
460 if (state_ != COMPLETE_INTERNAL || file_externally_removed_) 460 if (state_ != COMPLETE_INTERNAL || file_externally_removed_)
461 return; 461 return;
462 462
463 // Ideally, we want to detect errors in opening and report them, but we 463 // Ideally, we want to detect errors in opening and report them, but we
464 // don't generally have the proper interface for that to the external 464 // don't generally have the proper interface for that to the external
465 // program that opens the file. So instead we spawn a check to update 465 // program that opens the file. So instead we spawn a check to update
466 // the UI if the file has been deleted in parallel with the open. 466 // the UI if the file has been deleted in parallel with the open.
467 delegate_->CheckForFileRemoval(this); 467 delegate_->CheckForFileRemoval(this);
468 RecordOpen(GetEndTime(), !GetOpened()); 468 RecordOpen(GetEndTime(), !GetOpened());
469 opened_ = true; 469 opened_ = true;
470 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this)); 470 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
471 delegate_->OpenDownload(this); 471 delegate_->OpenDownload(this);
472 } 472 }
473 473
474 void DownloadItemImpl::ShowDownloadInShell() { 474 void DownloadItemImpl::ShowDownloadInShell() {
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 475 DCHECK_CURRENTLY_ON(BrowserThread::UI);
476 476
477 delegate_->ShowDownloadInShell(this); 477 delegate_->ShowDownloadInShell(this);
478 } 478 }
479 479
480 uint32 DownloadItemImpl::GetId() const { 480 uint32 DownloadItemImpl::GetId() const {
481 return download_id_; 481 return download_id_;
482 } 482 }
483 483
484 DownloadItem::DownloadState DownloadItemImpl::GetState() const { 484 DownloadItem::DownloadState DownloadItemImpl::GetState() const {
485 return InternalToExternalState(state_); 485 return InternalToExternalState(state_);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 634
635 const std::string& DownloadItemImpl::GetHashState() const { 635 const std::string& DownloadItemImpl::GetHashState() const {
636 return hash_state_; 636 return hash_state_;
637 } 637 }
638 638
639 bool DownloadItemImpl::GetFileExternallyRemoved() const { 639 bool DownloadItemImpl::GetFileExternallyRemoved() const {
640 return file_externally_removed_; 640 return file_externally_removed_;
641 } 641 }
642 642
643 void DownloadItemImpl::DeleteFile(const base::Callback<void(bool)>& callback) { 643 void DownloadItemImpl::DeleteFile(const base::Callback<void(bool)>& callback) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 644 DCHECK_CURRENTLY_ON(BrowserThread::UI);
645 if (GetState() != DownloadItem::COMPLETE) { 645 if (GetState() != DownloadItem::COMPLETE) {
646 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. 646 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved.
647 BrowserThread::PostTask( 647 BrowserThread::PostTask(
648 BrowserThread::UI, FROM_HERE, 648 BrowserThread::UI, FROM_HERE,
649 base::Bind(&DeleteDownloadedFileDone, 649 base::Bind(&DeleteDownloadedFileDone,
650 base::WeakPtr<DownloadItemImpl>(), callback, false)); 650 base::WeakPtr<DownloadItemImpl>(), callback, false));
651 return; 651 return;
652 } 652 }
653 if (current_path_.empty() || file_externally_removed_) { 653 if (current_path_.empty() || file_externally_removed_) {
654 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved. 654 // Pass a null WeakPtr so it doesn't call OnDownloadedFileRemoved.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // TODO(rdsmith): Remove null check after removing GetWebContents() from 772 // TODO(rdsmith): Remove null check after removing GetWebContents() from
773 // paths that might be used by DownloadItems created from history import. 773 // paths that might be used by DownloadItems created from history import.
774 // Currently such items have null request_handle_s, where other items 774 // Currently such items have null request_handle_s, where other items
775 // (regular and SavePackage downloads) have actual objects off the pointer. 775 // (regular and SavePackage downloads) have actual objects off the pointer.
776 if (request_handle_) 776 if (request_handle_)
777 return request_handle_->GetWebContents(); 777 return request_handle_->GetWebContents();
778 return NULL; 778 return NULL;
779 } 779 }
780 780
781 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) { 781 void DownloadItemImpl::OnContentCheckCompleted(DownloadDangerType danger_type) {
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
783 DCHECK(AllDataSaved()); 783 DCHECK(AllDataSaved());
784 DVLOG(20) << __FUNCTION__ << " danger_type=" << danger_type 784 DVLOG(20) << __FUNCTION__ << " danger_type=" << danger_type
785 << " download=" << DebugString(true); 785 << " download=" << DebugString(true);
786 SetDangerType(danger_type); 786 SetDangerType(danger_type);
787 UpdateObservers(); 787 UpdateObservers();
788 } 788 }
789 789
790 void DownloadItemImpl::SetOpenWhenComplete(bool open) { 790 void DownloadItemImpl::SetOpenWhenComplete(bool open) {
791 open_when_complete_ = open; 791 open_when_complete_ = open;
792 } 792 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 } else { 857 } else {
858 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 858 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
859 } 859 }
860 860
861 description += " }"; 861 description += " }";
862 862
863 return description; 863 return description;
864 } 864 }
865 865
866 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const { 866 DownloadItemImpl::ResumeMode DownloadItemImpl::GetResumeMode() const {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 867 DCHECK_CURRENTLY_ON(BrowserThread::UI);
868 // We can't continue without a handle on the intermediate file. 868 // We can't continue without a handle on the intermediate file.
869 // We also can't continue if we don't have some verifier to make sure 869 // We also can't continue if we don't have some verifier to make sure
870 // we're getting the same file. 870 // we're getting the same file.
871 const bool force_restart = 871 const bool force_restart =
872 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty())); 872 (current_path_.empty() || (etag_.empty() && last_modified_time_.empty()));
873 873
874 // We won't auto-restart if we've used up our attempts or the 874 // We won't auto-restart if we've used up our attempts or the
875 // download has been paused by user action. 875 // download has been paused by user action.
876 const bool force_user = 876 const bool force_user =
877 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_); 877 (auto_resume_count_ >= kMaxAutoResumeAttempts || is_paused_);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM: 931 case DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM:
932 mode = RESUME_MODE_INVALID; 932 mode = RESUME_MODE_INVALID;
933 break; 933 break;
934 } 934 }
935 935
936 return mode; 936 return mode;
937 } 937 }
938 938
939 void DownloadItemImpl::MergeOriginInfoOnResume( 939 void DownloadItemImpl::MergeOriginInfoOnResume(
940 const DownloadCreateInfo& new_create_info) { 940 const DownloadCreateInfo& new_create_info) {
941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 941 DCHECK_CURRENTLY_ON(BrowserThread::UI);
942 DCHECK_EQ(RESUMING_INTERNAL, state_); 942 DCHECK_EQ(RESUMING_INTERNAL, state_);
943 DCHECK(!new_create_info.url_chain.empty()); 943 DCHECK(!new_create_info.url_chain.empty());
944 944
945 // We are going to tack on any new redirects to our list of redirects. 945 // We are going to tack on any new redirects to our list of redirects.
946 // When a download is resumed, the URL used for the resumption request is the 946 // When a download is resumed, the URL used for the resumption request is the
947 // one at the end of the previous redirect chain. Tacking additional redirects 947 // one at the end of the previous redirect chain. Tacking additional redirects
948 // to the end of this chain ensures that: 948 // to the end of this chain ensures that:
949 // - If the download needs to be resumed again, the ETag/Last-Modified headers 949 // - If the download needs to be resumed again, the ETag/Last-Modified headers
950 // will be used with the last server that sent them to us. 950 // will be used with the last server that sent them to us.
951 // - The redirect chain contains all the servers that were involved in this 951 // - The redirect chain contains all the servers that were involved in this
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 997
998 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const { 998 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const {
999 return bound_net_log_; 999 return bound_net_log_;
1000 } 1000 }
1001 1001
1002 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 1002 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
1003 total_bytes_ = total_bytes; 1003 total_bytes_ = total_bytes;
1004 } 1004 }
1005 1005
1006 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { 1006 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) {
1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1007 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1008 1008
1009 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1009 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1010 DCHECK(!all_data_saved_); 1010 DCHECK(!all_data_saved_);
1011 all_data_saved_ = true; 1011 all_data_saved_ = true;
1012 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 1012 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
1013 1013
1014 // Store final hash and null out intermediate serialized hash state. 1014 // Store final hash and null out intermediate serialized hash state.
1015 hash_ = final_hash; 1015 hash_ = final_hash;
1016 hash_state_ = ""; 1016 hash_state_ = "";
1017 1017
1018 UpdateObservers(); 1018 UpdateObservers();
1019 } 1019 }
1020 1020
1021 void DownloadItemImpl::MarkAsComplete() { 1021 void DownloadItemImpl::MarkAsComplete() {
1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1022 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1023 1023
1024 DCHECK(all_data_saved_); 1024 DCHECK(all_data_saved_);
1025 end_time_ = base::Time::Now(); 1025 end_time_ = base::Time::Now();
1026 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); 1026 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS);
1027 } 1027 }
1028 1028
1029 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, 1029 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far,
1030 int64 bytes_per_sec, 1030 int64 bytes_per_sec,
1031 const std::string& hash_state) { 1031 const std::string& hash_state) {
1032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1032 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1033 DVLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far 1033 DVLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far
1034 << " per_sec=" << bytes_per_sec << " download=" 1034 << " per_sec=" << bytes_per_sec << " download="
1035 << DebugString(true); 1035 << DebugString(true);
1036 1036
1037 if (GetState() != IN_PROGRESS) { 1037 if (GetState() != IN_PROGRESS) {
1038 // Ignore if we're no longer in-progress. This can happen if we race a 1038 // Ignore if we're no longer in-progress. This can happen if we race a
1039 // Cancel on the UI thread with an update on the FILE thread. 1039 // Cancel on the UI thread with an update on the FILE thread.
1040 // 1040 //
1041 // TODO(rdsmith): Arguably we should let this go through, as this means 1041 // TODO(rdsmith): Arguably we should let this go through, as this means
1042 // the download really did get further than we know before it was 1042 // the download really did get further than we know before it was
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 if (GetState() != IN_PROGRESS) 1079 if (GetState() != IN_PROGRESS)
1080 return; 1080 return;
1081 OnAllDataSaved(final_hash); 1081 OnAllDataSaved(final_hash);
1082 MaybeCompleteDownload(); 1082 MaybeCompleteDownload();
1083 } 1083 }
1084 1084
1085 // **** Download progression cascade 1085 // **** Download progression cascade
1086 1086
1087 void DownloadItemImpl::Init(bool active, 1087 void DownloadItemImpl::Init(bool active,
1088 DownloadType download_type) { 1088 DownloadType download_type) {
1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1089 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1090 1090
1091 if (active) 1091 if (active)
1092 RecordDownloadCount(START_COUNT); 1092 RecordDownloadCount(START_COUNT);
1093 1093
1094 std::string file_name; 1094 std::string file_name;
1095 if (download_type == SRC_HISTORY_IMPORT) { 1095 if (download_type == SRC_HISTORY_IMPORT) {
1096 // target_path_ works for History and Save As versions. 1096 // target_path_ works for History and Save As versions.
1097 file_name = target_path_.AsUTF8Unsafe(); 1097 file_name = target_path_.AsUTF8Unsafe();
1098 } else { 1098 } else {
1099 // See if it's set programmatically. 1099 // See if it's set programmatically.
(...skipping 16 matching lines...) Expand all
1116 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data); 1116 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, active_data);
1117 } 1117 }
1118 1118
1119 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); 1119 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true);
1120 } 1120 }
1121 1121
1122 // We're starting the download. 1122 // We're starting the download.
1123 void DownloadItemImpl::Start( 1123 void DownloadItemImpl::Start(
1124 scoped_ptr<DownloadFile> file, 1124 scoped_ptr<DownloadFile> file,
1125 scoped_ptr<DownloadRequestHandleInterface> req_handle) { 1125 scoped_ptr<DownloadRequestHandleInterface> req_handle) {
1126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1127 DCHECK(!download_file_.get()); 1127 DCHECK(!download_file_.get());
1128 DCHECK(file.get()); 1128 DCHECK(file.get());
1129 DCHECK(req_handle.get()); 1129 DCHECK(req_handle.get());
1130 1130
1131 download_file_ = file.Pass(); 1131 download_file_ = file.Pass();
1132 request_handle_ = req_handle.Pass(); 1132 request_handle_ = req_handle.Pass();
1133 1133
1134 if (GetState() == CANCELLED) { 1134 if (GetState() == CANCELLED) {
1135 // The download was in the process of resuming when it was cancelled. Don't 1135 // The download was in the process of resuming when it was cancelled. Don't
1136 // proceed. 1136 // proceed.
1137 ReleaseDownloadFile(true); 1137 ReleaseDownloadFile(true);
1138 request_handle_->CancelRequest(); 1138 request_handle_->CancelRequest();
1139 return; 1139 return;
1140 } 1140 }
1141 1141
1142 TransitionTo(IN_PROGRESS_INTERNAL, UPDATE_OBSERVERS); 1142 TransitionTo(IN_PROGRESS_INTERNAL, UPDATE_OBSERVERS);
1143 1143
1144 BrowserThread::PostTask( 1144 BrowserThread::PostTask(
1145 BrowserThread::FILE, FROM_HERE, 1145 BrowserThread::FILE, FROM_HERE,
1146 base::Bind(&DownloadFile::Initialize, 1146 base::Bind(&DownloadFile::Initialize,
1147 // Safe because we control download file lifetime. 1147 // Safe because we control download file lifetime.
1148 base::Unretained(download_file_.get()), 1148 base::Unretained(download_file_.get()),
1149 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized, 1149 base::Bind(&DownloadItemImpl::OnDownloadFileInitialized,
1150 weak_ptr_factory_.GetWeakPtr()))); 1150 weak_ptr_factory_.GetWeakPtr())));
1151 } 1151 }
1152 1152
1153 void DownloadItemImpl::OnDownloadFileInitialized( 1153 void DownloadItemImpl::OnDownloadFileInitialized(
1154 DownloadInterruptReason result) { 1154 DownloadInterruptReason result) {
1155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1155 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1156 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { 1156 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) {
1157 Interrupt(result); 1157 Interrupt(result);
1158 // TODO(rdsmith/asanka): Arguably we should show this in the UI, but 1158 // TODO(rdsmith/asanka): Arguably we should show this in the UI, but
1159 // it's not at all clear what to show--we haven't done filename 1159 // it's not at all clear what to show--we haven't done filename
1160 // determination, so we don't know what name to display. OTOH, 1160 // determination, so we don't know what name to display. OTOH,
1161 // the failure mode of not showing the DI if the file initialization 1161 // the failure mode of not showing the DI if the file initialization
1162 // fails isn't a good one. Can we hack up a name based on the 1162 // fails isn't a good one. Can we hack up a name based on the
1163 // URLRequest? We'll need to make sure that initialization happens 1163 // URLRequest? We'll need to make sure that initialization happens
1164 // properly. Possibly the right thing is to have the UI handle 1164 // properly. Possibly the right thing is to have the UI handle
1165 // this case specially. 1165 // this case specially.
1166 return; 1166 return;
1167 } 1167 }
1168 1168
1169 delegate_->DetermineDownloadTarget( 1169 delegate_->DetermineDownloadTarget(
1170 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined, 1170 this, base::Bind(&DownloadItemImpl::OnDownloadTargetDetermined,
1171 weak_ptr_factory_.GetWeakPtr())); 1171 weak_ptr_factory_.GetWeakPtr()));
1172 } 1172 }
1173 1173
1174 // Called by delegate_ when the download target path has been 1174 // Called by delegate_ when the download target path has been
1175 // determined. 1175 // determined.
1176 void DownloadItemImpl::OnDownloadTargetDetermined( 1176 void DownloadItemImpl::OnDownloadTargetDetermined(
1177 const base::FilePath& target_path, 1177 const base::FilePath& target_path,
1178 TargetDisposition disposition, 1178 TargetDisposition disposition,
1179 DownloadDangerType danger_type, 1179 DownloadDangerType danger_type,
1180 const base::FilePath& intermediate_path) { 1180 const base::FilePath& intermediate_path) {
1181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1181 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1182 1182
1183 // If the |target_path| is empty, then we consider this download to be 1183 // If the |target_path| is empty, then we consider this download to be
1184 // canceled. 1184 // canceled.
1185 if (target_path.empty()) { 1185 if (target_path.empty()) {
1186 Cancel(true); 1186 Cancel(true);
1187 return; 1187 return;
1188 } 1188 }
1189 1189
1190 // TODO(rdsmith,asanka): We are ignoring the possibility that the download 1190 // TODO(rdsmith,asanka): We are ignoring the possibility that the download
1191 // has been interrupted at this point until we finish the intermediate 1191 // has been interrupted at this point until we finish the intermediate
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 BrowserThread::FILE, FROM_HERE, 1234 BrowserThread::FILE, FROM_HERE,
1235 base::Bind(&DownloadFile::RenameAndUniquify, 1235 base::Bind(&DownloadFile::RenameAndUniquify,
1236 // Safe because we control download file lifetime. 1236 // Safe because we control download file lifetime.
1237 base::Unretained(download_file_.get()), 1237 base::Unretained(download_file_.get()),
1238 intermediate_path, callback)); 1238 intermediate_path, callback));
1239 } 1239 }
1240 1240
1241 void DownloadItemImpl::OnDownloadRenamedToIntermediateName( 1241 void DownloadItemImpl::OnDownloadRenamedToIntermediateName(
1242 DownloadInterruptReason reason, 1242 DownloadInterruptReason reason,
1243 const base::FilePath& full_path) { 1243 const base::FilePath& full_path) {
1244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1244 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1245 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true); 1245 DVLOG(20) << __FUNCTION__ << " download=" << DebugString(true);
1246 1246
1247 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) { 1247 if (DOWNLOAD_INTERRUPT_REASON_NONE != destination_error_) {
1248 // Process destination error. If both |reason| and |destination_error_| 1248 // Process destination error. If both |reason| and |destination_error_|
1249 // refer to actual errors, we want to use the |destination_error_| as the 1249 // refer to actual errors, we want to use the |destination_error_| as the
1250 // argument to the Interrupt() routine, as it happened first. 1250 // argument to the Interrupt() routine, as it happened first.
1251 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE) 1251 if (reason == DOWNLOAD_INTERRUPT_REASON_NONE)
1252 SetFullPath(full_path); 1252 SetFullPath(full_path);
1253 Interrupt(destination_error_); 1253 Interrupt(destination_error_);
1254 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE; 1254 destination_error_ = DOWNLOAD_INTERRUPT_REASON_NONE;
(...skipping 13 matching lines...) Expand all
1268 // When SavePackage downloads MHTML to GData (see 1268 // When SavePackage downloads MHTML to GData (see
1269 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it 1269 // SavePackageFilePickerChromeOS), GData calls MaybeCompleteDownload() like it
1270 // does for non-SavePackage downloads, but SavePackage downloads never satisfy 1270 // does for non-SavePackage downloads, but SavePackage downloads never satisfy
1271 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls 1271 // IsDownloadReadyForCompletion(). GDataDownloadObserver manually calls
1272 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage 1272 // DownloadItem::UpdateObservers() when the upload completes so that SavePackage
1273 // notices that the upload has completed and runs its normal Finish() pathway. 1273 // notices that the upload has completed and runs its normal Finish() pathway.
1274 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes 1274 // MaybeCompleteDownload() is never the mechanism by which SavePackage completes
1275 // downloads. SavePackage always uses its own Finish() to mark downloads 1275 // downloads. SavePackage always uses its own Finish() to mark downloads
1276 // complete. 1276 // complete.
1277 void DownloadItemImpl::MaybeCompleteDownload() { 1277 void DownloadItemImpl::MaybeCompleteDownload() {
1278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1278 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1279 DCHECK(!is_save_package_download_); 1279 DCHECK(!is_save_package_download_);
1280 1280
1281 if (!IsDownloadReadyForCompletion( 1281 if (!IsDownloadReadyForCompletion(
1282 base::Bind(&DownloadItemImpl::MaybeCompleteDownload, 1282 base::Bind(&DownloadItemImpl::MaybeCompleteDownload,
1283 weak_ptr_factory_.GetWeakPtr()))) 1283 weak_ptr_factory_.GetWeakPtr())))
1284 return; 1284 return;
1285 1285
1286 // TODO(rdsmith): DCHECK that we only pass through this point 1286 // TODO(rdsmith): DCHECK that we only pass through this point
1287 // once per download. The natural way to do this is by a state 1287 // once per download. The natural way to do this is by a state
1288 // transition on the DownloadItem. 1288 // transition on the DownloadItem.
1289 1289
1290 // Confirm we're in the proper set of states to be here; 1290 // Confirm we're in the proper set of states to be here;
1291 // have all data, have a history handle, (validated or safe). 1291 // have all data, have a history handle, (validated or safe).
1292 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); 1292 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_);
1293 DCHECK(!IsDangerous()); 1293 DCHECK(!IsDangerous());
1294 DCHECK(all_data_saved_); 1294 DCHECK(all_data_saved_);
1295 1295
1296 OnDownloadCompleting(); 1296 OnDownloadCompleting();
1297 } 1297 }
1298 1298
1299 // Called by MaybeCompleteDownload() when it has determined that the download 1299 // Called by MaybeCompleteDownload() when it has determined that the download
1300 // is ready for completion. 1300 // is ready for completion.
1301 void DownloadItemImpl::OnDownloadCompleting() { 1301 void DownloadItemImpl::OnDownloadCompleting() {
1302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1302 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1303 1303
1304 if (state_ != IN_PROGRESS_INTERNAL) 1304 if (state_ != IN_PROGRESS_INTERNAL)
1305 return; 1305 return;
1306 1306
1307 DVLOG(20) << __FUNCTION__ << "()" 1307 DVLOG(20) << __FUNCTION__ << "()"
1308 << " " << DebugString(true); 1308 << " " << DebugString(true);
1309 DCHECK(!GetTargetFilePath().empty()); 1309 DCHECK(!GetTargetFilePath().empty());
1310 DCHECK(!IsDangerous()); 1310 DCHECK(!IsDangerous());
1311 1311
1312 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration. 1312 // TODO(rdsmith/benjhayden): Remove as part of SavePackage integration.
(...skipping 16 matching lines...) Expand all
1329 BrowserThread::PostTask( 1329 BrowserThread::PostTask(
1330 BrowserThread::FILE, FROM_HERE, 1330 BrowserThread::FILE, FROM_HERE,
1331 base::Bind(&DownloadFile::RenameAndAnnotate, 1331 base::Bind(&DownloadFile::RenameAndAnnotate,
1332 base::Unretained(download_file_.get()), 1332 base::Unretained(download_file_.get()),
1333 GetTargetFilePath(), callback)); 1333 GetTargetFilePath(), callback));
1334 } 1334 }
1335 1335
1336 void DownloadItemImpl::OnDownloadRenamedToFinalName( 1336 void DownloadItemImpl::OnDownloadRenamedToFinalName(
1337 DownloadInterruptReason reason, 1337 DownloadInterruptReason reason,
1338 const base::FilePath& full_path) { 1338 const base::FilePath& full_path) {
1339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1339 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1340 DCHECK(!is_save_package_download_); 1340 DCHECK(!is_save_package_download_);
1341 1341
1342 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which 1342 // If a cancel or interrupt hit, we'll cancel the DownloadFile, which
1343 // will result in deleting the file on the file thread. So we don't 1343 // will result in deleting the file on the file thread. So we don't
1344 // care about the name having been changed. 1344 // care about the name having been changed.
1345 if (state_ != IN_PROGRESS_INTERNAL) 1345 if (state_ != IN_PROGRESS_INTERNAL)
1346 return; 1346 return;
1347 1347
1348 DVLOG(20) << __FUNCTION__ << "()" 1348 DVLOG(20) << __FUNCTION__ << "()"
1349 << " full_path = \"" << full_path.value() << "\"" 1349 << " full_path = \"" << full_path.value() << "\""
(...skipping 30 matching lines...) Expand all
1380 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened, 1380 this, base::Bind(&DownloadItemImpl::DelayedDownloadOpened,
1381 weak_ptr_factory_.GetWeakPtr()))) { 1381 weak_ptr_factory_.GetWeakPtr()))) {
1382 Completed(); 1382 Completed();
1383 } else { 1383 } else {
1384 delegate_delayed_complete_ = true; 1384 delegate_delayed_complete_ = true;
1385 UpdateObservers(); 1385 UpdateObservers();
1386 } 1386 }
1387 } 1387 }
1388 1388
1389 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) { 1389 void DownloadItemImpl::DelayedDownloadOpened(bool auto_opened) {
1390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1390 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1391 1391
1392 auto_opened_ = auto_opened; 1392 auto_opened_ = auto_opened;
1393 Completed(); 1393 Completed();
1394 } 1394 }
1395 1395
1396 void DownloadItemImpl::Completed() { 1396 void DownloadItemImpl::Completed() {
1397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1397 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1398 1398
1399 DVLOG(20) << __FUNCTION__ << "() " << DebugString(false); 1399 DVLOG(20) << __FUNCTION__ << "() " << DebugString(false);
1400 1400
1401 DCHECK(all_data_saved_); 1401 DCHECK(all_data_saved_);
1402 end_time_ = base::Time::Now(); 1402 end_time_ = base::Time::Now();
1403 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS); 1403 TransitionTo(COMPLETE_INTERNAL, UPDATE_OBSERVERS);
1404 RecordDownloadCompleted(start_tick_, received_bytes_); 1404 RecordDownloadCompleted(start_tick_, received_bytes_);
1405 1405
1406 if (auto_opened_) { 1406 if (auto_opened_) {
1407 // If it was already handled by the delegate, do nothing. 1407 // If it was already handled by the delegate, do nothing.
(...skipping 24 matching lines...) Expand all
1432 // Otherwise, the request failed without passing through 1432 // Otherwise, the request failed without passing through
1433 // DownloadResourceHandler::OnResponseStarted. 1433 // DownloadResourceHandler::OnResponseStarted.
1434 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason); 1434 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, interrupt_reason);
1435 Interrupt(interrupt_reason); 1435 Interrupt(interrupt_reason);
1436 } 1436 }
1437 1437
1438 // **** End of Download progression cascade 1438 // **** End of Download progression cascade
1439 1439
1440 // An error occurred somewhere. 1440 // An error occurred somewhere.
1441 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) { 1441 void DownloadItemImpl::Interrupt(DownloadInterruptReason reason) {
1442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1442 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1443 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason); 1443 DCHECK_NE(DOWNLOAD_INTERRUPT_REASON_NONE, reason);
1444 1444
1445 // Somewhat counter-intuitively, it is possible for us to receive an 1445 // Somewhat counter-intuitively, it is possible for us to receive an
1446 // interrupt after we've already been interrupted. The generation of 1446 // interrupt after we've already been interrupted. The generation of
1447 // interrupts from the file thread Renames and the generation of 1447 // interrupts from the file thread Renames and the generation of
1448 // interrupts from disk writes go through two different mechanisms (driven 1448 // interrupts from disk writes go through two different mechanisms (driven
1449 // by rename requests from UI thread and by write requests from IO thread, 1449 // by rename requests from UI thread and by write requests from IO thread,
1450 // respectively), and since we choose not to keep state on the File thread, 1450 // respectively), and since we choose not to keep state on the File thread,
1451 // this is the place where the races collide. It's also possible for 1451 // this is the place where the races collide. It's also possible for
1452 // interrupts to race with cancels. 1452 // interrupts to race with cancels.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 TransitionTo(INTERRUPTED_INTERNAL, DONT_UPDATE_OBSERVERS); 1492 TransitionTo(INTERRUPTED_INTERNAL, DONT_UPDATE_OBSERVERS);
1493 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_); 1493 RecordDownloadInterrupted(reason, received_bytes_, total_bytes_);
1494 if (!GetWebContents()) 1494 if (!GetWebContents())
1495 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS); 1495 RecordDownloadCount(INTERRUPTED_WITHOUT_WEBCONTENTS);
1496 1496
1497 AutoResumeIfValid(); 1497 AutoResumeIfValid();
1498 UpdateObservers(); 1498 UpdateObservers();
1499 } 1499 }
1500 1500
1501 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) { 1501 void DownloadItemImpl::ReleaseDownloadFile(bool destroy_file) {
1502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1502 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1503 1503
1504 if (destroy_file) { 1504 if (destroy_file) {
1505 BrowserThread::PostTask( 1505 BrowserThread::PostTask(
1506 BrowserThread::FILE, FROM_HERE, 1506 BrowserThread::FILE, FROM_HERE,
1507 // Will be deleted at end of task execution. 1507 // Will be deleted at end of task execution.
1508 base::Bind(&DownloadFileCancel, base::Passed(&download_file_))); 1508 base::Bind(&DownloadFileCancel, base::Passed(&download_file_)));
1509 // Avoid attempting to reuse the intermediate file by clearing out 1509 // Avoid attempting to reuse the intermediate file by clearing out
1510 // current_path_. 1510 // current_path_.
1511 current_path_.clear(); 1511 current_path_.clear();
1512 } else { 1512 } else {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // Give the delegate a chance to hold up a stop sign. It'll call 1553 // Give the delegate a chance to hold up a stop sign. It'll call
1554 // use back through the passed callback if it does and that state changes. 1554 // use back through the passed callback if it does and that state changes.
1555 if (!delegate_->ShouldCompleteDownload(this, state_change_notification)) 1555 if (!delegate_->ShouldCompleteDownload(this, state_change_notification))
1556 return false; 1556 return false;
1557 1557
1558 return true; 1558 return true;
1559 } 1559 }
1560 1560
1561 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state, 1561 void DownloadItemImpl::TransitionTo(DownloadInternalState new_state,
1562 ShouldUpdateObservers notify_action) { 1562 ShouldUpdateObservers notify_action) {
1563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1563 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1564 1564
1565 if (state_ == new_state) 1565 if (state_ == new_state)
1566 return; 1566 return;
1567 1567
1568 DownloadInternalState old_state = state_; 1568 DownloadInternalState old_state = state_;
1569 state_ = new_state; 1569 state_ = new_state;
1570 1570
1571 switch (state_) { 1571 switch (state_) {
1572 case COMPLETING_INTERNAL: 1572 case COMPLETING_INTERNAL:
1573 bound_net_log_.AddEvent( 1573 bound_net_log_.AddEvent(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST || 1643 (danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST ||
1644 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || 1644 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
1645 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || 1645 danger_type == DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
1646 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) { 1646 danger_type == DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED)) {
1647 RecordMaliciousDownloadClassified(danger_type); 1647 RecordMaliciousDownloadClassified(danger_type);
1648 } 1648 }
1649 danger_type_ = danger_type; 1649 danger_type_ = danger_type;
1650 } 1650 }
1651 1651
1652 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) { 1652 void DownloadItemImpl::SetFullPath(const base::FilePath& new_path) {
1653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1653 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1654 DVLOG(20) << __FUNCTION__ << "()" 1654 DVLOG(20) << __FUNCTION__ << "()"
1655 << " new_path = \"" << new_path.value() << "\"" 1655 << " new_path = \"" << new_path.value() << "\""
1656 << " " << DebugString(true); 1656 << " " << DebugString(true);
1657 DCHECK(!new_path.empty()); 1657 DCHECK(!new_path.empty());
1658 1658
1659 bound_net_log_.AddEvent( 1659 bound_net_log_.AddEvent(
1660 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED, 1660 net::NetLog::TYPE_DOWNLOAD_ITEM_RENAMED,
1661 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path)); 1661 base::Bind(&ItemRenamedNetLogCallback, &current_path_, &new_path));
1662 1662
1663 current_path_ = new_path; 1663 current_path_ = new_path;
1664 } 1664 }
1665 1665
1666 void DownloadItemImpl::AutoResumeIfValid() { 1666 void DownloadItemImpl::AutoResumeIfValid() {
1667 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true); 1667 DVLOG(20) << __FUNCTION__ << "() " << DebugString(true);
1668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1668 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1669 ResumeMode mode = GetResumeMode(); 1669 ResumeMode mode = GetResumeMode();
1670 1670
1671 if (mode != RESUME_MODE_IMMEDIATE_RESTART && 1671 if (mode != RESUME_MODE_IMMEDIATE_RESTART &&
1672 mode != RESUME_MODE_IMMEDIATE_CONTINUE) { 1672 mode != RESUME_MODE_IMMEDIATE_CONTINUE) {
1673 return; 1673 return;
1674 } 1674 }
1675 1675
1676 auto_resume_count_++; 1676 auto_resume_count_++;
1677 1677
1678 ResumeInterruptedDownload(); 1678 ResumeInterruptedDownload();
1679 } 1679 }
1680 1680
1681 void DownloadItemImpl::ResumeInterruptedDownload() { 1681 void DownloadItemImpl::ResumeInterruptedDownload() {
1682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1682 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1683 1683
1684 // If the flag for downloads resumption isn't enabled, ignore 1684 // If the flag for downloads resumption isn't enabled, ignore
1685 // this request. 1685 // this request.
1686 const base::CommandLine& command_line = 1686 const base::CommandLine& command_line =
1687 *base::CommandLine::ForCurrentProcess(); 1687 *base::CommandLine::ForCurrentProcess();
1688 if (!command_line.HasSwitch(switches::kEnableDownloadResumption)) 1688 if (!command_line.HasSwitch(switches::kEnableDownloadResumption))
1689 return; 1689 return;
1690 1690
1691 // If we're not interrupted, ignore the request; our caller is drunk. 1691 // If we're not interrupted, ignore the request; our caller is drunk.
1692 if (state_ != INTERRUPTED_INTERNAL) 1692 if (state_ != INTERRUPTED_INTERNAL)
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 case RESUME_MODE_USER_CONTINUE: 1804 case RESUME_MODE_USER_CONTINUE:
1805 return "USER_CONTINUE"; 1805 return "USER_CONTINUE";
1806 case RESUME_MODE_USER_RESTART: 1806 case RESUME_MODE_USER_RESTART:
1807 return "USER_RESTART"; 1807 return "USER_RESTART";
1808 } 1808 }
1809 NOTREACHED() << "Unknown resume mode " << mode; 1809 NOTREACHED() << "Unknown resume mode " << mode;
1810 return "unknown"; 1810 return "unknown";
1811 } 1811 }
1812 1812
1813 } // namespace content 1813 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_file_impl.cc ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698