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

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

Issue 2287733002: Switch //components away from base::ListValue::Append(Value*) overload. (Closed)
Patch Set: Test fix Created 4 years, 3 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
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 11
11 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "components/bookmarks/browser/bookmark_model.h" 16 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "grit/components_strings.h" 17 #include "grit/components_strings.h"
17 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 value); 108 value);
108 FinalizeChecksum(); 109 FinalizeChecksum();
109 // If either the checksums differ or some IDs were missing/not unique, 110 // If either the checksums differ or some IDs were missing/not unique,
110 // reassign IDs. 111 // reassign IDs.
111 if (!ids_valid_ || computed_checksum() != stored_checksum()) 112 if (!ids_valid_ || computed_checksum() != stored_checksum())
112 ReassignIDs(bb_node, other_folder_node, mobile_folder_node); 113 ReassignIDs(bb_node, other_folder_node, mobile_folder_node);
113 *max_id = maximum_id_ + 1; 114 *max_id = maximum_id_ + 1;
114 return success; 115 return success;
115 } 116 }
116 117
117 base::Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { 118 std::unique_ptr<base::Value> BookmarkCodec::EncodeNode(
118 base::DictionaryValue* value = new base::DictionaryValue(); 119 const BookmarkNode* node) {
120 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
119 std::string id = base::Int64ToString(node->id()); 121 std::string id = base::Int64ToString(node->id());
120 value->SetString(kIdKey, id); 122 value->SetString(kIdKey, id);
121 const base::string16& title = node->GetTitle(); 123 const base::string16& title = node->GetTitle();
122 value->SetString(kNameKey, title); 124 value->SetString(kNameKey, title);
123 value->SetString(kDateAddedKey, 125 value->SetString(kDateAddedKey,
124 base::Int64ToString(node->date_added().ToInternalValue())); 126 base::Int64ToString(node->date_added().ToInternalValue()));
125 if (node->is_url()) { 127 if (node->is_url()) {
126 value->SetString(kTypeKey, kTypeURL); 128 value->SetString(kTypeKey, kTypeURL);
127 std::string url = node->url().possibly_invalid_spec(); 129 std::string url = node->url().possibly_invalid_spec();
128 value->SetString(kURLKey, url); 130 value->SetString(kURLKey, url);
(...skipping 11 matching lines...) Expand all
140 child_values->Append(EncodeNode(node->GetChild(i))); 142 child_values->Append(EncodeNode(node->GetChild(i)));
141 } 143 }
142 const BookmarkNode::MetaInfoMap* meta_info_map = node->GetMetaInfoMap(); 144 const BookmarkNode::MetaInfoMap* meta_info_map = node->GetMetaInfoMap();
143 if (meta_info_map) 145 if (meta_info_map)
144 value->Set(kMetaInfo, EncodeMetaInfo(*meta_info_map)); 146 value->Set(kMetaInfo, EncodeMetaInfo(*meta_info_map));
145 if (node->sync_transaction_version() != 147 if (node->sync_transaction_version() !=
146 BookmarkNode::kInvalidSyncTransactionVersion) { 148 BookmarkNode::kInvalidSyncTransactionVersion) {
147 value->SetString(kSyncTransactionVersion, 149 value->SetString(kSyncTransactionVersion,
148 base::Int64ToString(node->sync_transaction_version())); 150 base::Int64ToString(node->sync_transaction_version()));
149 } 151 }
150 return value; 152 return std::move(value);
blundell 2016/08/29 07:39:15 just to verify my own understanding of how this st
dcheng 2016/08/30 17:41:55 It is, because the type of the local doesn't match
151 } 153 }
152 154
153 base::Value* BookmarkCodec::EncodeMetaInfo( 155 base::Value* BookmarkCodec::EncodeMetaInfo(
154 const BookmarkNode::MetaInfoMap& meta_info_map) { 156 const BookmarkNode::MetaInfoMap& meta_info_map) {
155 base::DictionaryValue* meta_info = new base::DictionaryValue; 157 base::DictionaryValue* meta_info = new base::DictionaryValue;
156 for (BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.begin(); 158 for (BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.begin();
157 it != meta_info_map.end(); ++it) { 159 it != meta_info_map.end(); ++it) {
158 meta_info->SetStringWithoutPathExpansion(it->first, it->second); 160 meta_info->SetStringWithoutPathExpansion(it->first, it->second);
159 } 161 }
160 return meta_info; 162 return meta_info;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 base::MD5Init(&md5_context_); 485 base::MD5Init(&md5_context_);
484 } 486 }
485 487
486 void BookmarkCodec::FinalizeChecksum() { 488 void BookmarkCodec::FinalizeChecksum() {
487 base::MD5Digest digest; 489 base::MD5Digest digest;
488 base::MD5Final(&digest, &md5_context_); 490 base::MD5Final(&digest, &md5_context_);
489 computed_checksum_ = base::MD5DigestToBase16(digest); 491 computed_checksum_ = base::MD5DigestToBase16(digest);
490 } 492 }
491 493
492 } // namespace bookmarks 494 } // namespace bookmarks
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698