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

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

Issue 155165: Lands http://codereview.chromium.org/155128 for Thiago.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_html_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/bookmarks/bookmark_codec.h" 5 #include "chrome/browser/bookmarks/bookmark_codec.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 DictionaryValue* value = new DictionaryValue(); 131 DictionaryValue* value = new DictionaryValue();
132 std::string id; 132 std::string id;
133 if (persist_ids_) { 133 if (persist_ids_) {
134 id = IntToString(node->id()); 134 id = IntToString(node->id());
135 value->SetString(kIdKey, id); 135 value->SetString(kIdKey, id);
136 } 136 }
137 const std::wstring& title = node->GetTitle(); 137 const std::wstring& title = node->GetTitle();
138 value->SetString(kNameKey, title); 138 value->SetString(kNameKey, title);
139 value->SetString(kDateAddedKey, 139 value->SetString(kDateAddedKey,
140 Int64ToWString(node->date_added().ToInternalValue())); 140 Int64ToWString(node->date_added().ToInternalValue()));
141 if (node->GetType() == history::StarredEntry::URL) { 141 if (node->GetType() == BookmarkNode::URL) {
142 value->SetString(kTypeKey, kTypeURL); 142 value->SetString(kTypeKey, kTypeURL);
143 std::wstring url = UTF8ToWide(node->GetURL().possibly_invalid_spec()); 143 std::wstring url = UTF8ToWide(node->GetURL().possibly_invalid_spec());
144 value->SetString(kURLKey, url); 144 value->SetString(kURLKey, url);
145 UpdateChecksumWithUrlNode(id, title, url); 145 UpdateChecksumWithUrlNode(id, title, url);
146 } else { 146 } else {
147 value->SetString(kTypeKey, kTypeFolder); 147 value->SetString(kTypeKey, kTypeFolder);
148 value->SetString(kDateModifiedKey, 148 value->SetString(kDateModifiedKey,
149 Int64ToWString(node->date_group_modified(). 149 Int64ToWString(node->date_group_modified().
150 ToInternalValue())); 150 ToInternalValue()));
151 UpdateChecksumWithFolderNode(id, title); 151 UpdateChecksumWithFolderNode(id, title);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 other_folder_value->GetType() != Value::TYPE_DICTIONARY) 196 other_folder_value->GetType() != Value::TYPE_DICTIONARY)
197 return false; // Invalid type for root folder and/or other folder. 197 return false; // Invalid type for root folder and/or other folder.
198 198
199 DecodeNode(*static_cast<DictionaryValue*>(root_folder_value), NULL, 199 DecodeNode(*static_cast<DictionaryValue*>(root_folder_value), NULL,
200 bb_node); 200 bb_node);
201 DecodeNode(*static_cast<DictionaryValue*>(other_folder_value), NULL, 201 DecodeNode(*static_cast<DictionaryValue*>(other_folder_value), NULL,
202 other_folder_node); 202 other_folder_node);
203 // Need to reset the type as decoding resets the type to FOLDER. Similarly 203 // Need to reset the type as decoding resets the type to FOLDER. Similarly
204 // we need to reset the title as the title is persisted and restored from 204 // we need to reset the title as the title is persisted and restored from
205 // the file. 205 // the file.
206 bb_node->SetType(history::StarredEntry::BOOKMARK_BAR); 206 bb_node->SetType(BookmarkNode::BOOKMARK_BAR);
207 other_folder_node->SetType(history::StarredEntry::OTHER); 207 other_folder_node->SetType(BookmarkNode::OTHER_NODE);
208 bb_node->SetTitle(l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME)); 208 bb_node->SetTitle(l10n_util::GetString(IDS_BOOMARK_BAR_FOLDER_NAME));
209 other_folder_node->SetTitle( 209 other_folder_node->SetTitle(
210 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); 210 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME));
211 211
212 return true; 212 return true;
213 } 213 }
214 214
215 bool BookmarkCodec::DecodeChildren(const ListValue& child_value_list, 215 bool BookmarkCodec::DecodeChildren(const ListValue& child_value_list,
216 BookmarkNode* parent) { 216 BookmarkNode* parent) {
217 for (size_t i = 0; i < child_value_list.GetSize(); ++i) { 217 for (size_t i = 0; i < child_value_list.GetSize(); ++i) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (!value.GetString(kURLKey, &url_string)) 259 if (!value.GetString(kURLKey, &url_string))
260 return false; 260 return false;
261 261
262 if (!node) 262 if (!node)
263 node = new BookmarkNode(id, GURL(WideToUTF8(url_string))); 263 node = new BookmarkNode(id, GURL(WideToUTF8(url_string)));
264 else 264 else
265 return false; // Node invalid. 265 return false; // Node invalid.
266 266
267 if (parent) 267 if (parent)
268 parent->Add(parent->GetChildCount(), node); 268 parent->Add(parent->GetChildCount(), node);
269 node->SetType(history::StarredEntry::URL); 269 node->SetType(BookmarkNode::URL);
270 UpdateChecksumWithUrlNode(id_string, title, url_string); 270 UpdateChecksumWithUrlNode(id_string, title, url_string);
271 } else { 271 } else {
272 std::wstring last_modified_date; 272 std::wstring last_modified_date;
273 if (!value.GetString(kDateModifiedKey, &last_modified_date)) 273 if (!value.GetString(kDateModifiedKey, &last_modified_date))
274 last_modified_date = Int64ToWString(Time::Now().ToInternalValue()); 274 last_modified_date = Int64ToWString(Time::Now().ToInternalValue());
275 275
276 Value* child_values; 276 Value* child_values;
277 if (!value.Get(kChildrenKey, &child_values)) 277 if (!value.Get(kChildrenKey, &child_values))
278 return false; 278 return false;
279 279
280 if (child_values->GetType() != Value::TYPE_LIST) 280 if (child_values->GetType() != Value::TYPE_LIST)
281 return false; 281 return false;
282 282
283 if (!node) { 283 if (!node) {
284 node = new BookmarkNode(id, GURL()); 284 node = new BookmarkNode(id, GURL());
285 } else { 285 } else {
286 // If a new node is not created, explicitly assign ID to the existing one. 286 // If a new node is not created, explicitly assign ID to the existing one.
287 DCHECK(id != 0); 287 DCHECK(id != 0);
288 node->set_id(id); 288 node->set_id(id);
289 } 289 }
290 290
291 node->SetType(history::StarredEntry::USER_GROUP); 291 node->SetType(BookmarkNode::FOLDER);
292 node->set_date_group_modified(Time::FromInternalValue( 292 node->set_date_group_modified(Time::FromInternalValue(
293 StringToInt64(WideToUTF16Hack(last_modified_date)))); 293 StringToInt64(WideToUTF16Hack(last_modified_date))));
294 294
295 if (parent) 295 if (parent)
296 parent->Add(parent->GetChildCount(), node); 296 parent->Add(parent->GetChildCount(), node);
297 297
298 UpdateChecksumWithFolderNode(id_string, title); 298 UpdateChecksumWithFolderNode(id_string, title);
299
299 if (!DecodeChildren(*static_cast<ListValue*>(child_values), node)) 300 if (!DecodeChildren(*static_cast<ListValue*>(child_values), node))
300 return false; 301 return false;
301 } 302 }
302 303
303 node->SetTitle(title); 304 node->SetTitle(title);
304 node->set_date_added(Time::FromInternalValue( 305 node->set_date_added(Time::FromInternalValue(
305 StringToInt64(WideToUTF16Hack(date_added_string)))); 306 StringToInt64(WideToUTF16Hack(date_added_string))));
306 return true; 307 return true;
307 } 308 }
308 309
(...skipping 23 matching lines...) Expand all
332 333
333 void BookmarkCodec::InitializeChecksum() { 334 void BookmarkCodec::InitializeChecksum() {
334 MD5Init(&md5_context_); 335 MD5Init(&md5_context_);
335 } 336 }
336 337
337 void BookmarkCodec::FinalizeChecksum() { 338 void BookmarkCodec::FinalizeChecksum() {
338 MD5Digest digest; 339 MD5Digest digest;
339 MD5Final(&digest, &md5_context_); 340 MD5Final(&digest, &md5_context_);
340 computed_checksum_ = MD5DigestToBase16(digest); 341 computed_checksum_ = MD5DigestToBase16(digest);
341 } 342 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_html_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698