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

Unified Diff: chrome/browser/undo/bookmark_undo_service.h

Issue 19287013: Bookmark Undo service for multiple level undo/redo of bookmarks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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: chrome/browser/undo/bookmark_undo_service.h
diff --git a/chrome/browser/undo/bookmark_undo_service.h b/chrome/browser/undo/bookmark_undo_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..da64cd850a909a2af68f0b1f1a2e8cd738cf7d91
--- /dev/null
+++ b/chrome/browser/undo/bookmark_undo_service.h
@@ -0,0 +1,100 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_
+#define CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_
+
+#include <map>
+
+#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
+#include "chrome/browser/bookmarks/bookmark_node_data.h"
+#include "chrome/browser/undo/undo_manager.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
+
+class Profile;
+namespace {
+class BookmarkUndoOperation;
+} // namespace
+
+// BookmarkIdMap -------------------------------------------------------
+
+// Keeps a record of the bookmark identifiers as they change as a result of
+// user actions and the undo system.
+//
+// For example, an existing bookmark is modified and then deleted, the undo of
+// the deletion would recreate the bookmark but with a different id. In order
+// for the undo of the earlier modification to occur the new id should be
+// associated with the old id and be retrieved to undo the modification.
+class BookmarkIdMap {
sky 2013/07/18 14:35:41 I think I like notifying existing BookmarkUndoOper
Tom Cassiotis 2013/07/24 15:37:56 Since the UndoOperation and UndoService should kno
Tom Cassiotis 2013/07/25 13:02:03 Alternatively, I can add a new function in UndoOpe
+ public:
+ BookmarkIdMap();
+ virtual ~BookmarkIdMap();
+
+ // Retrieve the valid bookmark id given a possibly old id.
+ int64 GetCurrentId(int64 old_index);
+
+ // Associate an old bookmark id with a new id.
+ void AddMapping(int64 old_index, int64 new_index);
+
+ // Recursively identify changed ids after bookmarks have been pasted.
+ void ExtractMappings(BookmarkModel* model,
+ const BookmarkNodeData::Element& element,
+ const BookmarkNode* parent,
+ int index_added_at);
+ private:
+ std::map<int64, int64> identifier_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkIdMap);
+};
+
+// BookmarkUndoService --------------------------------------------------------
+
+// BookmarkUndoService is owned by the profile, and is responsible for observing
+// changes to the BookmarkModel in order to provide an undo for those changes.
+class BookmarkUndoService : public BaseBookmarkModelObserver,
+ public BrowserContextKeyedService {
+ public:
+ explicit BookmarkUndoService(Profile* profile);
+ // This constructor is made available for tests.
+ explicit BookmarkUndoService(BookmarkModel* model);
sky 2013/07/18 14:35:41 Can you nuke this and use a TestingProfile?
Tom Cassiotis 2013/07/24 15:37:56 TestingProfile simplified the code. However, I am
+ virtual ~BookmarkUndoService();
+
+ UndoManager* GetUndoManager() { return &undo_manager_; }
sky 2013/07/18 14:35:41 undo_manager()
Tom Cassiotis 2013/07/24 15:37:56 Done.
+
+ private:
+ friend class ::BookmarkUndoOperation;
sky 2013/07/18 14:35:41 I'm not a fan of this. I would rather see Bookmark
Tom Cassiotis 2013/07/24 15:37:56 The removal of the bookmark id map made this easie
+
+ BookmarkModel* GetBookmarkModel();
+
+ // BaseBookmarkModelObserver:
+ virtual void BookmarkModelChanged() OVERRIDE {}
+ virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
+ virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
+ virtual void BookmarkNodeMoved(BookmarkModel* model,
+ const BookmarkNode* old_parent,
+ int old_index,
+ const BookmarkNode* new_parent,
+ int new_index) OVERRIDE;
+ virtual void BookmarkNodeAdded(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int index) OVERRIDE;
+ virtual void OnWillRemoveBookmarks(BookmarkModel* model,
+ const BookmarkNode* parent,
+ int old_index,
+ const BookmarkNode* node) OVERRIDE;
+ virtual void OnWillRemoveAllBookmarks(BookmarkModel* model) OVERRIDE;
+ virtual void OnWillChangeBookmarkNode(BookmarkModel* model,
+ const BookmarkNode* node) OVERRIDE;
+ virtual void OnWillReorderBookmarkNode(BookmarkModel* model,
+ const BookmarkNode* node) OVERRIDE;
+
+ Profile* profile_;
+ BookmarkModel* model_;
+ UndoManager undo_manager_;
+ BookmarkIdMap bookmark_id_map_;
+
+ DISALLOW_COPY_AND_ASSIGN(BookmarkUndoService);
+};
+
+#endif // CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_
« no previous file with comments | « no previous file | chrome/browser/undo/bookmark_undo_service.cc » ('j') | chrome/browser/undo/bookmark_undo_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698