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

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

Issue 9518008: Add a const overload to DownloadItem::GetExternalData() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "Add a comment explaining the const cast" Created 8 years, 9 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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.h ('k') | content/browser/download/download_item_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698