OLD | NEW |
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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 294 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
295 delegate_->Attach(); | 295 delegate_->Attach(); |
296 Init(true /* actively downloading */, | 296 Init(true /* actively downloading */, |
297 download_net_logs::SRC_SAVE_PAGE_AS); | 297 download_net_logs::SRC_SAVE_PAGE_AS); |
298 } | 298 } |
299 | 299 |
300 DownloadItemImpl::~DownloadItemImpl() { | 300 DownloadItemImpl::~DownloadItemImpl() { |
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
302 | 302 |
303 TransitionTo(REMOVING); | 303 TransitionTo(REMOVING); |
304 STLDeleteContainerPairSecondPointers( | |
305 external_data_map_.begin(), external_data_map_.end()); | |
306 delegate_->AssertStateConsistent(this); | 304 delegate_->AssertStateConsistent(this); |
307 delegate_->Detach(); | 305 delegate_->Detach(); |
308 } | 306 } |
309 | 307 |
310 void DownloadItemImpl::AddObserver(Observer* observer) { | 308 void DownloadItemImpl::AddObserver(Observer* observer) { |
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
312 | 310 |
313 observers_.AddObserver(observer); | 311 observers_.AddObserver(observer); |
314 } | 312 } |
315 | 313 |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } | 1161 void DownloadItemImpl::SetOpened(bool opened) { opened_ = opened; } |
1164 bool DownloadItemImpl::GetOpened() const { return opened_; } | 1162 bool DownloadItemImpl::GetOpened() const { return opened_; } |
1165 const std::string& DownloadItemImpl::GetLastModifiedTime() const { | 1163 const std::string& DownloadItemImpl::GetLastModifiedTime() const { |
1166 return last_modified_time_; | 1164 return last_modified_time_; |
1167 } | 1165 } |
1168 const std::string& DownloadItemImpl::GetETag() const { return etag_; } | 1166 const std::string& DownloadItemImpl::GetETag() const { return etag_; } |
1169 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const { | 1167 content::DownloadInterruptReason DownloadItemImpl::GetLastReason() const { |
1170 return last_reason_; | 1168 return last_reason_; |
1171 } | 1169 } |
1172 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } | 1170 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 } | |
OLD | NEW |