Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 DownloadItem::DangerType GetDangerType(bool dangerous_file, | 103 DownloadItem::DangerType GetDangerType(bool dangerous_file, |
| 104 bool dangerous_url) { | 104 bool dangerous_url) { |
| 105 if (dangerous_url) { | 105 if (dangerous_url) { |
| 106 // dangerous URL overweights dangerous file. We check dangerous URL first. | 106 // dangerous URL overweights dangerous file. We check dangerous URL first. |
| 107 return DownloadItem::DANGEROUS_URL; | 107 return DownloadItem::DANGEROUS_URL; |
| 108 } | 108 } |
| 109 return dangerous_file ? | 109 return dangerous_file ? |
| 110 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; | 110 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Classes to null out request handle calls (for SavePage DownloadItems, which | |
| 114 // may have, e.g., Cancel() called on them without it doing anything) | |
| 115 // and to DCHECK on them (for history DownloadItems, which should never have | |
| 116 // any operation that implies an off-thread component, since they don't | |
| 117 // have any). | |
| 118 class NullDownloadRequestHandle : public DownloadRequestHandleInterface { | |
| 119 public: | |
| 120 NullDownloadRequestHandle() {} | |
| 121 | |
| 122 // DownloadRequestHandleInterface calls | |
| 123 virtual TabContents* GetTabContents() const OVERRIDE { | |
| 124 return NULL; | |
| 125 } | |
| 126 virtual DownloadManager* GetDownloadManager() const OVERRIDE { | |
| 127 return NULL; | |
| 128 } | |
| 129 virtual void PauseRequest() const OVERRIDE {} | |
| 130 virtual void ResumeRequest() const OVERRIDE {} | |
| 131 virtual void CancelRequest() const OVERRIDE {} | |
| 132 virtual std::string DebugString() const OVERRIDE { | |
| 133 return "Null DownloadRequestHandle"; | |
| 134 } | |
| 135 }; | |
| 136 | |
| 137 | |
| 113 } // namespace | 138 } // namespace |
| 114 | 139 |
| 115 // Our download table ID starts at 1, so we use 0 to represent a download that | 140 // Our download table ID starts at 1, so we use 0 to represent a download that |
| 116 // has started, but has not yet had its data persisted in the table. We use fake | 141 // has started, but has not yet had its data persisted in the table. We use fake |
| 117 // database handles in incognito mode starting at -1 and progressively getting | 142 // database handles in incognito mode starting at -1 and progressively getting |
| 118 // more negative. | 143 // more negative. |
| 119 // static | 144 // static |
| 120 const int DownloadItem::kUninitializedHandle = 0; | 145 const int DownloadItem::kUninitializedHandle = 0; |
| 121 | 146 |
| 122 // Constructor for reading from the history service. | 147 // Constructor for reading from the history service. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 delegate_delayed_complete_(false) { | 217 delegate_delayed_complete_(false) { |
| 193 Init(true /* actively downloading */); | 218 Init(true /* actively downloading */); |
| 194 } | 219 } |
| 195 | 220 |
| 196 // Constructing for the "Save Page As..." feature: | 221 // Constructing for the "Save Page As..." feature: |
| 197 DownloadItem::DownloadItem(DownloadManager* download_manager, | 222 DownloadItem::DownloadItem(DownloadManager* download_manager, |
| 198 const FilePath& path, | 223 const FilePath& path, |
| 199 const GURL& url, | 224 const GURL& url, |
| 200 bool is_otr, | 225 bool is_otr, |
| 201 DownloadId download_id) | 226 DownloadId download_id) |
| 202 : download_id_(download_id), | 227 : request_handle_(new NullDownloadRequestHandle()), |
| 228 download_id_(download_id), | |
| 203 full_path_(path), | 229 full_path_(path), |
| 204 url_chain_(1, url), | 230 url_chain_(1, url), |
| 205 referrer_url_(GURL()), | 231 referrer_url_(GURL()), |
| 206 total_bytes_(0), | 232 total_bytes_(0), |
| 207 received_bytes_(0), | 233 received_bytes_(0), |
| 208 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 234 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
| 209 start_tick_(base::TimeTicks::Now()), | 235 start_tick_(base::TimeTicks::Now()), |
| 210 state_(IN_PROGRESS), | 236 state_(IN_PROGRESS), |
| 211 start_time_(base::Time::Now()), | 237 start_time_(base::Time::Now()), |
| 212 db_handle_(DownloadItem::kUninitializedHandle), | 238 db_handle_(DownloadItem::kUninitializedHandle), |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 return state_info_.target_name; | 726 return state_info_.target_name; |
| 701 } | 727 } |
| 702 | 728 |
| 703 FilePath DownloadItem::GetUserVerifiedFilePath() const { | 729 FilePath DownloadItem::GetUserVerifiedFilePath() const { |
| 704 return (safety_state_ == DownloadItem::SAFE) ? | 730 return (safety_state_ == DownloadItem::SAFE) ? |
| 705 GetTargetFilePath() : full_path_; | 731 GetTargetFilePath() : full_path_; |
| 706 } | 732 } |
| 707 | 733 |
| 708 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { | 734 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { |
| 709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 710 request_handle_->CancelRequest(); | 736 request_handle_->CancelRequest(); |
|
benjhayden
2011/11/11 16:30:59
Why not just if(request_handle_) here?
| |
| 711 | 737 |
| 712 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 738 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 713 base::Bind(&DownloadFileManager::CancelDownload, | 739 base::Bind(&DownloadFileManager::CancelDownload, |
| 714 file_manager, global_id())); | 740 file_manager, global_id())); |
| 715 } | 741 } |
| 716 | 742 |
| 717 void DownloadItem::Init(bool active) { | 743 void DownloadItem::Init(bool active) { |
| 718 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. | 744 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. |
| 719 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 745 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 720 | 746 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 state_info_.target_name.value().c_str(), | 821 state_info_.target_name.value().c_str(), |
| 796 full_path().value().c_str()); | 822 full_path().value().c_str()); |
| 797 } else { | 823 } else { |
| 798 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 824 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
| 799 } | 825 } |
| 800 | 826 |
| 801 description += " }"; | 827 description += " }"; |
| 802 | 828 |
| 803 return description; | 829 return description; |
| 804 } | 830 } |
| OLD | NEW |