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

Unified Diff: components/enhanced_bookmarks/enhanced_bookmark_model.h

Issue 563363002: Only set remote id during url node creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Dedup remote ids + server service changes Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/enhanced_bookmarks/enhanced_bookmark_model.h
diff --git a/components/enhanced_bookmarks/enhanced_bookmark_model.h b/components/enhanced_bookmarks/enhanced_bookmark_model.h
index d89f07f78960f9300b600a5ca1a0d5296c9978af..5c58d367b23386ac8208e18b8fe9607439c68b2b 100644
--- a/components/enhanced_bookmarks/enhanced_bookmark_model.h
+++ b/components/enhanced_bookmarks/enhanced_bookmark_model.h
@@ -5,9 +5,11 @@
#ifndef COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_
#define COMPONENTS_ENHANCED_BOOKMARKS_ENHANCED_BOOKMARK_MODEL_H_
+#include <map>
#include <string>
#include "base/strings/string16.h"
+#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/keyed_service/core/keyed_service.h"
@@ -16,17 +18,21 @@ class Time;
} // namespace base
class BookmarkModel;
+class BookmarkNode;
class GURL;
namespace enhanced_bookmarks {
// Wrapper around BookmarkModel providing utility functions for enhanced
// bookmarks.
-class EnhancedBookmarkModel : public KeyedService {
+class EnhancedBookmarkModel : public KeyedService,
+ public BaseBookmarkModelObserver {
public:
EnhancedBookmarkModel(BookmarkModel* bookmark_model,
const std::string& version);
virtual ~EnhancedBookmarkModel();
+ virtual void ShutDown();
+
// Moves |node| to |new_parent| and inserts it at the given |index|.
void Move(const BookmarkNode* node,
const BookmarkNode* new_parent,
@@ -47,6 +53,10 @@ class EnhancedBookmarkModel : public KeyedService {
// Returns the remote id for a bookmark |node|.
std::string GetRemoteId(const BookmarkNode* node);
+ // Returns the bookmark node corresponding to the given |remote_id|, or NULL
+ // if there is no node with the id.
+ const BookmarkNode* BookmarkForRemoteId(const std::string& remote_id);
+
// Sets the description of a bookmark |node|.
void SetDescription(const BookmarkNode* node, const std::string& description);
@@ -105,21 +115,62 @@ class EnhancedBookmarkModel : public KeyedService {
BookmarkModel* bookmark_model() { return bookmark_model_; }
private:
- // Generates and sets a remote id for the given bookmark |node|.
- // Returns the id set.
- std::string SetRemoteId(const BookmarkNode* node);
+ typedef std::map<std::string, const BookmarkNode*> IdToNodeMap;
+ typedef std::map<const BookmarkNode*, std::string> NodeToIdMap;
+
+ // BaseBookmarkModelObserver:
+ virtual void BookmarkModelChanged() OVERRIDE;
+ virtual void BookmarkModelLoaded(BookmarkModel* model,
+ bool ids_reassigned) OVERRIDE;
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int index) OVERRIDE;
+ virtual void BookmarkNodeRemoved(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int old_index,
+ const BookmarkNode* node,
+ const std::set<GURL>& removed_urls) OVERRIDE;
+ virtual void OnWillChangeBookmarkMetaInfo(BookmarkModel* model,
+ const BookmarkNode* node) OVERRIDE;
+ virtual void BookmarkMetaInfoChanged(BookmarkModel* model,
+ const BookmarkNode* node) OVERRIDE;
+ virtual void BookmarkAllUserNodesRemoved(
+ BookmarkModel* model,
+ const std::set<GURL>& removed_urls) OVERRIDE;
+
+ // Initialize the mapping from remote ids to nodes.
+ void InitializeIdMap();
+
+ // Adds a node to the id map if it has a (unique) remote id. Must be followed
+ // by a ResetDuplicateRemoteIds call when done adding nodes.
+ void AddToIdMap(const BookmarkNode* node);
+
+ // Clears out any duplicate remote ids detected by AddToIdMap calls.
+ void ResetDuplicateRemoteIds();
// Helper method for setting a meta info field on a node. Also updates the
- // version and userEdits fields.
+ // version field.
void SetMetaInfo(const BookmarkNode* node,
const std::string& field,
- const std::string& value,
- bool user_edit);
+ const std::string& value);
+
+ // Helper method for setting multiple meta info fields at once. All the fields
+ // in |meta_info| will be set, but the method will not delete fields not
+ // present.
+ void SetMultipleMetaInfo(const BookmarkNode* node,
+ BookmarkNode::MetaInfoMap meta_info);
// Returns the version string to use when setting stars.version.
std::string GetVersionString();
BookmarkModel* bookmark_model_;
+
+ IdToNodeMap id_map_;
+ NodeToIdMap nodes_to_reset_;
+
+ // Caches the remote id of a node before its meta info changes.
+ std::string prev_remote_id_;
+
std::string version_;
std::string version_suffix_;
};

Powered by Google App Engine
This is Rietveld 408576698