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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 return last_reason_; | 1124 return last_reason_; |
1125 } | 1125 } |
1126 DownloadStateInfo DownloadItemImpl::GetStateInfo() const { return state_info_; } | 1126 DownloadStateInfo DownloadItemImpl::GetStateInfo() const { return state_info_; } |
1127 bool DownloadItemImpl::NeedsRename() const { | 1127 bool DownloadItemImpl::NeedsRename() const { |
1128 return state_info_.target_name != full_path_.BaseName(); | 1128 return state_info_.target_name != full_path_.BaseName(); |
1129 } | 1129 } |
1130 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } | 1130 void DownloadItemImpl::MockDownloadOpenForTesting() { open_enabled_ = false; } |
1131 | 1131 |
1132 DownloadItem::ExternalData* | 1132 DownloadItem::ExternalData* |
1133 DownloadItemImpl::GetExternalData(const void* key) { | 1133 DownloadItemImpl::GetExternalData(const void* key) { |
1134 if (!ContainsKey(external_data_map_, key)) | 1134 // The behavior of the const overload is identical with the exception of the |
1135 return NULL; | 1135 // constness of |this| and the return value. |
1136 return external_data_map_[key]; | 1136 return const_cast<DownloadItem::ExternalData*>( |
| 1137 static_cast<const DownloadItemImpl&>(*this).GetExternalData(key)); |
| 1138 } |
| 1139 |
| 1140 const DownloadItem::ExternalData* |
| 1141 DownloadItemImpl::GetExternalData(const void* key) const { |
| 1142 std::map<const void*, ExternalData*>::const_iterator it = |
| 1143 external_data_map_.find(key); |
| 1144 return (it == external_data_map_.end()) ? NULL : it->second; |
1137 } | 1145 } |
1138 | 1146 |
1139 void DownloadItemImpl::SetExternalData( | 1147 void DownloadItemImpl::SetExternalData( |
1140 const void* key, DownloadItem::ExternalData* data) { | 1148 const void* key, DownloadItem::ExternalData* data) { |
1141 std::map<const void*, ExternalData*>::iterator it = | 1149 std::map<const void*, ExternalData*>::iterator it = |
1142 external_data_map_.find(key); | 1150 external_data_map_.find(key); |
1143 | 1151 |
1144 if (it == external_data_map_.end()) { | 1152 if (it == external_data_map_.end()) { |
1145 external_data_map_[key] = data; | 1153 external_data_map_[key] = data; |
1146 } else if (it->second != data) { | 1154 } else if (it->second != data) { |
1147 delete it->second; | 1155 delete it->second; |
1148 it->second = data; | 1156 it->second = data; |
1149 } | 1157 } |
1150 } | 1158 } |
OLD | NEW |