| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return false; | 173 return false; |
| 174 | 174 |
| 175 DecodeNode(*static_cast<DictionaryValue*>(child_value), parent, NULL); | 175 DecodeNode(*static_cast<DictionaryValue*>(child_value), parent, NULL); |
| 176 } | 176 } |
| 177 return true; | 177 return true; |
| 178 } | 178 } |
| 179 | 179 |
| 180 bool BookmarkCodec::DecodeNode(const DictionaryValue& value, | 180 bool BookmarkCodec::DecodeNode(const DictionaryValue& value, |
| 181 BookmarkNode* parent, | 181 BookmarkNode* parent, |
| 182 BookmarkNode* node) { | 182 BookmarkNode* node) { |
| 183 // If no |node| is specified, we'll create one and add it to the |parent|. |
| 184 // Therefore, in that case, |parent| must be non-NULL. |
| 185 if (!node && !parent) { |
| 186 NOTREACHED(); |
| 187 return false; |
| 188 } |
| 189 |
| 183 std::string id_string; | 190 std::string id_string; |
| 184 int64 id = 0; | 191 int64 id = 0; |
| 185 if (!value.GetString(kIdKey, &id_string) || !StringToInt64(id_string, &id)) | 192 if (!value.GetString(kIdKey, &id_string) || !StringToInt64(id_string, &id)) |
| 186 ids_missing_ = true; | 193 ids_missing_ = true; |
| 187 | 194 |
| 188 maximum_id_ = std::max(maximum_id_, id); | 195 maximum_id_ = std::max(maximum_id_, id); |
| 189 | 196 |
| 190 std::wstring title; | 197 std::wstring title; |
| 191 value.GetString(kNameKey, &title); | 198 value.GetString(kNameKey, &title); |
| 192 | 199 |
| 193 std::wstring date_added_string; | 200 std::wstring date_added_string; |
| 194 if (!value.GetString(kDateAddedKey, &date_added_string)) | 201 if (!value.GetString(kDateAddedKey, &date_added_string)) |
| 195 date_added_string = Int64ToWString(Time::Now().ToInternalValue()); | 202 date_added_string = Int64ToWString(Time::Now().ToInternalValue()); |
| 196 | 203 |
| 197 std::wstring type_string; | 204 std::wstring type_string; |
| 198 if (!value.GetString(kTypeKey, &type_string)) | 205 if (!value.GetString(kTypeKey, &type_string)) |
| 199 return false; | 206 return false; |
| 200 | 207 |
| 201 if (type_string != kTypeURL && type_string != kTypeFolder) | 208 if (type_string != kTypeURL && type_string != kTypeFolder) |
| 202 return false; // Unknown type. | 209 return false; // Unknown type. |
| 203 | 210 |
| 204 if (type_string == kTypeURL) { | 211 if (type_string == kTypeURL) { |
| 205 std::wstring url_string; | 212 std::wstring url_string; |
| 206 if (!value.GetString(kURLKey, &url_string)) | 213 if (!value.GetString(kURLKey, &url_string)) |
| 207 return false; | 214 return false; |
| 208 | 215 |
| 209 if (!node) | 216 if (!node) |
| 210 node = new BookmarkNode(id, GURL(WideToUTF8(url_string))); | 217 node = new BookmarkNode(id, GURL(WideToUTF8(url_string))); |
| 211 else | 218 else |
| 212 return false; // Node invalid. | 219 return false; // Node invalid. |
| 213 | 220 |
| 214 if (parent) | 221 if (parent) |
| 215 parent->Add(parent->GetChildCount(), node); | 222 parent->Add(parent->GetChildCount(), node); |
| 216 node->SetType(BookmarkNode::URL); | 223 node->SetType(BookmarkNode::URL); |
| 217 UpdateChecksumWithUrlNode(id_string, title, url_string); | 224 UpdateChecksumWithUrlNode(id_string, title, url_string); |
| 218 } else { | 225 } else { |
| 219 std::wstring last_modified_date; | 226 std::wstring last_modified_date; |
| 220 if (!value.GetString(kDateModifiedKey, &last_modified_date)) | 227 if (!value.GetString(kDateModifiedKey, &last_modified_date)) |
| 221 last_modified_date = Int64ToWString(Time::Now().ToInternalValue()); | 228 last_modified_date = Int64ToWString(Time::Now().ToInternalValue()); |
| 222 | 229 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 301 |
| 295 void BookmarkCodec::InitializeChecksum() { | 302 void BookmarkCodec::InitializeChecksum() { |
| 296 MD5Init(&md5_context_); | 303 MD5Init(&md5_context_); |
| 297 } | 304 } |
| 298 | 305 |
| 299 void BookmarkCodec::FinalizeChecksum() { | 306 void BookmarkCodec::FinalizeChecksum() { |
| 300 MD5Digest digest; | 307 MD5Digest digest; |
| 301 MD5Final(&digest, &md5_context_); | 308 MD5Final(&digest, &md5_context_); |
| 302 computed_checksum_ = MD5DigestToBase16(digest); | 309 computed_checksum_ = MD5DigestToBase16(digest); |
| 303 } | 310 } |
| OLD | NEW |