OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (!ids_valid_ || computed_checksum() != stored_checksum()) | 106 if (!ids_valid_ || computed_checksum() != stored_checksum()) |
107 ReassignIDs(bb_node, other_folder_node, mobile_folder_node); | 107 ReassignIDs(bb_node, other_folder_node, mobile_folder_node); |
108 *max_id = maximum_id_ + 1; | 108 *max_id = maximum_id_ + 1; |
109 return success; | 109 return success; |
110 } | 110 } |
111 | 111 |
112 Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { | 112 Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { |
113 DictionaryValue* value = new DictionaryValue(); | 113 DictionaryValue* value = new DictionaryValue(); |
114 std::string id = base::Int64ToString(node->id()); | 114 std::string id = base::Int64ToString(node->id()); |
115 value->SetString(kIdKey, id); | 115 value->SetString(kIdKey, id); |
116 const string16& title = node->GetTitle(); | 116 const base::string16& title = node->GetTitle(); |
117 value->SetString(kNameKey, title); | 117 value->SetString(kNameKey, title); |
118 value->SetString(kDateAddedKey, | 118 value->SetString(kDateAddedKey, |
119 base::Int64ToString(node->date_added().ToInternalValue())); | 119 base::Int64ToString(node->date_added().ToInternalValue())); |
120 if (node->is_url()) { | 120 if (node->is_url()) { |
121 value->SetString(kTypeKey, kTypeURL); | 121 value->SetString(kTypeKey, kTypeURL); |
122 std::string url = node->url().possibly_invalid_spec(); | 122 std::string url = node->url().possibly_invalid_spec(); |
123 value->SetString(kURLKey, url); | 123 value->SetString(kURLKey, url); |
124 UpdateChecksumWithUrlNode(id, title, url); | 124 UpdateChecksumWithUrlNode(id, title, url); |
125 } else { | 125 } else { |
126 value->SetString(kTypeKey, kTypeFolder); | 126 value->SetString(kTypeKey, kTypeFolder); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 !base::StringToInt64(id_string, &id) || | 275 !base::StringToInt64(id_string, &id) || |
276 ids_.count(id) != 0) { | 276 ids_.count(id) != 0) { |
277 ids_valid_ = false; | 277 ids_valid_ = false; |
278 } else { | 278 } else { |
279 ids_.insert(id); | 279 ids_.insert(id); |
280 } | 280 } |
281 } | 281 } |
282 | 282 |
283 maximum_id_ = std::max(maximum_id_, id); | 283 maximum_id_ = std::max(maximum_id_, id); |
284 | 284 |
285 string16 title; | 285 base::string16 title; |
286 value.GetString(kNameKey, &title); | 286 value.GetString(kNameKey, &title); |
287 | 287 |
288 std::string date_added_string; | 288 std::string date_added_string; |
289 if (!value.GetString(kDateAddedKey, &date_added_string)) | 289 if (!value.GetString(kDateAddedKey, &date_added_string)) |
290 date_added_string = base::Int64ToString(Time::Now().ToInternalValue()); | 290 date_added_string = base::Int64ToString(Time::Now().ToInternalValue()); |
291 int64 internal_time; | 291 int64 internal_time; |
292 base::StringToInt64(date_added_string, &internal_time); | 292 base::StringToInt64(date_added_string, &internal_time); |
293 | 293 |
294 std::string type_string; | 294 std::string type_string; |
295 if (!value.GetString(kTypeKey, &type_string)) | 295 if (!value.GetString(kTypeKey, &type_string)) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 DCHECK(node); | 443 DCHECK(node); |
444 node->set_id(++maximum_id_); | 444 node->set_id(++maximum_id_); |
445 for (int i = 0; i < node->child_count(); ++i) | 445 for (int i = 0; i < node->child_count(); ++i) |
446 ReassignIDsHelper(node->GetChild(i)); | 446 ReassignIDsHelper(node->GetChild(i)); |
447 } | 447 } |
448 | 448 |
449 void BookmarkCodec::UpdateChecksum(const std::string& str) { | 449 void BookmarkCodec::UpdateChecksum(const std::string& str) { |
450 base::MD5Update(&md5_context_, str); | 450 base::MD5Update(&md5_context_, str); |
451 } | 451 } |
452 | 452 |
453 void BookmarkCodec::UpdateChecksum(const string16& str) { | 453 void BookmarkCodec::UpdateChecksum(const base::string16& str) { |
454 base::MD5Update(&md5_context_, | 454 base::MD5Update(&md5_context_, |
455 base::StringPiece( | 455 base::StringPiece( |
456 reinterpret_cast<const char*>(str.data()), | 456 reinterpret_cast<const char*>(str.data()), |
457 str.length() * sizeof(str[0]))); | 457 str.length() * sizeof(str[0]))); |
458 } | 458 } |
459 | 459 |
460 void BookmarkCodec::UpdateChecksumWithUrlNode(const std::string& id, | 460 void BookmarkCodec::UpdateChecksumWithUrlNode(const std::string& id, |
461 const string16& title, | 461 const base::string16& title, |
462 const std::string& url) { | 462 const std::string& url) { |
463 DCHECK(IsStringUTF8(url)); | 463 DCHECK(IsStringUTF8(url)); |
464 UpdateChecksum(id); | 464 UpdateChecksum(id); |
465 UpdateChecksum(title); | 465 UpdateChecksum(title); |
466 UpdateChecksum(kTypeURL); | 466 UpdateChecksum(kTypeURL); |
467 UpdateChecksum(url); | 467 UpdateChecksum(url); |
468 } | 468 } |
469 | 469 |
470 void BookmarkCodec::UpdateChecksumWithFolderNode(const std::string& id, | 470 void BookmarkCodec::UpdateChecksumWithFolderNode(const std::string& id, |
471 const string16& title) { | 471 const base::string16& title) { |
472 UpdateChecksum(id); | 472 UpdateChecksum(id); |
473 UpdateChecksum(title); | 473 UpdateChecksum(title); |
474 UpdateChecksum(kTypeFolder); | 474 UpdateChecksum(kTypeFolder); |
475 } | 475 } |
476 | 476 |
477 void BookmarkCodec::InitializeChecksum() { | 477 void BookmarkCodec::InitializeChecksum() { |
478 base::MD5Init(&md5_context_); | 478 base::MD5Init(&md5_context_); |
479 } | 479 } |
480 | 480 |
481 void BookmarkCodec::FinalizeChecksum() { | 481 void BookmarkCodec::FinalizeChecksum() { |
482 base::MD5Digest digest; | 482 base::MD5Digest digest; |
483 base::MD5Final(&digest, &md5_context_); | 483 base::MD5Final(&digest, &md5_context_); |
484 computed_checksum_ = base::MD5DigestToBase16(digest); | 484 computed_checksum_ = base::MD5DigestToBase16(digest); |
485 } | 485 } |
OLD | NEW |