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

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

Issue 3056029: Move the number conversions from string_util to a new file.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2009 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_number_conversions.h"
10 #include "base/string_util.h" 11 #include "base/string_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
15 16
16 using base::Time; 17 using base::Time;
17 18
18 const wchar_t* BookmarkCodec::kRootsKey = L"roots"; 19 const wchar_t* BookmarkCodec::kRootsKey = L"roots";
19 const wchar_t* BookmarkCodec::kRootFolderNameKey = L"bookmark_bar"; 20 const wchar_t* BookmarkCodec::kRootFolderNameKey = L"bookmark_bar";
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // If either the checksums differ or some IDs were missing/not unique, 78 // If either the checksums differ or some IDs were missing/not unique,
78 // reassign IDs. 79 // reassign IDs.
79 if (!ids_valid_ || computed_checksum() != stored_checksum()) 80 if (!ids_valid_ || computed_checksum() != stored_checksum())
80 ReassignIDs(bb_node, other_folder_node); 81 ReassignIDs(bb_node, other_folder_node);
81 *max_id = maximum_id_ + 1; 82 *max_id = maximum_id_ + 1;
82 return success; 83 return success;
83 } 84 }
84 85
85 Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) { 86 Value* BookmarkCodec::EncodeNode(const BookmarkNode* node) {
86 DictionaryValue* value = new DictionaryValue(); 87 DictionaryValue* value = new DictionaryValue();
87 std::string id = Int64ToString(node->id()); 88 std::string id = base::Int64ToString(node->id());
88 value->SetString(kIdKey, id); 89 value->SetString(kIdKey, id);
89 const string16& title = node->GetTitleAsString16(); 90 const string16& title = node->GetTitleAsString16();
90 value->SetStringFromUTF16(kNameKey, title); 91 value->SetStringFromUTF16(kNameKey, title);
91 value->SetString(kDateAddedKey, 92 value->SetString(kDateAddedKey,
92 Int64ToString(node->date_added().ToInternalValue())); 93 base::Int64ToString(node->date_added().ToInternalValue()));
93 if (node->type() == BookmarkNode::URL) { 94 if (node->type() == BookmarkNode::URL) {
94 value->SetString(kTypeKey, kTypeURL); 95 value->SetString(kTypeKey, kTypeURL);
95 std::string url = node->GetURL().possibly_invalid_spec(); 96 std::string url = node->GetURL().possibly_invalid_spec();
96 value->SetString(kURLKey, url); 97 value->SetString(kURLKey, url);
97 UpdateChecksumWithUrlNode(id, title, url); 98 UpdateChecksumWithUrlNode(id, title, url);
98 } else { 99 } else {
99 value->SetString(kTypeKey, kTypeFolder); 100 value->SetString(kTypeKey, kTypeFolder);
100 value->SetString(kDateModifiedKey, 101 value->SetString(kDateModifiedKey,
101 Int64ToString(node->date_group_modified(). 102 base::Int64ToString(node->date_group_modified().
102 ToInternalValue())); 103 ToInternalValue()));
103 UpdateChecksumWithFolderNode(id, title); 104 UpdateChecksumWithFolderNode(id, title);
104 105
105 ListValue* child_values = new ListValue(); 106 ListValue* child_values = new ListValue();
106 value->Set(kChildrenKey, child_values); 107 value->Set(kChildrenKey, child_values);
107 for (int i = 0; i < node->GetChildCount(); ++i) 108 for (int i = 0; i < node->GetChildCount(); ++i)
108 child_values->Append(EncodeNode(node->GetChild(i))); 109 child_values->Append(EncodeNode(node->GetChild(i)));
109 } 110 }
110 return value; 111 return value;
111 } 112 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 201 }
201 } 202 }
202 203
203 maximum_id_ = std::max(maximum_id_, id); 204 maximum_id_ = std::max(maximum_id_, id);
204 205
205 string16 title; 206 string16 title;
206 value.GetStringAsUTF16(kNameKey, &title); 207 value.GetStringAsUTF16(kNameKey, &title);
207 208
208 std::string date_added_string; 209 std::string date_added_string;
209 if (!value.GetString(kDateAddedKey, &date_added_string)) 210 if (!value.GetString(kDateAddedKey, &date_added_string))
210 date_added_string = Int64ToString(Time::Now().ToInternalValue()); 211 date_added_string = base::Int64ToString(Time::Now().ToInternalValue());
211 base::Time date_added = base::Time::FromInternalValue( 212 base::Time date_added = base::Time::FromInternalValue(
212 StringToInt64(date_added_string)); 213 StringToInt64(date_added_string));
213 #if !defined(OS_WIN) 214 #if !defined(OS_WIN)
214 // We changed the epoch for dates on Mac & Linux from 1970 to the Windows 215 // We changed the epoch for dates on Mac & Linux from 1970 to the Windows
215 // one of 1601. We assume any number we encounter from before 1970 is using 216 // one of 1601. We assume any number we encounter from before 1970 is using
216 // the old format, so we need to add the delta to it. 217 // the old format, so we need to add the delta to it.
217 // 218 //
218 // This code should be removed at some point: 219 // This code should be removed at some point:
219 // http://code.google.com/p/chromium/issues/detail?id=20264 220 // http://code.google.com/p/chromium/issues/detail?id=20264
220 if (date_added.ToInternalValue() < 221 if (date_added.ToInternalValue() <
(...skipping 21 matching lines...) Expand all
242 else 243 else
243 return false; // Node invalid. 244 return false; // Node invalid.
244 245
245 if (parent) 246 if (parent)
246 parent->Add(parent->GetChildCount(), node); 247 parent->Add(parent->GetChildCount(), node);
247 node->set_type(BookmarkNode::URL); 248 node->set_type(BookmarkNode::URL);
248 UpdateChecksumWithUrlNode(id_string, title, url_string); 249 UpdateChecksumWithUrlNode(id_string, title, url_string);
249 } else { 250 } else {
250 std::string last_modified_date; 251 std::string last_modified_date;
251 if (!value.GetString(kDateModifiedKey, &last_modified_date)) 252 if (!value.GetString(kDateModifiedKey, &last_modified_date))
252 last_modified_date = Int64ToString(Time::Now().ToInternalValue()); 253 last_modified_date = base::Int64ToString(Time::Now().ToInternalValue());
253 254
254 Value* child_values; 255 Value* child_values;
255 if (!value.Get(kChildrenKey, &child_values)) 256 if (!value.Get(kChildrenKey, &child_values))
256 return false; 257 return false;
257 258
258 if (child_values->GetType() != Value::TYPE_LIST) 259 if (child_values->GetType() != Value::TYPE_LIST)
259 return false; 260 return false;
260 261
261 if (!node) { 262 if (!node) {
262 node = new BookmarkNode(id, GURL()); 263 node = new BookmarkNode(id, GURL());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 326
326 void BookmarkCodec::InitializeChecksum() { 327 void BookmarkCodec::InitializeChecksum() {
327 MD5Init(&md5_context_); 328 MD5Init(&md5_context_);
328 } 329 }
329 330
330 void BookmarkCodec::FinalizeChecksum() { 331 void BookmarkCodec::FinalizeChecksum() {
331 MD5Digest digest; 332 MD5Digest digest;
332 MD5Final(&digest, &md5_context_); 333 MD5Final(&digest, &md5_context_);
333 computed_checksum_ = MD5DigestToBase16(digest); 334 computed_checksum_ = MD5DigestToBase16(digest);
334 } 335 }
OLDNEW
« no previous file with comments | « chrome/browser/back_forward_menu_model.cc ('k') | chrome/browser/bookmarks/bookmark_html_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698