Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_ | |
| 6 #define CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | |
| 11 #include "chrome/browser/bookmarks/bookmark_node_data.h" | |
| 12 #include "chrome/browser/undo/undo_manager.h" | |
| 13 #include "components/browser_context_keyed_service/browser_context_keyed_service .h" | |
| 14 | |
| 15 class Profile; | |
| 16 namespace { | |
| 17 class BookmarkUndoOperation; | |
| 18 } // namespace | |
| 19 | |
| 20 // BookmarkIdMap ------------------------------------------------------- | |
| 21 | |
| 22 // Keeps a record of the bookmark identifiers as they change as a result of | |
| 23 // user actions and the undo system. | |
| 24 // | |
| 25 // For example, an existing bookmark is modified and then deleted, the undo of | |
| 26 // the deletion would recreate the bookmark but with a different id. In order | |
| 27 // for the undo of the earlier modification to occur the new id should be | |
| 28 // associated with the old id and be retrieved to undo the modification. | |
| 29 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
| |
| 30 public: | |
| 31 BookmarkIdMap(); | |
| 32 virtual ~BookmarkIdMap(); | |
| 33 | |
| 34 // Retrieve the valid bookmark id given a possibly old id. | |
| 35 int64 GetCurrentId(int64 old_index); | |
| 36 | |
| 37 // Associate an old bookmark id with a new id. | |
| 38 void AddMapping(int64 old_index, int64 new_index); | |
| 39 | |
| 40 // Recursively identify changed ids after bookmarks have been pasted. | |
| 41 void ExtractMappings(BookmarkModel* model, | |
| 42 const BookmarkNodeData::Element& element, | |
| 43 const BookmarkNode* parent, | |
| 44 int index_added_at); | |
| 45 private: | |
| 46 std::map<int64, int64> identifier_map_; | |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(BookmarkIdMap); | |
| 49 }; | |
| 50 | |
| 51 // BookmarkUndoService -------------------------------------------------------- | |
| 52 | |
| 53 // BookmarkUndoService is owned by the profile, and is responsible for observing | |
| 54 // changes to the BookmarkModel in order to provide an undo for those changes. | |
| 55 class BookmarkUndoService : public BaseBookmarkModelObserver, | |
| 56 public BrowserContextKeyedService { | |
| 57 public: | |
| 58 explicit BookmarkUndoService(Profile* profile); | |
| 59 // This constructor is made available for tests. | |
| 60 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
| |
| 61 virtual ~BookmarkUndoService(); | |
| 62 | |
| 63 UndoManager* GetUndoManager() { return &undo_manager_; } | |
|
sky
2013/07/18 14:35:41
undo_manager()
Tom Cassiotis
2013/07/24 15:37:56
Done.
| |
| 64 | |
| 65 private: | |
| 66 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
| |
| 67 | |
| 68 BookmarkModel* GetBookmarkModel(); | |
| 69 | |
| 70 // BaseBookmarkModelObserver: | |
| 71 virtual void BookmarkModelChanged() OVERRIDE {} | |
| 72 virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; | |
| 73 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; | |
| 74 virtual void BookmarkNodeMoved(BookmarkModel* model, | |
| 75 const BookmarkNode* old_parent, | |
| 76 int old_index, | |
| 77 const BookmarkNode* new_parent, | |
| 78 int new_index) OVERRIDE; | |
| 79 virtual void BookmarkNodeAdded(BookmarkModel* model, | |
| 80 const BookmarkNode* parent, | |
| 81 int index) OVERRIDE; | |
| 82 virtual void OnWillRemoveBookmarks(BookmarkModel* model, | |
| 83 const BookmarkNode* parent, | |
| 84 int old_index, | |
| 85 const BookmarkNode* node) OVERRIDE; | |
| 86 virtual void OnWillRemoveAllBookmarks(BookmarkModel* model) OVERRIDE; | |
| 87 virtual void OnWillChangeBookmarkNode(BookmarkModel* model, | |
| 88 const BookmarkNode* node) OVERRIDE; | |
| 89 virtual void OnWillReorderBookmarkNode(BookmarkModel* model, | |
| 90 const BookmarkNode* node) OVERRIDE; | |
| 91 | |
| 92 Profile* profile_; | |
| 93 BookmarkModel* model_; | |
| 94 UndoManager undo_manager_; | |
| 95 BookmarkIdMap bookmark_id_map_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(BookmarkUndoService); | |
| 98 }; | |
| 99 | |
| 100 #endif // CHROME_BROWSER_UNDO_BOOKMARK_UNDO_SERVICE_H_ | |
| OLD | NEW |