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: components/bookmarks/browser/bookmark_codec.cc

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 years, 6 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 #include <utility>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 BookmarkCodec::BookmarkCodec() 49 BookmarkCodec::BookmarkCodec()
50 : ids_reassigned_(false), 50 : ids_reassigned_(false),
51 ids_valid_(true), 51 ids_valid_(true),
52 maximum_id_(0), 52 maximum_id_(0),
53 model_sync_transaction_version_( 53 model_sync_transaction_version_(
54 BookmarkNode::kInvalidSyncTransactionVersion) { 54 BookmarkNode::kInvalidSyncTransactionVersion) {
55 } 55 }
56 56
57 BookmarkCodec::~BookmarkCodec() {} 57 BookmarkCodec::~BookmarkCodec() {}
58 58
59 base::Value* BookmarkCodec::Encode(BookmarkModel* model) { 59 std::unique_ptr<base::Value> BookmarkCodec::Encode(BookmarkModel* model) {
60 return Encode(model->bookmark_bar_node(), 60 return Encode(model->bookmark_bar_node(),
61 model->other_node(), 61 model->other_node(),
62 model->mobile_node(), 62 model->mobile_node(),
63 model->root_node()->GetMetaInfoMap(), 63 model->root_node()->GetMetaInfoMap(),
64 model->root_node()->sync_transaction_version()); 64 model->root_node()->sync_transaction_version());
65 } 65 }
66 66
67 base::Value* BookmarkCodec::Encode( 67 std::unique_ptr<base::Value> BookmarkCodec::Encode(
68 const BookmarkNode* bookmark_bar_node, 68 const BookmarkNode* bookmark_bar_node,
69 const BookmarkNode* other_folder_node, 69 const BookmarkNode* other_folder_node,
70 const BookmarkNode* mobile_folder_node, 70 const BookmarkNode* mobile_folder_node,
71 const BookmarkNode::MetaInfoMap* model_meta_info_map, 71 const BookmarkNode::MetaInfoMap* model_meta_info_map,
72 int64_t sync_transaction_version) { 72 int64_t sync_transaction_version) {
73 ids_reassigned_ = false; 73 ids_reassigned_ = false;
74 InitializeChecksum(); 74 InitializeChecksum();
75 base::DictionaryValue* roots = new base::DictionaryValue(); 75 auto roots = base::MakeUnique<base::DictionaryValue>();
76 roots->Set(kRootFolderNameKey, EncodeNode(bookmark_bar_node)); 76 roots->Set(kRootFolderNameKey, EncodeNode(bookmark_bar_node));
77 roots->Set(kOtherBookmarkFolderNameKey, EncodeNode(other_folder_node)); 77 roots->Set(kOtherBookmarkFolderNameKey, EncodeNode(other_folder_node));
78 roots->Set(kMobileBookmarkFolderNameKey, EncodeNode(mobile_folder_node)); 78 roots->Set(kMobileBookmarkFolderNameKey, EncodeNode(mobile_folder_node));
79 if (model_meta_info_map) 79 if (model_meta_info_map)
80 roots->Set(kMetaInfo, EncodeMetaInfo(*model_meta_info_map)); 80 roots->Set(kMetaInfo, EncodeMetaInfo(*model_meta_info_map));
81 if (sync_transaction_version != 81 if (sync_transaction_version !=
82 BookmarkNode::kInvalidSyncTransactionVersion) { 82 BookmarkNode::kInvalidSyncTransactionVersion) {
83 roots->SetString(kSyncTransactionVersion, 83 roots->SetString(kSyncTransactionVersion,
84 base::Int64ToString(sync_transaction_version)); 84 base::Int64ToString(sync_transaction_version));
85 } 85 }
86 base::DictionaryValue* main = new base::DictionaryValue(); 86 auto main = base::MakeUnique<base::DictionaryValue>();
87 main->SetInteger(kVersionKey, kCurrentVersion); 87 main->SetInteger(kVersionKey, kCurrentVersion);
88 FinalizeChecksum(); 88 FinalizeChecksum();
89 // We are going to store the computed checksum. So set stored checksum to be 89 // We are going to store the computed checksum. So set stored checksum to be
90 // the same as computed checksum. 90 // the same as computed checksum.
91 stored_checksum_ = computed_checksum_; 91 stored_checksum_ = computed_checksum_;
92 main->Set(kChecksumKey, new base::Value(computed_checksum_)); 92 main->SetString(kChecksumKey, computed_checksum_);
93 main->Set(kRootsKey, roots); 93 main->Set(kRootsKey, std::move(roots));
94 return main; 94 return std::move(main);
95 } 95 }
96 96
97 bool BookmarkCodec::Decode(BookmarkNode* bb_node, 97 bool BookmarkCodec::Decode(BookmarkNode* bb_node,
98 BookmarkNode* other_folder_node, 98 BookmarkNode* other_folder_node,
99 BookmarkNode* mobile_folder_node, 99 BookmarkNode* mobile_folder_node,
100 int64_t* max_id, 100 int64_t* max_id,
101 const base::Value& value) { 101 const base::Value& value) {
102 ids_.clear(); 102 ids_.clear();
103 ids_reassigned_ = false; 103 ids_reassigned_ = false;
104 ids_valid_ = true; 104 ids_valid_ = true;
(...skipping 25 matching lines...) Expand all
130 std::string url = node->url().possibly_invalid_spec(); 130 std::string url = node->url().possibly_invalid_spec();
131 value->SetString(kURLKey, url); 131 value->SetString(kURLKey, url);
132 UpdateChecksumWithUrlNode(id, title, url); 132 UpdateChecksumWithUrlNode(id, title, url);
133 } else { 133 } else {
134 value->SetString(kTypeKey, kTypeFolder); 134 value->SetString(kTypeKey, kTypeFolder);
135 value->SetString( 135 value->SetString(
136 kDateModifiedKey, 136 kDateModifiedKey,
137 base::Int64ToString(node->date_folder_modified().ToInternalValue())); 137 base::Int64ToString(node->date_folder_modified().ToInternalValue()));
138 UpdateChecksumWithFolderNode(id, title); 138 UpdateChecksumWithFolderNode(id, title);
139 139
140 base::ListValue* child_values = new base::ListValue(); 140 auto child_values = base::MakeUnique<base::ListValue>();
141 value->Set(kChildrenKey, child_values);
142 for (int i = 0; i < node->child_count(); ++i) 141 for (int i = 0; i < node->child_count(); ++i)
143 child_values->Append(EncodeNode(node->GetChild(i))); 142 child_values->Append(EncodeNode(node->GetChild(i)));
143 value->Set(kChildrenKey, std::move(child_values));
144 } 144 }
145 const BookmarkNode::MetaInfoMap* meta_info_map = node->GetMetaInfoMap(); 145 const BookmarkNode::MetaInfoMap* meta_info_map = node->GetMetaInfoMap();
146 if (meta_info_map) 146 if (meta_info_map)
147 value->Set(kMetaInfo, EncodeMetaInfo(*meta_info_map)); 147 value->Set(kMetaInfo, EncodeMetaInfo(*meta_info_map));
148 if (node->sync_transaction_version() != 148 if (node->sync_transaction_version() !=
149 BookmarkNode::kInvalidSyncTransactionVersion) { 149 BookmarkNode::kInvalidSyncTransactionVersion) {
150 value->SetString(kSyncTransactionVersion, 150 value->SetString(kSyncTransactionVersion,
151 base::Int64ToString(node->sync_transaction_version())); 151 base::Int64ToString(node->sync_transaction_version()));
152 } 152 }
153 return std::move(value); 153 return std::move(value);
154 } 154 }
155 155
156 base::Value* BookmarkCodec::EncodeMetaInfo( 156 std::unique_ptr<base::Value> BookmarkCodec::EncodeMetaInfo(
157 const BookmarkNode::MetaInfoMap& meta_info_map) { 157 const BookmarkNode::MetaInfoMap& meta_info_map) {
158 base::DictionaryValue* meta_info = new base::DictionaryValue; 158 auto meta_info = base::MakeUnique<base::DictionaryValue>();
159 for (BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.begin(); 159 for (BookmarkNode::MetaInfoMap::const_iterator it = meta_info_map.begin();
160 it != meta_info_map.end(); ++it) { 160 it != meta_info_map.end(); ++it) {
161 meta_info->SetStringWithoutPathExpansion(it->first, it->second); 161 meta_info->SetStringWithoutPathExpansion(it->first, it->second);
162 } 162 }
163 return meta_info; 163 return std::move(meta_info);
164 } 164 }
165 165
166 bool BookmarkCodec::DecodeHelper(BookmarkNode* bb_node, 166 bool BookmarkCodec::DecodeHelper(BookmarkNode* bb_node,
167 BookmarkNode* other_folder_node, 167 BookmarkNode* other_folder_node,
168 BookmarkNode* mobile_folder_node, 168 BookmarkNode* mobile_folder_node,
169 const base::Value& value) { 169 const base::Value& value) {
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
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 base::MD5Init(&md5_context_); 497 base::MD5Init(&md5_context_);
498 } 498 }
499 499
500 void BookmarkCodec::FinalizeChecksum() { 500 void BookmarkCodec::FinalizeChecksum() {
501 base::MD5Digest digest; 501 base::MD5Digest digest;
502 base::MD5Final(&digest, &md5_context_); 502 base::MD5Final(&digest, &md5_context_);
503 computed_checksum_ = base::MD5DigestToBase16(digest); 503 computed_checksum_ = base::MD5DigestToBase16(digest);
504 } 504 }
505 505
506 } // namespace bookmarks 506 } // namespace bookmarks
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_codec.h ('k') | components/cloud_devices/common/cloud_device_description.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698