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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 if (IsInProgress()) | 147 if (IsInProgress()) |
148 state_ = CANCELLED; | 148 state_ = CANCELLED; |
149 if (IsComplete()) | 149 if (IsComplete()) |
150 all_data_saved_ = true; | 150 all_data_saved_ = true; |
151 Init(false /* not actively downloading */); | 151 Init(false /* not actively downloading */); |
152 } | 152 } |
153 | 153 |
154 // Constructing for a regular download: | 154 // Constructing for a regular download: |
155 DownloadItem::DownloadItem(DownloadManager* download_manager, | 155 DownloadItem::DownloadItem(DownloadManager* download_manager, |
156 const DownloadCreateInfo& info, | 156 const DownloadCreateInfo& info, |
157 const DownloadRequestHandle& request_handle, | 157 DownloadRequestHandleInterface* request_handle, |
158 bool is_otr) | 158 bool is_otr) |
159 : state_info_(info.original_name, info.save_info.file_path, | 159 : state_info_(info.original_name, info.save_info.file_path, |
160 info.has_user_gesture, info.transition_type, | 160 info.has_user_gesture, info.transition_type, |
161 info.prompt_user_for_save_location, info.path_uniquifier, | 161 info.prompt_user_for_save_location, info.path_uniquifier, |
162 false, false), | 162 false, false), |
163 request_handle_(request_handle), | 163 request_handle_(request_handle), |
164 download_id_(info.download_id), | 164 download_id_(info.download_id), |
165 full_path_(info.path), | 165 full_path_(info.path), |
166 url_chain_(info.url_chain), | 166 url_chain_(info.url_chain), |
167 referrer_url_(info.referrer_url), | 167 referrer_url_(info.referrer_url), |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 DCHECK(!full_path.empty()); | 569 DCHECK(!full_path.empty()); |
570 full_path_ = full_path; | 570 full_path_ = full_path; |
571 } | 571 } |
572 | 572 |
573 void DownloadItem::TogglePause() { | 573 void DownloadItem::TogglePause() { |
574 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 574 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
575 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 575 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
576 | 576 |
577 DCHECK(IsInProgress()); | 577 DCHECK(IsInProgress()); |
578 if (is_paused_) | 578 if (is_paused_) |
579 request_handle_.ResumeRequest(); | 579 request_handle_->ResumeRequest(); |
580 else | 580 else |
581 request_handle_.PauseRequest(); | 581 request_handle_->PauseRequest(); |
582 is_paused_ = !is_paused_; | 582 is_paused_ = !is_paused_; |
583 UpdateObservers(); | 583 UpdateObservers(); |
584 } | 584 } |
585 | 585 |
586 void DownloadItem::OnDownloadCompleting(DownloadFileManager* file_manager) { | 586 void DownloadItem::OnDownloadCompleting(DownloadFileManager* file_manager) { |
587 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 587 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
588 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 588 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
589 | 589 |
590 VLOG(20) << __FUNCTION__ << "()" | 590 VLOG(20) << __FUNCTION__ << "()" |
591 << " needs rename = " << NeedsRename() | 591 << " needs rename = " << NeedsRename() |
(...skipping 43 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()) | |
cbentzel
2011/10/27 17:20:39
Why is this needed? DownloadItem::MatchesQuery doe
Randy Smith (Not in Mondays)
2011/10/27 18:21:22
See DownloadManager::RestartDownload. I ran into
cbentzel
2011/10/27 18:45:34
I have no problem with the wrapper - just was more
| |
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( | 733 BrowserThread::PostTask( |
728 BrowserThread::FILE, FROM_HERE, | 734 BrowserThread::FILE, FROM_HERE, |
729 NewRunnableMethod( | 735 NewRunnableMethod( |
730 file_manager, &DownloadFileManager::CancelDownload, global_id())); | 736 file_manager, &DownloadFileManager::CancelDownload, global_id())); |
731 } | 737 } |
732 | 738 |
733 void DownloadItem::Init(bool active) { | 739 void DownloadItem::Init(bool active) { |
734 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 740 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
735 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 741 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 state_info_.target_name.value().c_str(), | 818 state_info_.target_name.value().c_str(), |
813 full_path().value().c_str()); | 819 full_path().value().c_str()); |
814 } else { | 820 } else { |
815 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 821 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
816 } | 822 } |
817 | 823 |
818 description += " }"; | 824 description += " }"; |
819 | 825 |
820 return description; | 826 return description; |
821 } | 827 } |
OLD | NEW |