Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: content/browser/download/download_item_impl.cc

Issue 10665049: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 const char* DebugDownloadStateString(DownloadItem::DownloadState state) { 82 const char* DebugDownloadStateString(DownloadItem::DownloadState state) {
83 switch (state) { 83 switch (state) {
84 case DownloadItem::IN_PROGRESS: 84 case DownloadItem::IN_PROGRESS:
85 return "IN_PROGRESS"; 85 return "IN_PROGRESS";
86 case DownloadItem::COMPLETE: 86 case DownloadItem::COMPLETE:
87 return "COMPLETE"; 87 return "COMPLETE";
88 case DownloadItem::CANCELLED: 88 case DownloadItem::CANCELLED:
89 return "CANCELLED"; 89 return "CANCELLED";
90 case DownloadItem::REMOVING:
91 return "REMOVING";
92 case DownloadItem::INTERRUPTED: 90 case DownloadItem::INTERRUPTED:
93 return "INTERRUPTED"; 91 return "INTERRUPTED";
94 default: 92 default:
95 NOTREACHED() << "Unknown download state " << state; 93 NOTREACHED() << "Unknown download state " << state;
96 return "unknown"; 94 return "unknown";
97 }; 95 };
98 } 96 }
99 97
100 // Classes to null out request handle calls (for SavePage DownloadItems, which 98 // Classes to null out request handle calls (for SavePage DownloadItems, which
101 // may have, e.g., Cancel() called on them without it doing anything) 99 // may have, e.g., Cancel() called on them without it doing anything)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 has_user_gesture_(false), 154 has_user_gesture_(false),
157 total_bytes_(info.total_bytes), 155 total_bytes_(info.total_bytes),
158 received_bytes_(info.received_bytes), 156 received_bytes_(info.received_bytes),
159 bytes_per_sec_(0), 157 bytes_per_sec_(0),
160 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 158 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
161 start_tick_(base::TimeTicks()), 159 start_tick_(base::TimeTicks()),
162 state_(static_cast<DownloadState>(info.state)), 160 state_(static_cast<DownloadState>(info.state)),
163 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 161 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
164 start_time_(info.start_time), 162 start_time_(info.start_time),
165 end_time_(info.end_time), 163 end_time_(info.end_time),
166 db_handle_(info.db_handle),
167 delegate_(delegate), 164 delegate_(delegate),
168 is_paused_(false), 165 is_paused_(false),
169 open_when_complete_(false), 166 open_when_complete_(false),
170 file_externally_removed_(false), 167 file_externally_removed_(false),
171 safety_state_(SAFE), 168 safety_state_(SAFE),
172 auto_opened_(false), 169 auto_opened_(false),
173 is_persisted_(true),
174 is_otr_(false), 170 is_otr_(false),
175 is_temporary_(false), 171 is_temporary_(false),
176 all_data_saved_(false), 172 all_data_saved_(false),
177 opened_(info.opened), 173 opened_(info.opened),
178 open_enabled_(true), 174 open_enabled_(true),
179 delegate_delayed_complete_(false), 175 delegate_delayed_complete_(false),
180 bound_net_log_(bound_net_log), 176 bound_net_log_(bound_net_log),
181 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 177 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
182 delegate_->Attach(); 178 delegate_->Attach();
183 if (IsInProgress()) 179 if (IsInProgress())
(...skipping 28 matching lines...) Expand all
212 referrer_charset_(info.referrer_charset), 208 referrer_charset_(info.referrer_charset),
213 remote_address_(info.remote_address), 209 remote_address_(info.remote_address),
214 total_bytes_(info.total_bytes), 210 total_bytes_(info.total_bytes),
215 received_bytes_(0), 211 received_bytes_(0),
216 bytes_per_sec_(0), 212 bytes_per_sec_(0),
217 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 213 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
218 start_tick_(base::TimeTicks::Now()), 214 start_tick_(base::TimeTicks::Now()),
219 state_(IN_PROGRESS), 215 state_(IN_PROGRESS),
220 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 216 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
221 start_time_(info.start_time), 217 start_time_(info.start_time),
222 db_handle_(DownloadItem::kUninitializedHandle),
223 delegate_(delegate), 218 delegate_(delegate),
224 is_paused_(false), 219 is_paused_(false),
225 open_when_complete_(false), 220 open_when_complete_(false),
226 file_externally_removed_(false), 221 file_externally_removed_(false),
227 safety_state_(SAFE), 222 safety_state_(SAFE),
228 auto_opened_(false), 223 auto_opened_(false),
229 is_persisted_(false),
230 is_otr_(is_otr), 224 is_otr_(is_otr),
231 is_temporary_(!info.save_info.file_path.empty()), 225 is_temporary_(!info.save_info.file_path.empty()),
232 all_data_saved_(false), 226 all_data_saved_(false),
233 opened_(false), 227 opened_(false),
234 open_enabled_(true), 228 open_enabled_(true),
235 delegate_delayed_complete_(false), 229 delegate_delayed_complete_(false),
236 bound_net_log_(bound_net_log), 230 bound_net_log_(bound_net_log),
237 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 231 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
238 delegate_->Attach(); 232 delegate_->Attach();
239 Init(true /* actively downloading */, 233 Init(true /* actively downloading */,
(...skipping 29 matching lines...) Expand all
269 mime_type_(mime_type), 263 mime_type_(mime_type),
270 original_mime_type_(mime_type), 264 original_mime_type_(mime_type),
271 total_bytes_(0), 265 total_bytes_(0),
272 received_bytes_(0), 266 received_bytes_(0),
273 bytes_per_sec_(0), 267 bytes_per_sec_(0),
274 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE), 268 last_reason_(content::DOWNLOAD_INTERRUPT_REASON_NONE),
275 start_tick_(base::TimeTicks::Now()), 269 start_tick_(base::TimeTicks::Now()),
276 state_(IN_PROGRESS), 270 state_(IN_PROGRESS),
277 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 271 danger_type_(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
278 start_time_(base::Time::Now()), 272 start_time_(base::Time::Now()),
279 db_handle_(DownloadItem::kUninitializedHandle),
280 delegate_(delegate), 273 delegate_(delegate),
281 is_paused_(false), 274 is_paused_(false),
282 open_when_complete_(false), 275 open_when_complete_(false),
283 file_externally_removed_(false), 276 file_externally_removed_(false),
284 safety_state_(SAFE), 277 safety_state_(SAFE),
285 auto_opened_(false), 278 auto_opened_(false),
286 is_persisted_(false),
287 is_otr_(is_otr), 279 is_otr_(is_otr),
288 is_temporary_(false), 280 is_temporary_(false),
289 all_data_saved_(false), 281 all_data_saved_(false),
290 opened_(false), 282 opened_(false),
291 open_enabled_(true), 283 open_enabled_(true),
292 delegate_delayed_complete_(false), 284 delegate_delayed_complete_(false),
293 bound_net_log_(bound_net_log), 285 bound_net_log_(bound_net_log),
294 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 286 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
295 delegate_->Attach(); 287 delegate_->Attach();
296 Init(true /* actively downloading */, 288 Init(true /* actively downloading */,
297 download_net_logs::SRC_SAVE_PAGE_AS); 289 download_net_logs::SRC_SAVE_PAGE_AS);
298 } 290 }
299 291
300 DownloadItemImpl::~DownloadItemImpl() { 292 DownloadItemImpl::~DownloadItemImpl() {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
302 294 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadDestroyed(this));
303 TransitionTo(REMOVING);
304 STLDeleteContainerPairSecondPointers(
305 external_data_map_.begin(), external_data_map_.end());
306 delegate_->AssertStateConsistent(this); 295 delegate_->AssertStateConsistent(this);
307 delegate_->Detach(); 296 delegate_->Detach();
308 } 297 }
309 298
310 void DownloadItemImpl::AddObserver(Observer* observer) { 299 void DownloadItemImpl::AddObserver(Observer* observer) {
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
312 301
313 observers_.AddObserver(observer); 302 observers_.AddObserver(observer);
314 } 303 }
315 304
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // We have now been deleted. 636 // We have now been deleted.
648 } 637 }
649 638
650 void DownloadItemImpl::Remove() { 639 void DownloadItemImpl::Remove() {
651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
652 641
653 delegate_->AssertStateConsistent(this); 642 delegate_->AssertStateConsistent(this);
654 Cancel(true); 643 Cancel(true);
655 delegate_->AssertStateConsistent(this); 644 delegate_->AssertStateConsistent(this);
656 645
657 TransitionTo(REMOVING); 646 NotifyRemoved();
658 delegate_->DownloadRemoved(this); 647 delegate_->DownloadRemoved(this);
659 // We have now been deleted. 648 // We have now been deleted.
660 } 649 }
661 650
651 void DownloadItemImpl::NotifyRemoved() {
652 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadRemoved(this));
653 }
654
662 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { 655 bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
663 if (total_bytes_ <= 0) 656 if (total_bytes_ <= 0)
664 return false; // We never received the content_length for this download. 657 return false; // We never received the content_length for this download.
665 658
666 int64 speed = CurrentSpeed(); 659 int64 speed = CurrentSpeed();
667 if (speed == 0) 660 if (speed == 0)
668 return false; 661 return false;
669 662
670 *remaining = base::TimeDelta::FromSeconds( 663 *remaining = base::TimeDelta::FromSeconds(
671 (total_bytes_ - received_bytes_) / speed); 664 (total_bytes_ - received_bytes_) / speed);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 return (danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || 813 return (danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
821 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL || 814 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
822 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT || 815 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
823 danger_type_ == content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT); 816 danger_type_ == content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
824 #else 817 #else
825 return (danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE || 818 return (danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
826 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 819 danger_type_ == content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
827 #endif 820 #endif
828 } 821 }
829 822
830 DownloadPersistentStoreInfo DownloadItemImpl::GetPersistentStoreInfo() const {
831 // TODO(asanka): Persist GetTargetFilePath() as well.
832 return DownloadPersistentStoreInfo(GetFullPath(),
833 GetURL(),
834 GetReferrerUrl(),
835 GetStartTime(),
836 GetEndTime(),
837 GetReceivedBytes(),
838 GetTotalBytes(),
839 GetState(),
840 GetDbHandle(),
841 GetOpened());
842 }
843
844 WebContents* DownloadItemImpl::GetWebContents() const { 823 WebContents* DownloadItemImpl::GetWebContents() const {
845 // TODO(rdsmith): Remove null check after removing GetWebContents() from 824 // TODO(rdsmith): Remove null check after removing GetWebContents() from
846 // paths that might be used by DownloadItems created from history import. 825 // paths that might be used by DownloadItems created from history import.
847 // Currently such items have null request_handle_s, where other items 826 // Currently such items have null request_handle_s, where other items
848 // (regular and SavePackage downloads) have actual objects off the pointer. 827 // (regular and SavePackage downloads) have actual objects off the pointer.
849 if (request_handle_.get()) 828 if (request_handle_.get())
850 return request_handle_->GetWebContents(); 829 return request_handle_->GetWebContents();
851 return NULL; 830 return NULL;
852 } 831 }
853 832
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 944
966 bound_net_log_.BeginEvent( 945 bound_net_log_.BeginEvent(
967 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE, 946 net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE,
968 base::Bind(&download_net_logs::ItemActivatedCallback, 947 base::Bind(&download_net_logs::ItemActivatedCallback,
969 this, download_type, &file_name)); 948 this, download_type, &file_name));
970 949
971 // If this is not an active download, end the ACTIVE event now. 950 // If this is not an active download, end the ACTIVE event now.
972 if (!active) { 951 if (!active) {
973 bound_net_log_.AddEvent( 952 bound_net_log_.AddEvent(
974 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY, 953 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
975 net::NetLog::Int64Callback("db_handle", db_handle_)); 954 net::NetLog::Int64Callback("id", GetId()));
976 955
977 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE); 956 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_ITEM_ACTIVE);
978 } 957 }
979 958
980 VLOG(20) << __FUNCTION__ << "() " << DebugString(true); 959 VLOG(20) << __FUNCTION__ << "() " << DebugString(true);
981 } 960 }
982 961
983 bool DownloadItemImpl::NeedsRename() const { 962 bool DownloadItemImpl::NeedsRename() const {
984 DCHECK(target_path_.DirName() == current_path_.DirName()); 963 DCHECK(target_path_.DirName() == current_path_.DirName());
985 return target_path_ != current_path_; 964 return target_path_ != current_path_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 ++iter; 1008 ++iter;
1030 for ( ; verbose && (iter != last); ++iter) { 1009 for ( ; verbose && (iter != last); ++iter) {
1031 url_list += " ->\n\t"; 1010 url_list += " ->\n\t";
1032 const GURL& next_url = *iter; 1011 const GURL& next_url = *iter;
1033 url_list += next_url.spec(); 1012 url_list += next_url.spec();
1034 } 1013 }
1035 } 1014 }
1036 1015
1037 if (verbose) { 1016 if (verbose) {
1038 description += base::StringPrintf( 1017 description += base::StringPrintf(
1039 " db_handle = %" PRId64
1040 " total = %" PRId64 1018 " total = %" PRId64
1041 " received = %" PRId64 1019 " received = %" PRId64
1042 " reason = %s" 1020 " reason = %s"
1043 " paused = %c" 1021 " paused = %c"
1044 " otr = %c" 1022 " otr = %c"
1045 " safety = %s" 1023 " safety = %s"
1046 " last_modified = '%s'" 1024 " last_modified = '%s'"
1047 " etag = '%s'" 1025 " etag = '%s'"
1048 " url_chain = \n\t\"%s\"\n\t" 1026 " url_chain = \n\t\"%s\"\n\t"
1049 " full_path = \"%" PRFilePath "\"" 1027 " full_path = \"%" PRFilePath "\""
1050 " target_path = \"%" PRFilePath "\"", 1028 " target_path = \"%" PRFilePath "\"",
1051 GetDbHandle(),
1052 GetTotalBytes(), 1029 GetTotalBytes(),
1053 GetReceivedBytes(), 1030 GetReceivedBytes(),
1054 InterruptReasonDebugString(last_reason_).c_str(), 1031 InterruptReasonDebugString(last_reason_).c_str(),
1055 IsPaused() ? 'T' : 'F', 1032 IsPaused() ? 'T' : 'F',
1056 IsOtr() ? 'T' : 'F', 1033 IsOtr() ? 'T' : 'F',
1057 DebugSafetyStateString(GetSafetyState()), 1034 DebugSafetyStateString(GetSafetyState()),
1058 GetLastModifiedTime().c_str(), 1035 GetLastModifiedTime().c_str(),
1059 GetETag().c_str(), 1036 GetETag().c_str(),
1060 url_list.c_str(), 1037 url_list.c_str(),
1061 GetFullPath().value().c_str(), 1038 GetFullPath().value().c_str(),
1062 GetTargetFilePath().value().c_str()); 1039 GetTargetFilePath().value().c_str());
1063 } else { 1040 } else {
1064 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 1041 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
1065 } 1042 }
1066 1043
1067 description += " }"; 1044 description += " }";
1068 1045
1069 return description; 1046 return description;
1070 } 1047 }
1071 1048
1072 bool DownloadItemImpl::AllDataSaved() const { return all_data_saved_; } 1049 bool DownloadItemImpl::AllDataSaved() const { return all_data_saved_; }
1050
1073 DownloadItem::DownloadState DownloadItemImpl::GetState() const { 1051 DownloadItem::DownloadState DownloadItemImpl::GetState() const {
1074 return state_; 1052 return state_;
1075 } 1053 }
1054
1076 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const { 1055 const std::vector<GURL>& DownloadItemImpl::GetUrlChain() const {
1077 return url_chain_; 1056 return url_chain_;
1078 } 1057 }
1058
1079 const GURL& DownloadItemImpl::GetOriginalUrl() const { 1059 const GURL& DownloadItemImpl::GetOriginalUrl() const {
1080 return url_chain_.front(); 1060 return url_chain_.front();
1081 } 1061 }
1062
1082 const GURL& DownloadItemImpl::GetReferrerUrl() const { return referrer_url_; } 1063 const GURL& DownloadItemImpl::GetReferrerUrl() const { return referrer_url_; }
1064
1083 std::string DownloadItemImpl::GetSuggestedFilename() const { 1065 std::string DownloadItemImpl::GetSuggestedFilename() const {
1084 return suggested_filename_; 1066 return suggested_filename_;
1085 } 1067 }
1068
1086 std::string DownloadItemImpl::GetContentDisposition() const { 1069 std::string DownloadItemImpl::GetContentDisposition() const {
1087 return content_disposition_; 1070 return content_disposition_;
1088 } 1071 }
1072
1089 std::string DownloadItemImpl::GetMimeType() const { return mime_type_; } 1073 std::string DownloadItemImpl::GetMimeType() const { return mime_type_; }
1074
1090 std::string DownloadItemImpl::GetOriginalMimeType() const { 1075 std::string DownloadItemImpl::GetOriginalMimeType() const {
1091 return original_mime_type_; 1076 return original_mime_type_;
1092 } 1077 }
1078
1093 std::string DownloadItemImpl::GetReferrerCharset() const { 1079 std::string DownloadItemImpl::GetReferrerCharset() const {
1094 return referrer_charset_; 1080 return referrer_charset_;
1095 } 1081 }
1082
1096 std::string DownloadItemImpl::GetRemoteAddress() const { 1083 std::string DownloadItemImpl::GetRemoteAddress() const {
1097 return remote_address_; 1084 return remote_address_;
1098 } 1085 }
1086
1099 int64 DownloadItemImpl::GetTotalBytes() const { return total_bytes_; } 1087 int64 DownloadItemImpl::GetTotalBytes() const { return total_bytes_; }
1088
1100 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { 1089 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) {
1101 total_bytes_ = total_bytes; 1090 total_bytes_ = total_bytes;
1102 } 1091 }
1092
1103 const std::string& DownloadItemImpl::GetHash() const { return hash_; } 1093 const std::string& DownloadItemImpl::GetHash() const { return hash_; }
1094
1104 int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; } 1095 int64 DownloadItemImpl::GetReceivedBytes() const { return received_bytes_; }
1096
1105 const std::string& DownloadItemImpl::GetHashState() const { 1097 const std::string& DownloadItemImpl::GetHashState() const {
1106 return hash_state_; 1098 return hash_state_;
1107 } 1099 }
1100
1108 int32 DownloadItemImpl::GetId() const { return download_id_.local(); } 1101 int32 DownloadItemImpl::GetId() const { return download_id_.local(); }
1102
1109 DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; } 1103 DownloadId DownloadItemImpl::GetGlobalId() const { return download_id_; }
1104
1110 base::Time DownloadItemImpl::GetStartTime() const { return start_time_; } 1105 base::Time DownloadItemImpl::GetStartTime() const { return start_time_; }
1106
1111 base::Time DownloadItemImpl::GetEndTime() const { return end_time_; } 1107 base::Time DownloadItemImpl::GetEndTime() const { return end_time_; }
1112 1108
1113 void DownloadItemImpl::SetIsPersisted() { 1109 bool DownloadItemImpl::IsPaused() const { return is_paused_; }
1114 is_persisted_ = true;
1115 }
1116 1110
1117 bool DownloadItemImpl::IsPersisted() const {
1118 return is_persisted_;
1119 }
1120
1121 void DownloadItemImpl::SetDbHandle(int64 handle) {
1122 db_handle_ = handle;
1123
1124 bound_net_log_.AddEvent(
1125 net::NetLog::TYPE_DOWNLOAD_ITEM_IN_HISTORY,
1126 net::NetLog::Int64Callback("db_handle", db_handle_));
1127 }
1128
1129 int64 DownloadItemImpl::GetDbHandle() const { return db_handle_; }
1130 bool DownloadItemImpl::IsPaused() const { return is_paused_; }
1131 bool DownloadItemImpl::GetOpenWhenComplete() const { 1111 bool DownloadItemImpl::GetOpenWhenComplete() const {
1132 return open_when_complete_; 1112 return open_when_complete_;
1133 } 1113 }
1114
1134 void DownloadItemImpl::SetOpenWhenComplete(bool open) { 1115 void DownloadItemImpl::SetOpenWhenComplete(bool open) {
1135 open_when_complete_ = open; 1116 open_when_complete_ = open;
1136 } 1117 }
1118
1137 bool DownloadItemImpl::GetFileExternallyRemoved() const { 1119 bool DownloadItemImpl::GetFileExternallyRemoved() const {
1138 return file_externally_removed_; 1120 return file_externally_removed_;
1139 } 1121 }
1122
1140 DownloadItem::SafetyState DownloadItemImpl::GetSafetyState() const { 1123 DownloadItem::SafetyState DownloadItemImpl::GetSafetyState() const {
1141 return safety_state_; 1124 return safety_state_;
1142 } 1125 }
1126
1143 bool DownloadItemImpl::IsOtr() const { return is_otr_; } 1127 bool DownloadItemImpl::IsOtr() const { return is_otr_; }
1128
1144 bool DownloadItemImpl::GetAutoOpened() { return auto_opened_; } 1129 bool DownloadItemImpl::GetAutoOpened() { return auto_opened_; }
1130
1145 FilePath DownloadItemImpl::GetTargetName() const { 1131 FilePath DownloadItemImpl::GetTargetName() const {
1146 return target_path_.BaseName(); 1132 return target_path_.BaseName();
1147 } 1133 }
1134
1148 const FilePath& DownloadItemImpl::GetForcedFilePath() const { 1135 const FilePath& DownloadItemImpl::GetForcedFilePath() const {
1149 // TODO(asanka): Get rid of GetForcedFilePath(). We should instead just 1136 // TODO(asanka): Get rid of GetForcedFilePath(). We should instead just
1150 // require that clients respect GetTargetFilePath() if it is already set. 1137 // require that clients respect GetTargetFilePath() if it is already set.
1151 return forced_file_path_; 1138 return forced_file_path_;
1152 } 1139 }
1140
1153 bool DownloadItemImpl::HasUserGesture() const { 1141 bool DownloadItemImpl::HasUserGesture() const {
1154 return has_user_gesture_; 1142 return has_user_gesture_;
1155 }; 1143 };
1144
1156 content::PageTransition DownloadItemImpl::GetTransitionType() const { 1145 content::PageTransition DownloadItemImpl::GetTransitionType() const {
1157 return transition_type_; 1146 return transition_type_;
1158 }; 1147 };
1148
1159 bool DownloadItemImpl::IsTemporary() const { return is_temporary_; } 1149 bool DownloadItemImpl::IsTemporary() const { return is_temporary_; }
1150
1160 void DownloadItemImpl::SetIsTemporary(bool temporary) { 1151 void DownloadItemImpl::SetIsTemporary(bool temporary) {
1161 is_temporary_ = temporary; 1152 is_temporary_ = temporary;
1162 } 1153 }
1154
1163 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } 1155 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; }
1156
1164 bool DownloadItemImpl::GetOpened() const { return opened_; } 1157 bool DownloadItemImpl::GetOpened() const { return opened_; }
1158
1165 const std::string& DownloadItemImpl::GetLastModifiedTime() const { 1159 const std::string& DownloadItemImpl::GetLastModifiedTime() const {
1166 return last_modified_time_; 1160 return last_modified_time_;
1167 } 1161 }
1162
1168 const std::string& DownloadItemImpl::GetETag() const { return etag_; } 1163 const std::string& DownloadItemImpl::GetETag() const { return etag_; }
1164
1169 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const { 1165 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const {
1170 return last_reason_; 1166 return last_reason_;
1171 } 1167 }
1168
1172 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } 1169 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; }
1173
1174 DownloadItem::ExternalData*
1175 DownloadItemImpl::GetExternalData(const void* key) {
1176 // The behavior of the const overload is identical with the exception of the
1177 // constness of |this| and the return value.
1178 return const_cast<DownloadItem::ExternalData*>(
1179 static_cast<const DownloadItemImpl&>(*this).GetExternalData(key));
1180 }
1181
1182 const DownloadItem::ExternalData*
1183 DownloadItemImpl::GetExternalData(const void* key) const {
1184 std::map<const void*, ExternalData*>::const_iterator it =
1185 external_data_map_.find(key);
1186 return (it == external_data_map_.end()) ? NULL : it->second;
1187 }
1188
1189 void DownloadItemImpl::SetExternalData(
1190 const void* key, DownloadItem::ExternalData* data) {
1191 std::map<const void*, ExternalData*>::iterator it =
1192 external_data_map_.find(key);
1193
1194 if (it == external_data_map_.end()) {
1195 external_data_map_[key] = data;
1196 } else if (it->second != data) {
1197 delete it->second;
1198 it->second = data;
1199 }
1200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698