OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 const bool new_download = !id.IsValid(); | 365 const bool new_download = !id.IsValid(); |
366 DownloadItemImpl* download = NULL; | 366 DownloadItemImpl* download = NULL; |
367 | 367 |
368 if (new_download) { | 368 if (new_download) { |
369 id = GetNextId(); | 369 id = GetNextId(); |
370 download = CreateActiveItem(id, *info); | 370 download = CreateActiveItem(id, *info); |
371 } else { | 371 } else { |
372 DownloadMap::iterator item_iterator = downloads_.find(id.local()); | 372 DownloadMap::iterator item_iterator = downloads_.find(id.local()); |
373 // Trying to resume an interrupted download. | 373 // Trying to resume an interrupted download. |
374 if (item_iterator == downloads_.end() || | 374 if (item_iterator == downloads_.end() || |
375 item_iterator->second->IsCancelled()) { | 375 (item_iterator->second->GetState() == DownloadItem::CANCELLED)) { |
376 // If the download is no longer known to the DownloadManager, then it was | 376 // If the download is no longer known to the DownloadManager, then it was |
377 // removed after it was resumed. Ignore. If the download is cancelled | 377 // removed after it was resumed. Ignore. If the download is cancelled |
378 // while resuming, then also ignore the request. | 378 // while resuming, then also ignore the request. |
379 info->request_handle.CancelRequest(); | 379 info->request_handle.CancelRequest(); |
380 return NULL; | 380 return NULL; |
381 } | 381 } |
382 download = item_iterator->second; | 382 download = item_iterator->second; |
383 DCHECK(download->IsInterrupted()); | 383 DCHECK_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
384 } | 384 } |
385 | 385 |
386 base::FilePath default_download_directory; | 386 base::FilePath default_download_directory; |
387 if (delegate_) { | 387 if (delegate_) { |
388 base::FilePath website_save_directory; // Unused | 388 base::FilePath website_save_directory; // Unused |
389 bool skip_dir_check = false; // Unused | 389 bool skip_dir_check = false; // Unused |
390 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, | 390 delegate_->GetSaveDir(GetBrowserContext(), &website_save_directory, |
391 &default_download_directory, &skip_dir_check); | 391 &default_download_directory, &skip_dir_check); |
392 } | 392 } |
393 | 393 |
(...skipping 24 matching lines...) Expand all Loading... |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
419 for (DownloadMap::iterator it = downloads_.begin(); | 419 for (DownloadMap::iterator it = downloads_.begin(); |
420 it != downloads_.end(); ++it) { | 420 it != downloads_.end(); ++it) { |
421 DownloadItemImpl* item = it->second; | 421 DownloadItemImpl* item = it->second; |
422 CheckForFileRemoval(item); | 422 CheckForFileRemoval(item); |
423 } | 423 } |
424 } | 424 } |
425 | 425 |
426 void DownloadManagerImpl::CheckForFileRemoval(DownloadItemImpl* download_item) { | 426 void DownloadManagerImpl::CheckForFileRemoval(DownloadItemImpl* download_item) { |
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
428 if (download_item->IsComplete() && | 428 if ((download_item->GetState() == DownloadItem::COMPLETE) && |
429 !download_item->GetFileExternallyRemoved() && | 429 !download_item->GetFileExternallyRemoved() && |
430 delegate_) { | 430 delegate_) { |
431 delegate_->CheckForFileExistence( | 431 delegate_->CheckForFileExistence( |
432 download_item, | 432 download_item, |
433 base::Bind(&DownloadManagerImpl::OnFileExistenceChecked, | 433 base::Bind(&DownloadManagerImpl::OnFileExistenceChecked, |
434 weak_factory_.GetWeakPtr(), download_item->GetId())); | 434 weak_factory_.GetWeakPtr(), download_item->GetId())); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 void DownloadManagerImpl::OnFileExistenceChecked(int32 download_id, | 438 void DownloadManagerImpl::OnFileExistenceChecked(int32 download_id, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 int count = 0; | 523 int count = 0; |
524 DownloadMap::const_iterator it = downloads_.begin(); | 524 DownloadMap::const_iterator it = downloads_.begin(); |
525 while (it != downloads_.end()) { | 525 while (it != downloads_.end()) { |
526 DownloadItemImpl* download = it->second; | 526 DownloadItemImpl* download = it->second; |
527 | 527 |
528 // Increment done here to protect against invalidation below. | 528 // Increment done here to protect against invalidation below. |
529 ++it; | 529 ++it; |
530 | 530 |
531 if (download->GetStartTime() >= remove_begin && | 531 if (download->GetStartTime() >= remove_begin && |
532 (remove_end.is_null() || download->GetStartTime() < remove_end) && | 532 (remove_end.is_null() || download->GetStartTime() < remove_end) && |
533 !download->IsInProgress()) { | 533 (download->GetState() != DownloadItem::IN_PROGRESS)) { |
534 // Erases the download from downloads_. | 534 // Erases the download from downloads_. |
535 download->Remove(); | 535 download->Remove(); |
536 count++; | 536 count++; |
537 } | 537 } |
538 } | 538 } |
539 return count; | 539 return count; |
540 } | 540 } |
541 | 541 |
542 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { | 542 int DownloadManagerImpl::RemoveDownloads(base::Time remove_begin) { |
543 return RemoveDownloadsBetween(remove_begin, base::Time()); | 543 return RemoveDownloadsBetween(remove_begin, base::Time()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 downloads_[item->GetId()] = item; | 602 downloads_[item->GetId()] = item; |
603 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); | 603 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadCreated(this, item)); |
604 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); | 604 VLOG(20) << __FUNCTION__ << "() download = " << item->DebugString(true); |
605 return item; | 605 return item; |
606 } | 606 } |
607 | 607 |
608 int DownloadManagerImpl::InProgressCount() const { | 608 int DownloadManagerImpl::InProgressCount() const { |
609 int count = 0; | 609 int count = 0; |
610 for (DownloadMap::const_iterator it = downloads_.begin(); | 610 for (DownloadMap::const_iterator it = downloads_.begin(); |
611 it != downloads_.end(); ++it) { | 611 it != downloads_.end(); ++it) { |
612 if (it->second->IsInProgress()) | 612 if (it->second->GetState() == DownloadItem::IN_PROGRESS) |
613 ++count; | 613 ++count; |
614 } | 614 } |
615 return count; | 615 return count; |
616 } | 616 } |
617 | 617 |
618 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { | 618 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { |
619 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; | 619 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; |
620 } | 620 } |
621 | 621 |
622 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { | 622 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
623 for (DownloadMap::iterator it = downloads_.begin(); | 623 for (DownloadMap::iterator it = downloads_.begin(); |
624 it != downloads_.end(); ++it) { | 624 it != downloads_.end(); ++it) { |
625 downloads->push_back(it->second); | 625 downloads->push_back(it->second); |
626 } | 626 } |
627 } | 627 } |
628 | 628 |
629 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { | 629 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { |
630 int num_unopened = 0; | 630 int num_unopened = 0; |
631 for (DownloadMap::iterator it = downloads_.begin(); | 631 for (DownloadMap::iterator it = downloads_.begin(); |
632 it != downloads_.end(); ++it) { | 632 it != downloads_.end(); ++it) { |
633 DownloadItemImpl* item = it->second; | 633 DownloadItemImpl* item = it->second; |
634 if (item->IsComplete() && | 634 if ((item->GetState() == DownloadItem::COMPLETE) && |
635 !item->GetOpened()) | 635 !item->GetOpened()) |
636 ++num_unopened; | 636 ++num_unopened; |
637 } | 637 } |
638 RecordOpensOutstanding(num_unopened); | 638 RecordOpensOutstanding(num_unopened); |
639 | 639 |
640 if (delegate_) | 640 if (delegate_) |
641 delegate_->OpenDownload(download); | 641 delegate_->OpenDownload(download); |
642 } | 642 } |
643 | 643 |
644 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { | 644 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
645 if (delegate_) | 645 if (delegate_) |
646 delegate_->ShowDownloadInShell(download); | 646 delegate_->ShowDownloadInShell(download); |
647 } | 647 } |
648 | 648 |
649 } // namespace content | 649 } // namespace content |
OLD | NEW |