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.
5 #ifndef COMPONENTS_UNDO_BOOKMARK_UNDO_SERVICE_H_
6 #define COMPONENTS_UNDO_BOOKMARK_UNDO_SERVICE_H_
10 #include "base/scoped_observer.h"
11 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
12 #include "components/bookmarks/browser/bookmark_node_data.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/undo/bookmark_renumber_observer.h"
15 #include "components/undo/undo_manager.h"
19 class BookmarkModelObserver
;
22 // BookmarkUndoService --------------------------------------------------------
24 // BookmarkUndoService is owned by the profile, and is responsible for observing
25 // BookmarkModel changes in order to provide an undo for those changes.
26 class BookmarkUndoService
: public bookmarks::BaseBookmarkModelObserver
,
28 public BookmarkRenumberObserver
{
30 BookmarkUndoService();
31 ~BookmarkUndoService() override
;
33 // Starts the BookmarkUndoService and register it as a BookmarkModelObserver.
34 // Calling this method is optional, but the service will be inactive until it
36 void Start(bookmarks::BookmarkModel
* model
);
38 UndoManager
* undo_manager() { return &undo_manager_
; }
41 void Shutdown() override
;
44 // bookmarks::BaseBookmarkModelObserver:
45 void BookmarkModelChanged() override
{}
46 void BookmarkModelLoaded(bookmarks::BookmarkModel
* model
,
47 bool ids_reassigned
) override
;
48 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel
* model
) override
;
49 void BookmarkNodeMoved(bookmarks::BookmarkModel
* model
,
50 const bookmarks::BookmarkNode
* old_parent
,
52 const bookmarks::BookmarkNode
* new_parent
,
53 int new_index
) override
;
54 void BookmarkNodeAdded(bookmarks::BookmarkModel
* model
,
55 const bookmarks::BookmarkNode
* parent
,
57 void OnWillRemoveBookmarks(bookmarks::BookmarkModel
* model
,
58 const bookmarks::BookmarkNode
* parent
,
60 const bookmarks::BookmarkNode
* node
) override
;
61 void OnWillRemoveAllUserBookmarks(bookmarks::BookmarkModel
* model
) override
;
62 void OnWillChangeBookmarkNode(bookmarks::BookmarkModel
* model
,
63 const bookmarks::BookmarkNode
* node
) override
;
64 void OnWillReorderBookmarkNode(bookmarks::BookmarkModel
* model
,
65 const bookmarks::BookmarkNode
* node
) override
;
66 void GroupedBookmarkChangesBeginning(
67 bookmarks::BookmarkModel
* model
) override
;
68 void GroupedBookmarkChangesEnded(bookmarks::BookmarkModel
* model
) override
;
70 // BookmarkRenumberObserver:
71 void OnBookmarkRenumbered(int64 old_id
, int64 new_id
) override
;
73 UndoManager undo_manager_
;
74 ScopedObserver
<bookmarks::BookmarkModel
, bookmarks::BookmarkModelObserver
>
77 DISALLOW_COPY_AND_ASSIGN(BookmarkUndoService
);
80 #endif // COMPONENTS_UNDO_BOOKMARK_UNDO_SERVICE_H_