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

Side by Side Diff: chrome/browser/sync/glue/preference_model_associator.cc

Issue 6324004: Made return types of various Value::DeepCopy() implementations more specific (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test for covariant return types Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/sync/glue/preference_model_associator.h" 5 #include "chrome/browser/sync/glue/preference_model_associator.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 const Value& to_value) { 256 const Value& to_value) {
257 if (from_value.GetType() == Value::TYPE_NULL) 257 if (from_value.GetType() == Value::TYPE_NULL)
258 return to_value.DeepCopy(); 258 return to_value.DeepCopy();
259 if (to_value.GetType() == Value::TYPE_NULL) 259 if (to_value.GetType() == Value::TYPE_NULL)
260 return from_value.DeepCopy(); 260 return from_value.DeepCopy();
261 261
262 DCHECK(from_value.GetType() == Value::TYPE_LIST); 262 DCHECK(from_value.GetType() == Value::TYPE_LIST);
263 DCHECK(to_value.GetType() == Value::TYPE_LIST); 263 DCHECK(to_value.GetType() == Value::TYPE_LIST);
264 const ListValue& from_list_value = static_cast<const ListValue&>(from_value); 264 const ListValue& from_list_value = static_cast<const ListValue&>(from_value);
265 const ListValue& to_list_value = static_cast<const ListValue&>(to_value); 265 const ListValue& to_list_value = static_cast<const ListValue&>(to_value);
266 ListValue* result = static_cast<ListValue*>(to_list_value.DeepCopy()); 266 ListValue* result = to_list_value.DeepCopy();
267 267
268 for (ListValue::const_iterator i = from_list_value.begin(); 268 for (ListValue::const_iterator i = from_list_value.begin();
269 i != from_list_value.end(); ++i) { 269 i != from_list_value.end(); ++i) {
270 Value* value = (*i)->DeepCopy(); 270 Value* value = (*i)->DeepCopy();
271 if (!result->AppendIfNotPresent(value)) 271 if (!result->AppendIfNotPresent(value))
272 delete value; 272 delete value;
273 } 273 }
274 return result; 274 return result;
275 } 275 }
276 276
277 Value* PreferenceModelAssociator::MergeDictionaryValues( 277 Value* PreferenceModelAssociator::MergeDictionaryValues(
278 const Value& from_value, 278 const Value& from_value,
279 const Value& to_value) { 279 const Value& to_value) {
280 if (from_value.GetType() == Value::TYPE_NULL) 280 if (from_value.GetType() == Value::TYPE_NULL)
281 return to_value.DeepCopy(); 281 return to_value.DeepCopy();
282 if (to_value.GetType() == Value::TYPE_NULL) 282 if (to_value.GetType() == Value::TYPE_NULL)
283 return from_value.DeepCopy(); 283 return from_value.DeepCopy();
284 284
285 DCHECK(from_value.GetType() == Value::TYPE_DICTIONARY); 285 DCHECK(from_value.GetType() == Value::TYPE_DICTIONARY);
286 DCHECK(to_value.GetType() == Value::TYPE_DICTIONARY); 286 DCHECK(to_value.GetType() == Value::TYPE_DICTIONARY);
287 const DictionaryValue& from_dict_value = 287 const DictionaryValue& from_dict_value =
288 static_cast<const DictionaryValue&>(from_value); 288 static_cast<const DictionaryValue&>(from_value);
289 const DictionaryValue& to_dict_value = 289 const DictionaryValue& to_dict_value =
290 static_cast<const DictionaryValue&>(to_value); 290 static_cast<const DictionaryValue&>(to_value);
291 DictionaryValue* result = 291 DictionaryValue* result = to_dict_value.DeepCopy();
292 static_cast<DictionaryValue*>(to_dict_value.DeepCopy());
293 292
294 for (DictionaryValue::key_iterator key = from_dict_value.begin_keys(); 293 for (DictionaryValue::key_iterator key = from_dict_value.begin_keys();
295 key != from_dict_value.end_keys(); ++key) { 294 key != from_dict_value.end_keys(); ++key) {
296 Value* from_value; 295 Value* from_value;
297 bool success = from_dict_value.GetWithoutPathExpansion(*key, &from_value); 296 bool success = from_dict_value.GetWithoutPathExpansion(*key, &from_value);
298 DCHECK(success); 297 DCHECK(success);
299 298
300 Value* to_key_value; 299 Value* to_key_value;
301 if (result->GetWithoutPathExpansion(*key, &to_key_value)) { 300 if (result->GetWithoutPathExpansion(*key, &to_key_value)) {
302 if (to_key_value->GetType() == Value::TYPE_DICTIONARY) { 301 if (to_key_value->GetType() == Value::TYPE_DICTIONARY) {
(...skipping 15 matching lines...) Expand all
318 // notification to update the UI. 317 // notification to update the UI.
319 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { 318 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) {
320 NotificationService::current()->Notify( 319 NotificationService::current()->Notify(
321 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 320 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
322 Source<PreferenceModelAssociator>(this), 321 Source<PreferenceModelAssociator>(this),
323 NotificationService::NoDetails()); 322 NotificationService::NoDetails());
324 } 323 }
325 } 324 }
326 325
327 } // namespace browser_sync 326 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_policy_cache.cc ('k') | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698