| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 state_(static_cast<DownloadState>(info.state)), | 128 state_(static_cast<DownloadState>(info.state)), |
| 129 start_time_(info.start_time), | 129 start_time_(info.start_time), |
| 130 db_handle_(info.db_handle), | 130 db_handle_(info.db_handle), |
| 131 download_manager_(download_manager), | 131 download_manager_(download_manager), |
| 132 is_paused_(false), | 132 is_paused_(false), |
| 133 open_when_complete_(false), | 133 open_when_complete_(false), |
| 134 safety_state_(SAFE), | 134 safety_state_(SAFE), |
| 135 danger_type_(NOT_DANGEROUS), | 135 danger_type_(NOT_DANGEROUS), |
| 136 auto_opened_(false), | 136 auto_opened_(false), |
| 137 target_name_(info.original_name), | 137 target_name_(info.original_name), |
| 138 render_process_id_(-1), | |
| 139 request_id_(-1), | |
| 140 save_as_(false), | 138 save_as_(false), |
| 141 is_otr_(false), | 139 is_otr_(false), |
| 142 is_extension_install_(info.is_extension_install), | 140 is_extension_install_(info.is_extension_install), |
| 143 is_temporary_(false), | 141 is_temporary_(false), |
| 144 all_data_saved_(false), | 142 all_data_saved_(false), |
| 145 opened_(false) { | 143 opened_(false) { |
| 146 if (IsInProgress()) | 144 if (IsInProgress()) |
| 147 state_ = CANCELLED; | 145 state_ = CANCELLED; |
| 148 if (IsComplete()) | 146 if (IsComplete()) |
| 149 all_data_saved_ = true; | 147 all_data_saved_ = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 170 db_handle_(DownloadHistory::kUninitializedHandle), | 168 db_handle_(DownloadHistory::kUninitializedHandle), |
| 171 download_manager_(download_manager), | 169 download_manager_(download_manager), |
| 172 is_paused_(false), | 170 is_paused_(false), |
| 173 open_when_complete_(false), | 171 open_when_complete_(false), |
| 174 safety_state_(GetSafetyState(info.is_dangerous_file, | 172 safety_state_(GetSafetyState(info.is_dangerous_file, |
| 175 info.is_dangerous_url)), | 173 info.is_dangerous_url)), |
| 176 danger_type_(GetDangerType(info.is_dangerous_file, | 174 danger_type_(GetDangerType(info.is_dangerous_file, |
| 177 info.is_dangerous_url)), | 175 info.is_dangerous_url)), |
| 178 auto_opened_(false), | 176 auto_opened_(false), |
| 179 target_name_(info.original_name), | 177 target_name_(info.original_name), |
| 180 render_process_id_(info.child_id), | 178 process_handle_(info.process_handle), |
| 181 request_id_(info.request_id), | |
| 182 save_as_(info.prompt_user_for_save_location), | 179 save_as_(info.prompt_user_for_save_location), |
| 183 is_otr_(is_otr), | 180 is_otr_(is_otr), |
| 184 is_extension_install_(info.is_extension_install), | 181 is_extension_install_(info.is_extension_install), |
| 185 is_temporary_(!info.save_info.file_path.empty()), | 182 is_temporary_(!info.save_info.file_path.empty()), |
| 186 all_data_saved_(false), | 183 all_data_saved_(false), |
| 187 opened_(false) { | 184 opened_(false) { |
| 188 Init(true /* start progress timer */); | 185 Init(true /* start progress timer */); |
| 189 } | 186 } |
| 190 | 187 |
| 191 // Constructing for the "Save Page As..." feature: | 188 // Constructing for the "Save Page As..." feature: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 206 start_tick_(base::TimeTicks::Now()), | 203 start_tick_(base::TimeTicks::Now()), |
| 207 state_(IN_PROGRESS), | 204 state_(IN_PROGRESS), |
| 208 start_time_(base::Time::Now()), | 205 start_time_(base::Time::Now()), |
| 209 db_handle_(DownloadHistory::kUninitializedHandle), | 206 db_handle_(DownloadHistory::kUninitializedHandle), |
| 210 download_manager_(download_manager), | 207 download_manager_(download_manager), |
| 211 is_paused_(false), | 208 is_paused_(false), |
| 212 open_when_complete_(false), | 209 open_when_complete_(false), |
| 213 safety_state_(SAFE), | 210 safety_state_(SAFE), |
| 214 danger_type_(NOT_DANGEROUS), | 211 danger_type_(NOT_DANGEROUS), |
| 215 auto_opened_(false), | 212 auto_opened_(false), |
| 216 render_process_id_(-1), | |
| 217 request_id_(-1), | |
| 218 save_as_(false), | 213 save_as_(false), |
| 219 is_otr_(is_otr), | 214 is_otr_(is_otr), |
| 220 is_extension_install_(false), | 215 is_extension_install_(false), |
| 221 is_temporary_(false), | 216 is_temporary_(false), |
| 222 all_data_saved_(false), | 217 all_data_saved_(false), |
| 223 opened_(false) { | 218 opened_(false) { |
| 224 Init(true /* start progress timer */); | 219 Init(true /* start progress timer */); |
| 225 } | 220 } |
| 226 | 221 |
| 227 DownloadItem::~DownloadItem() { | 222 DownloadItem::~DownloadItem() { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 } | 604 } |
| 610 | 605 |
| 611 bool DownloadItem::IsComplete() const { | 606 bool DownloadItem::IsComplete() const { |
| 612 return (state_ == COMPLETE); | 607 return (state_ == COMPLETE); |
| 613 } | 608 } |
| 614 | 609 |
| 615 std::string DownloadItem::DebugString(bool verbose) const { | 610 std::string DownloadItem::DebugString(bool verbose) const { |
| 616 std::string description = base::StringPrintf( | 611 std::string description = base::StringPrintf( |
| 617 "{ id_ = %d state = %s", id_, DebugDownloadStateString(state())); | 612 "{ id_ = %d state = %s", id_, DebugDownloadStateString(state())); |
| 618 | 613 |
| 614 // Construct a string of the URL chain. |
| 615 std::string url_list("<none>"); |
| 616 if (!url_chain_.empty()) { |
| 617 std::vector<GURL>::const_iterator iter = url_chain_.begin(); |
| 618 std::vector<GURL>::const_iterator last = url_chain_.end(); |
| 619 url_list = (*iter).spec(); |
| 620 ++iter; |
| 621 for ( ; verbose && (iter != last); ++iter) { |
| 622 url_list += " -> "; |
| 623 const GURL& next_url = *iter; |
| 624 url_list += next_url.spec(); |
| 625 } |
| 626 } |
| 627 |
| 619 if (verbose) { | 628 if (verbose) { |
| 620 description += base::StringPrintf( | 629 description += base::StringPrintf( |
| 621 " db_handle = %" PRId64 | 630 " db_handle = %" PRId64 |
| 622 " total_bytes = %" PRId64 | 631 " total_bytes = %" PRId64 |
| 623 " is_paused = %c" | 632 " is_paused = " "%c" |
| 624 " is_extension_install = %c" | 633 " is_extension_install = " "%c" |
| 625 " is_otr = %c" | 634 " is_otr = " "%c" |
| 626 " safety_state = %s" | 635 " safety_state = " "%s" |
| 627 " url = \"%s\"" | 636 " url_chain = " "\"%s\"" |
| 628 " target_name_ = \"%" PRFilePath "\"" | 637 " target_name_ = \"%" PRFilePath "\"" |
| 629 " full_path = \"%" PRFilePath "\" }", | 638 " full_path = \"%" PRFilePath "\"", |
| 630 db_handle(), | 639 db_handle(), |
| 631 total_bytes(), | 640 total_bytes(), |
| 632 is_paused() ? 'T' : 'F', | 641 is_paused() ? 'T' : 'F', |
| 633 is_extension_install() ? 'T' : 'F', | 642 is_extension_install() ? 'T' : 'F', |
| 634 is_otr() ? 'T' : 'F', | 643 is_otr() ? 'T' : 'F', |
| 635 DebugSafetyStateString(safety_state()), | 644 DebugSafetyStateString(safety_state()), |
| 636 url().spec().c_str(), | 645 url_list.c_str(), |
| 637 target_name_.value().c_str(), | 646 target_name_.value().c_str(), |
| 638 full_path().value().c_str()); | 647 full_path().value().c_str()); |
| 639 } else { | 648 } else { |
| 640 description += " url = \"" + url().spec() + "\" }"; | 649 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); |
| 641 } | 650 } |
| 642 return description; | 651 return description; |
| 643 } | 652 } |
| OLD | NEW |