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 const char DownloadItem::kEmptyFileHash[] = ""; | 147 const char DownloadItem::kEmptyFileHash[] = ""; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 delegate_delayed_complete_(false) { | 219 delegate_delayed_complete_(false) { |
195 Init(true /* actively downloading */); | 220 Init(true /* actively downloading */); |
196 } | 221 } |
197 | 222 |
198 // Constructing for the "Save Page As..." feature: | 223 // Constructing for the "Save Page As..." feature: |
199 DownloadItem::DownloadItem(DownloadManager* download_manager, | 224 DownloadItem::DownloadItem(DownloadManager* download_manager, |
200 const FilePath& path, | 225 const FilePath& path, |
201 const GURL& url, | 226 const GURL& url, |
202 bool is_otr, | 227 bool is_otr, |
203 DownloadId download_id) | 228 DownloadId download_id) |
204 : download_id_(download_id), | 229 : request_handle_(new NullDownloadRequestHandle()), |
230 download_id_(download_id), | |
205 full_path_(path), | 231 full_path_(path), |
206 url_chain_(1, url), | 232 url_chain_(1, url), |
207 referrer_url_(GURL()), | 233 referrer_url_(GURL()), |
208 total_bytes_(0), | 234 total_bytes_(0), |
209 received_bytes_(0), | 235 received_bytes_(0), |
210 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), | 236 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), |
211 start_tick_(base::TimeTicks::Now()), | 237 start_tick_(base::TimeTicks::Now()), |
212 state_(IN_PROGRESS), | 238 state_(IN_PROGRESS), |
213 start_time_(base::Time::Now()), | 239 start_time_(base::Time::Now()), |
214 db_handle_(DownloadItem::kUninitializedHandle), | 240 db_handle_(DownloadItem::kUninitializedHandle), |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 start_time(), | 703 start_time(), |
678 end_time(), | 704 end_time(), |
679 received_bytes(), | 705 received_bytes(), |
680 total_bytes(), | 706 total_bytes(), |
681 state(), | 707 state(), |
682 db_handle(), | 708 db_handle(), |
683 opened()); | 709 opened()); |
684 } | 710 } |
685 | 711 |
686 TabContents* DownloadItem::GetTabContents() const { | 712 TabContents* DownloadItem::GetTabContents() const { |
687 if (request_handle_.get()) | 713 if (request_handle_.get()) |
cbentzel
2011/11/15 11:47:56
Can you remove the NULL check here?
Randy Smith (Not in Mondays)
2011/11/15 19:25:39
No, I can't, though I'd like to and I have another
cbentzel
2011/11/15 19:53:23
Thanks. It seems very confusing that it's checked
Randy Smith (Not in Mondays)
2011/11/15 21:49:49
Done.
| |
688 return request_handle_->GetTabContents(); | 714 return request_handle_->GetTabContents(); |
689 return NULL; | 715 return NULL; |
690 } | 716 } |
691 | 717 |
692 FilePath DownloadItem::GetTargetFilePath() const { | 718 FilePath DownloadItem::GetTargetFilePath() const { |
693 return full_path_.DirName().Append(state_info_.target_name); | 719 return full_path_.DirName().Append(state_info_.target_name); |
694 } | 720 } |
695 | 721 |
696 FilePath DownloadItem::GetFileNameToReportUser() const { | 722 FilePath DownloadItem::GetFileNameToReportUser() const { |
697 if (state_info_.path_uniquifier > 0) { | 723 if (state_info_.path_uniquifier > 0) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 state_info_.target_name.value().c_str(), | 823 state_info_.target_name.value().c_str(), |
798 full_path().value().c_str()); | 824 full_path().value().c_str()); |
799 } else { | 825 } else { |
800 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 826 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
801 } | 827 } |
802 | 828 |
803 description += " }"; | 829 description += " }"; |
804 | 830 |
805 return description; | 831 return description; |
806 } | 832 } |
OLD | NEW |