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-07-15 20:15:26 +0000
committermunjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-15 20:15:26 +0000
commit95234df98c31158c55e9732cdf682ed5e1e8e71a (patch)
tree4abc912d503dfbc30eca00e442592dc62362b580 /chrome/browser/bookmarks/bookmark_codec.h
parentf6582b315e31d5eb526ee97f9733130ae751dd20 (diff)
downloadchromium_src-95234df98c31158c55e9732cdf682ed5e1e8e71a.zip
chromium_src-95234df98c31158c55e9732cdf682ed5e1e8e71a.tar.gz
chromium_src-95234df98c31158c55e9732cdf682ed5e1e8e71a.tar.bz2
Don't use ID generation logic always. Only reassign IDs
when checksums differ or if IDs are missing and do that simply by assigning the next maximum id. Add a unit test. BUG=16357 TEST=NONE Review URL: http://codereview.chromium.org/155560 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20779 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_codec.h')
-rw-r--r--chrome/browser/bookmarks/bookmark_codec.h49
1 files changed, 12 insertions, 37 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h
index 2c13cef..becdf4e 100644
--- a/chrome/browser/bookmarks/bookmark_codec.h
+++ b/chrome/browser/bookmarks/bookmark_codec.h
@@ -9,7 +9,6 @@
#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_
#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_CODEC_H_
-#include <set>
#include <string>
#include "base/basictypes.h"
@@ -22,39 +21,6 @@ class DictionaryValue;
class ListValue;
class Value;
-// Utility class to help assign unique 64-bit IDs.
-class UniqueIDGenerator {
- public:
- UniqueIDGenerator();
-
- // Checks whether the given ID can be used as a unique ID or not. If it can,
- // returns the id itself, otherwise generates a new unique id in a simple way
- // and returns that.
- // NOTE that if id is 0, a new unique id is returned.
- int64 GetUniqueID(int64 id);
-
- // Resets the ID generator to initial state.
- void Reset();
-
- // Returns the current maximum.
- int64 current_max() const { return current_max_; }
-
- private:
- // Checks if the given ID is already assigned.
- bool IsIdAssigned(int64 id) const;
-
- // Records the given ID as assigned.
- void RecordId(int64 id);
-
- // Maximum value we have seen so far.
- int64 current_max_;
-
- // All IDs assigned so far.
- scoped_ptr<std::set<int64> > assigned_ids_;
-
- DISALLOW_COPY_AND_ASSIGN(UniqueIDGenerator);
-};
-
// BookmarkCodec is responsible for encoding/decoding bookmarks into JSON
// values. BookmarkCodec is used by BookmarkService.
@@ -135,6 +101,12 @@ class BookmarkCodec {
bool DecodeChildren(const ListValue& child_value_list,
BookmarkNode* parent);
+ // Reassigns bookmark IDs for all nodes.
+ void ReassignIDs(BookmarkNode* bb_node, BookmarkNode* other_node);
+
+ // Helper to recursively reassign IDs.
+ void ReassignIDsHelper(BookmarkNode* node);
+
// Decodes the supplied node from the supplied value. Child nodes are
// created appropriately by way of DecodeChildren. If node is NULL a new
// node is created and added to parent, otherwise node is used.
@@ -161,12 +133,12 @@ class BookmarkCodec {
void InitializeChecksum();
void FinalizeChecksum();
- // Unique ID generator used during decoding.
- UniqueIDGenerator id_generator_;
-
// Whether or not IDs were reassigned by the codec.
bool ids_reassigned_;
+ // Whether or not IDs were missing for some bookmark nodes during decoding.
+ bool ids_missing_;
+
// MD5 context used to compute MD5 hash of all bookmark data.
MD5Context md5_context_;
@@ -174,6 +146,9 @@ class BookmarkCodec {
std::string computed_checksum_;
std::string stored_checksum_;
+ // Maximum ID assigned when decoding data.
+ int64 maximum_id_;
+
DISALLOW_COPY_AND_ASSIGN(BookmarkCodec);
};