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

Side by Side Diff: components/bookmarks/browser/bookmark_codec.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_codec.h" 5 #include "components/bookmarks/browser/bookmark_codec.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const base::DictionaryValue* d_value = nullptr; 170 const base::DictionaryValue* d_value = nullptr;
171 if (!value.GetAsDictionary(&d_value)) 171 if (!value.GetAsDictionary(&d_value))
172 return false; // Unexpected type. 172 return false; // Unexpected type.
173 173
174 int version; 174 int version;
175 if (!d_value->GetInteger(kVersionKey, &version) || version != kCurrentVersion) 175 if (!d_value->GetInteger(kVersionKey, &version) || version != kCurrentVersion)
176 return false; // Unknown version. 176 return false; // Unknown version.
177 177
178 const base::Value* checksum_value; 178 const base::Value* checksum_value;
179 if (d_value->Get(kChecksumKey, &checksum_value)) { 179 if (d_value->Get(kChecksumKey, &checksum_value)) {
180 if (checksum_value->GetType() != base::Value::TYPE_STRING) 180 if (checksum_value->GetType() != base::Value::Type::STRING)
181 return false; 181 return false;
182 if (!checksum_value->GetAsString(&stored_checksum_)) 182 if (!checksum_value->GetAsString(&stored_checksum_))
183 return false; 183 return false;
184 } 184 }
185 185
186 const base::Value* roots; 186 const base::Value* roots;
187 if (!d_value->Get(kRootsKey, &roots)) 187 if (!d_value->Get(kRootsKey, &roots))
188 return false; // No roots. 188 return false; // No roots.
189 189
190 const base::DictionaryValue* roots_d_value = nullptr; 190 const base::DictionaryValue* roots_d_value = nullptr;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 UpdateChecksumWithUrlNode(id_string, title, url_string); 326 UpdateChecksumWithUrlNode(id_string, title, url_string);
327 } else { 327 } else {
328 std::string last_modified_date; 328 std::string last_modified_date;
329 if (!value.GetString(kDateModifiedKey, &last_modified_date)) 329 if (!value.GetString(kDateModifiedKey, &last_modified_date))
330 last_modified_date = base::Int64ToString(Time::Now().ToInternalValue()); 330 last_modified_date = base::Int64ToString(Time::Now().ToInternalValue());
331 331
332 const base::Value* child_values; 332 const base::Value* child_values;
333 if (!value.Get(kChildrenKey, &child_values)) 333 if (!value.Get(kChildrenKey, &child_values))
334 return false; 334 return false;
335 335
336 if (child_values->GetType() != base::Value::TYPE_LIST) 336 if (child_values->GetType() != base::Value::Type::LIST)
337 return false; 337 return false;
338 338
339 if (!node) { 339 if (!node) {
340 node = new BookmarkNode(id, GURL()); 340 node = new BookmarkNode(id, GURL());
341 } else { 341 } else {
342 // If a new node is not created, explicitly assign ID to the existing one. 342 // If a new node is not created, explicitly assign ID to the existing one.
343 node->set_id(id); 343 node->set_id(id);
344 } 344 }
345 345
346 node->set_type(BookmarkNode::FOLDER); 346 node->set_type(BookmarkNode::FOLDER);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 meta_info_map->clear(); 388 meta_info_map->clear();
389 389
390 const base::Value* meta_info; 390 const base::Value* meta_info;
391 if (!value.Get(kMetaInfo, &meta_info)) 391 if (!value.Get(kMetaInfo, &meta_info))
392 return true; 392 return true;
393 393
394 std::unique_ptr<base::Value> deserialized_holder; 394 std::unique_ptr<base::Value> deserialized_holder;
395 395
396 // Meta info used to be stored as a serialized dictionary, so attempt to 396 // Meta info used to be stored as a serialized dictionary, so attempt to
397 // parse the value as one. 397 // parse the value as one.
398 if (meta_info->IsType(base::Value::TYPE_STRING)) { 398 if (meta_info->IsType(base::Value::Type::STRING)) {
399 std::string meta_info_str; 399 std::string meta_info_str;
400 meta_info->GetAsString(&meta_info_str); 400 meta_info->GetAsString(&meta_info_str);
401 JSONStringValueDeserializer deserializer(meta_info_str); 401 JSONStringValueDeserializer deserializer(meta_info_str);
402 deserialized_holder = deserializer.Deserialize(nullptr, nullptr); 402 deserialized_holder = deserializer.Deserialize(nullptr, nullptr);
403 if (!deserialized_holder) 403 if (!deserialized_holder)
404 return false; 404 return false;
405 meta_info = deserialized_holder.get(); 405 meta_info = deserialized_holder.get();
406 } 406 }
407 // meta_info is now either the kMetaInfo node, or the deserialized node if it 407 // meta_info is now either the kMetaInfo node, or the deserialized node if it
408 // was stored as a string. Either way it should now be a (possibly nested) 408 // was stored as a string. Either way it should now be a (possibly nested)
(...skipping 17 matching lines...) Expand all
426 } 426 }
427 427
428 return true; 428 return true;
429 } 429 }
430 430
431 void BookmarkCodec::DecodeMetaInfoHelper( 431 void BookmarkCodec::DecodeMetaInfoHelper(
432 const base::DictionaryValue& dict, 432 const base::DictionaryValue& dict,
433 const std::string& prefix, 433 const std::string& prefix,
434 BookmarkNode::MetaInfoMap* meta_info_map) { 434 BookmarkNode::MetaInfoMap* meta_info_map) {
435 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) { 435 for (base::DictionaryValue::Iterator it(dict); !it.IsAtEnd(); it.Advance()) {
436 if (it.value().IsType(base::Value::TYPE_DICTIONARY)) { 436 if (it.value().IsType(base::Value::Type::DICTIONARY)) {
437 const base::DictionaryValue* subdict; 437 const base::DictionaryValue* subdict;
438 it.value().GetAsDictionary(&subdict); 438 it.value().GetAsDictionary(&subdict);
439 DecodeMetaInfoHelper(*subdict, prefix + it.key() + ".", meta_info_map); 439 DecodeMetaInfoHelper(*subdict, prefix + it.key() + ".", meta_info_map);
440 } else if (it.value().IsType(base::Value::TYPE_STRING)) { 440 } else if (it.value().IsType(base::Value::Type::STRING)) {
441 it.value().GetAsString(&(*meta_info_map)[prefix + it.key()]); 441 it.value().GetAsString(&(*meta_info_map)[prefix + it.key()]);
442 } 442 }
443 } 443 }
444 } 444 }
445 445
446 void BookmarkCodec::ReassignIDs(BookmarkNode* bb_node, 446 void BookmarkCodec::ReassignIDs(BookmarkNode* bb_node,
447 BookmarkNode* other_node, 447 BookmarkNode* other_node,
448 BookmarkNode* mobile_node) { 448 BookmarkNode* mobile_node) {
449 maximum_id_ = 0; 449 maximum_id_ = 0;
450 ReassignIDsHelper(bb_node); 450 ReassignIDsHelper(bb_node);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 base::MD5Init(&md5_context_); 492 base::MD5Init(&md5_context_);
493 } 493 }
494 494
495 void BookmarkCodec::FinalizeChecksum() { 495 void BookmarkCodec::FinalizeChecksum() {
496 base::MD5Digest digest; 496 base::MD5Digest digest;
497 base::MD5Final(&digest, &md5_context_); 497 base::MD5Final(&digest, &md5_context_);
498 computed_checksum_ = base::MD5DigestToBase16(digest); 498 computed_checksum_ = base::MD5DigestToBase16(digest);
499 } 499 }
500 500
501 } // namespace bookmarks 501 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/autofill/core/browser/payments/payments_client.cc ('k') | components/bookmarks/browser/bookmark_codec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698