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 "chrome/browser/download/download_item.h" | 5 #include "chrome/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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 all_data_saved_ = true; | 142 all_data_saved_ = true; |
143 Init(false /* don't start progress timer */); | 143 Init(false /* don't start progress timer */); |
144 } | 144 } |
145 | 145 |
146 // Constructing for a regular download: | 146 // Constructing for a regular download: |
147 DownloadItem::DownloadItem(DownloadManager* download_manager, | 147 DownloadItem::DownloadItem(DownloadManager* download_manager, |
148 const DownloadCreateInfo& info, | 148 const DownloadCreateInfo& info, |
149 bool is_otr) | 149 bool is_otr) |
150 : state_info_(info.original_name, info.save_info.file_path, | 150 : state_info_(info.original_name, info.save_info.file_path, |
151 info.has_user_gesture, info.prompt_user_for_save_location, | 151 info.has_user_gesture, info.prompt_user_for_save_location, |
152 info.path_uniquifier, info.is_dangerous_file, | 152 info.path_uniquifier, false, false, |
153 info.is_dangerous_url, info.is_extension_install), | 153 info.is_extension_install), |
154 process_handle_(info.process_handle), | 154 process_handle_(info.process_handle), |
155 download_id_(info.download_id), | 155 download_id_(info.download_id), |
156 full_path_(info.path), | 156 full_path_(info.path), |
157 url_chain_(info.url_chain), | 157 url_chain_(info.url_chain), |
158 referrer_url_(info.referrer_url), | 158 referrer_url_(info.referrer_url), |
159 content_disposition_(info.content_disposition), | 159 content_disposition_(info.content_disposition), |
160 mime_type_(info.mime_type), | 160 mime_type_(info.mime_type), |
161 original_mime_type_(info.original_mime_type), | 161 original_mime_type_(info.original_mime_type), |
162 referrer_charset_(info.referrer_charset), | 162 referrer_charset_(info.referrer_charset), |
163 total_bytes_(info.total_bytes), | 163 total_bytes_(info.total_bytes), |
164 received_bytes_(0), | 164 received_bytes_(0), |
165 last_os_error_(0), | 165 last_os_error_(0), |
166 start_tick_(base::TimeTicks::Now()), | 166 start_tick_(base::TimeTicks::Now()), |
167 state_(IN_PROGRESS), | 167 state_(IN_PROGRESS), |
168 start_time_(info.start_time), | 168 start_time_(info.start_time), |
169 db_handle_(DownloadHistory::kUninitializedHandle), | 169 db_handle_(DownloadHistory::kUninitializedHandle), |
170 download_manager_(download_manager), | 170 download_manager_(download_manager), |
171 is_paused_(false), | 171 is_paused_(false), |
172 open_when_complete_(false), | 172 open_when_complete_(false), |
173 safety_state_(GetSafetyState(info.is_dangerous_file, | 173 safety_state_(SAFE), |
174 info.is_dangerous_url)), | |
175 auto_opened_(false), | 174 auto_opened_(false), |
176 is_otr_(is_otr), | 175 is_otr_(is_otr), |
177 is_temporary_(!info.save_info.file_path.empty()), | 176 is_temporary_(!info.save_info.file_path.empty()), |
178 all_data_saved_(false), | 177 all_data_saved_(false), |
179 opened_(false) { | 178 opened_(false) { |
180 Init(true /* start progress timer */); | 179 Init(true /* start progress timer */); |
181 } | 180 } |
182 | 181 |
183 // Constructing for the "Save Page As..." feature: | 182 // Constructing for the "Save Page As..." feature: |
184 DownloadItem::DownloadItem(DownloadManager* download_manager, | 183 DownloadItem::DownloadItem(DownloadManager* download_manager, |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 533 |
535 DownloadItem::DangerType DownloadItem::GetDangerType() const { | 534 DownloadItem::DangerType DownloadItem::GetDangerType() const { |
536 return ::GetDangerType(state_info_.is_dangerous_file, | 535 return ::GetDangerType(state_info_.is_dangerous_file, |
537 state_info_.is_dangerous_url); | 536 state_info_.is_dangerous_url); |
538 } | 537 } |
539 | 538 |
540 bool DownloadItem::IsDangerous() const { | 539 bool DownloadItem::IsDangerous() const { |
541 return GetDangerType() != DownloadItem::NOT_DANGEROUS; | 540 return GetDangerType() != DownloadItem::NOT_DANGEROUS; |
542 } | 541 } |
543 | 542 |
| 543 void DownloadItem::MarkFileDangerous() { |
| 544 state_info_.is_dangerous_file = true; |
| 545 safety_state_ = GetSafetyState(state_info_.is_dangerous_file, |
| 546 state_info_.is_dangerous_url); |
| 547 } |
| 548 |
544 void DownloadItem::MarkUrlDangerous() { | 549 void DownloadItem::MarkUrlDangerous() { |
545 state_info_.is_dangerous_url = true; | 550 state_info_.is_dangerous_url = true; |
| 551 safety_state_ = GetSafetyState(state_info_.is_dangerous_file, |
| 552 state_info_.is_dangerous_url); |
546 } | 553 } |
547 | 554 |
548 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const { | 555 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const { |
549 return DownloadHistoryInfo(full_path(), | 556 return DownloadHistoryInfo(full_path(), |
550 GetURL(), | 557 GetURL(), |
551 referrer_url(), | 558 referrer_url(), |
552 start_time(), | 559 start_time(), |
553 received_bytes(), | 560 received_bytes(), |
554 total_bytes(), | 561 total_bytes(), |
555 state(), | 562 state(), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 state_info_.target_name.value().c_str(), | 658 state_info_.target_name.value().c_str(), |
652 full_path().value().c_str()); | 659 full_path().value().c_str()); |
653 } else { | 660 } else { |
654 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); | 661 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
655 } | 662 } |
656 | 663 |
657 description += " }"; | 664 description += " }"; |
658 | 665 |
659 return description; | 666 return description; |
660 } | 667 } |
OLD | NEW |