summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks/bookmark_codec.h
diff options
context:
space:
mode:
authormunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 16:56:23 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 16:56:23 +0000
commit33ba5fbf040015cd4dd9c330db3b7eec65510cfd (patch)
tree7b15075473da8428378d4dddd9798009dddccc85 /chrome/browser/bookmarks/bookmark_codec.h
parentf9b24b24a6a6ef9965bb03d4a4221c4a2946b997 (diff)
downloadchromium_src-33ba5fbf040015cd4dd9c330db3b7eec65510cfd.zip
chromium_src-33ba5fbf040015cd4dd9c330db3b7eec65510cfd.tar.gz
chromium_src-33ba5fbf040015cd4dd9c330db3b7eec65510cfd.tar.bz2
Add a way to checksum bookmark data to help determine if the
bookmarks file was changed by the user between two chrome runs. - BookmarkCodec now serializes a checksum of bookmark data along side bookmark data during encoding. - During decoding BookmarkCodec computes the checksum of deserialized data, and it also reads the checksum in the file. - BookmarkCodec exposes both the checksums via getters. - Add unit tests for BookmarkCodec, right now only checksum related. Review URL: http://codereview.chromium.org/69028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14612 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_codec.h')
-rw-r--r--chrome/browser/bookmarks/bookmark_codec.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h
index 4e1fb81..fb9d06f 100644
--- a/chrome/browser/bookmarks/bookmark_codec.h
+++ b/chrome/browser/bookmarks/bookmark_codec.h
@@ -9,7 +9,10 @@
#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_
#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_
+#include <string>
+
#include "base/basictypes.h"
+#include "base/md5.h"
class BookmarkModel;
class BookmarkNode;
@@ -43,11 +46,22 @@ class BookmarkCodec {
// nodes.
bool Decode(BookmarkModel* model, const Value& value);
+ // Returns the checksum computed during last encoding/decoding call.
+ const std::string& computed_checksum() const { return computed_checksum_; }
+
+ // Returns the checksum that's stored in the file. After a call to Encode,
+ // the computed and stored checksums are the same since the computed checksum
+ // is stored to the file. After a call to decode, the computed checksum can
+ // differ from the stored checksum if the file contents were changed by the
+ // user.
+ const std::string& stored_checksum() const { return stored_checksum_; }
+
// Names of the various keys written to the Value.
static const wchar_t* kRootsKey;
static const wchar_t* kRootFolderNameKey;
static const wchar_t* kOtherBookmarFolderNameKey;
static const wchar_t* kVersionKey;
+ static const wchar_t* kChecksumKey;
static const wchar_t* kTypeKey;
static const wchar_t* kNameKey;
static const wchar_t* kDateAddedKey;
@@ -64,6 +78,9 @@ class BookmarkCodec {
// The caller takes ownership of the returned object.
Value* EncodeNode(BookmarkNode* node);
+ // Helper to perform decoding.
+ bool DecodeHelper(BookmarkModel* model, const Value& value);
+
// Decodes the children of the specified node. Returns true on success.
bool DecodeChildren(BookmarkModel* model,
const ListValue& child_value_list,
@@ -77,6 +94,31 @@ class BookmarkCodec {
BookmarkNode* parent,
BookmarkNode* node);
+ // Updates the check-sum with the given string.
+ void UpdateChecksum(const std::string& str);
+ void UpdateChecksum(const std::wstring& str);
+
+ // Updates the check-sum with the given contents of URL/folder bookmark node.
+ // NOTE: These functions take in individual properties of a bookmark node
+ // instead of taking in a BookmarkNode for efficiency so that we don't convert
+ // varous data-types to wide strings multiple times - once for serializing
+ // and once for computing the check-sum.
+ void UpdateChecksumWithUrlNode(const std::wstring& title,
+ const std::wstring& url);
+ void UpdateChecksumWithFolderNode(const std::wstring& title);
+
+ // Initializes/Finalizes the checksum.
+ void InitializeChecksum();
+ void FinalizeChecksum();
+
+ // MD5 context used to compute MD5 hash of all bookmark data.
+ MD5Context md5_context_;
+
+ // Checksums.
+ std::string computed_checksum_;
+ std::string stored_checksum_;
+
+
DISALLOW_COPY_AND_ASSIGN(BookmarkCodec);
};