OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_item.h" | 5 #include "content/browser/download/download_item.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (IsInProgress()) | 150 if (IsInProgress()) |
151 state_ = CANCELLED; | 151 state_ = CANCELLED; |
152 if (IsComplete()) | 152 if (IsComplete()) |
153 all_data_saved_ = true; | 153 all_data_saved_ = true; |
154 Init(false /* not actively downloading */); | 154 Init(false /* not actively downloading */); |
155 } | 155 } |
156 | 156 |
157 // Constructing for a regular download: | 157 // Constructing for a regular download: |
158 DownloadItem::DownloadItem(DownloadManager* download_manager, | 158 DownloadItem::DownloadItem(DownloadManager* download_manager, |
159 const DownloadCreateInfo& info, | 159 const DownloadCreateInfo& info, |
160 const DownloadRequestHandle& request_handle, | 160 DownloadRequestHandleInterface* request_handle, |
161 bool is_otr) | 161 bool is_otr) |
162 : state_info_(info.original_name, info.save_info.file_path, | 162 : state_info_(info.original_name, info.save_info.file_path, |
163 info.has_user_gesture, info.transition_type, | 163 info.has_user_gesture, info.transition_type, |
164 info.prompt_user_for_save_location, info.path_uniquifier, | 164 info.prompt_user_for_save_location, info.path_uniquifier, |
165 false, false), | 165 false, false), |
166 request_handle_(request_handle), | 166 request_handle_(request_handle), |
167 download_id_(info.download_id), | 167 download_id_(info.download_id), |
168 full_path_(info.path), | 168 full_path_(info.path), |
169 url_chain_(info.url_chain), | 169 url_chain_(info.url_chain), |
170 referrer_url_(info.referrer_url), | 170 referrer_url_(info.referrer_url), |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 DCHECK(!full_path.empty()); | 568 DCHECK(!full_path.empty()); |
569 full_path_ = full_path; | 569 full_path_ = full_path; |
570 } | 570 } |
571 | 571 |
572 void DownloadItem::TogglePause() { | 572 void DownloadItem::TogglePause() { |
573 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 573 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
574 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 574 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
575 | 575 |
576 DCHECK(IsInProgress()); | 576 DCHECK(IsInProgress()); |
577 if (is_paused_) | 577 if (is_paused_) |
578 request_handle_.ResumeRequest(); | 578 request_handle_->ResumeRequest(); |
579 else | 579 else |
580 request_handle_.PauseRequest(); | 580 request_handle_->PauseRequest(); |
581 is_paused_ = !is_paused_; | 581 is_paused_ = !is_paused_; |
582 UpdateObservers(); | 582 UpdateObservers(); |
583 } | 583 } |
584 | 584 |
585 void DownloadItem::OnDownloadCompleting(DownloadFileManager* file_manager) { | 585 void DownloadItem::OnDownloadCompleting(DownloadFileManager* file_manager) { |
586 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 586 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
587 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 587 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
588 | 588 |
589 VLOG(20) << __FUNCTION__ << "()" | 589 VLOG(20) << __FUNCTION__ << "()" |
590 << " needs rename = " << NeedsRename() | 590 << " needs rename = " << NeedsRename() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 string16 url_raw(UTF8ToUTF16(GetURL().spec())); | 635 string16 url_raw(UTF8ToUTF16(GetURL().spec())); |
636 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_raw)) | 636 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_raw)) |
637 return true; | 637 return true; |
638 | 638 |
639 // TODO(phajdan.jr): write a test case for the following code. | 639 // TODO(phajdan.jr): write a test case for the following code. |
640 // A good test case would be: | 640 // A good test case would be: |
641 // "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", | 641 // "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd", |
642 // L"/\x4f60\x597d\x4f60\x597d", | 642 // L"/\x4f60\x597d\x4f60\x597d", |
643 // "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD" | 643 // "/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD" |
644 std::string languages; | 644 std::string languages; |
645 TabContents* tab = request_handle_.GetTabContents(); | 645 TabContents* tab = request_handle_->GetTabContents(); |
646 if (tab) | 646 if (tab) |
647 languages = content::GetContentClient()->browser()->GetAcceptLangs(tab); | 647 languages = content::GetContentClient()->browser()->GetAcceptLangs(tab); |
648 string16 url_formatted(net::FormatUrl(GetURL(), languages)); | 648 string16 url_formatted(net::FormatUrl(GetURL(), languages)); |
649 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_formatted)) | 649 if (base::i18n::StringSearchIgnoringCaseAndAccents(query, url_formatted)) |
650 return true; | 650 return true; |
651 | 651 |
652 string16 path(full_path().LossyDisplayName()); | 652 string16 path(full_path().LossyDisplayName()); |
653 return base::i18n::StringSearchIgnoringCaseAndAccents(query, path); | 653 return base::i18n::StringSearchIgnoringCaseAndAccents(query, path); |
654 } | 654 } |
655 | 655 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 referrer_url(), | 695 referrer_url(), |
696 start_time(), | 696 start_time(), |
697 end_time(), | 697 end_time(), |
698 received_bytes(), | 698 received_bytes(), |
699 total_bytes(), | 699 total_bytes(), |
700 state(), | 700 state(), |
701 db_handle(), | 701 db_handle(), |
702 opened()); | 702 opened()); |
703 } | 703 } |
704 | 704 |
| 705 TabContents* DownloadItem::GetTabContents() const { |
| 706 if (request_handle_.get()) |
| 707 return request_handle_->GetTabContents(); |
| 708 return NULL; |
| 709 } |
| 710 |
705 FilePath DownloadItem::GetTargetFilePath() const { | 711 FilePath DownloadItem::GetTargetFilePath() const { |
706 return full_path_.DirName().Append(state_info_.target_name); | 712 return full_path_.DirName().Append(state_info_.target_name); |
707 } | 713 } |
708 | 714 |
709 FilePath DownloadItem::GetFileNameToReportUser() const { | 715 FilePath DownloadItem::GetFileNameToReportUser() const { |
710 if (state_info_.path_uniquifier > 0) { | 716 if (state_info_.path_uniquifier > 0) { |
711 FilePath name(state_info_.target_name); | 717 FilePath name(state_info_.target_name); |
712 DownloadFile::AppendNumberToPath(&name, state_info_.path_uniquifier); | 718 DownloadFile::AppendNumberToPath(&name, state_info_.path_uniquifier); |
713 return name; | 719 return name; |
714 } | 720 } |
715 return state_info_.target_name; | 721 return state_info_.target_name; |
716 } | 722 } |
717 | 723 |
718 FilePath DownloadItem::GetUserVerifiedFilePath() const { | 724 FilePath DownloadItem::GetUserVerifiedFilePath() const { |
719 return (safety_state_ == DownloadItem::SAFE) ? | 725 return (safety_state_ == DownloadItem::SAFE) ? |
720 GetTargetFilePath() : full_path_; | 726 GetTargetFilePath() : full_path_; |
721 } | 727 } |
722 | 728 |
723 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { | 729 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { |
724 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
725 request_handle_.CancelRequest(); | 731 request_handle_->CancelRequest(); |
726 | 732 |
727 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 733 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
728 base::Bind(&DownloadFileManager::CancelDownload, | 734 base::Bind(&DownloadFileManager::CancelDownload, |
729 file_manager, global_id())); | 735 file_manager, global_id())); |
730 } | 736 } |
731 | 737 |
732 void DownloadItem::Init(bool active) { | 738 void DownloadItem::Init(bool active) { |
733 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 739 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
734 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 740 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
735 | 741 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 state_info_.target_name.value().c_str(), | 817 state_info_.target_name.value().c_str(), |
812 full_path().value().c_str()); | 818 full_path().value().c_str()); |
813 } else { | 819 } else { |
814 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 820 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
815 } | 821 } |
816 | 822 |
817 description += " }"; | 823 description += " }"; |
818 | 824 |
819 return description; | 825 return description; |
820 } | 826 } |
OLD | NEW |