OLD | NEW |
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 Loading... |
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 Loading... |
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); |
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 Loading... |
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 |
OLD | NEW |