1// Copyright 2014 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 COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_OBSERVER_H_
6#define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_OBSERVER_H_
7
8#include <set>
9
10class BookmarkModel;
11class BookmarkNode;
12class GURL;
13
14// Observer for the BookmarkModel.
15class BookmarkModelObserver {
16 public:
17  // Invoked when the model has finished loading. |ids_reassigned| mirrors
18  // that of BookmarkLoadDetails::ids_reassigned. See it for details.
19  virtual void BookmarkModelLoaded(BookmarkModel* model,
20                                   bool ids_reassigned) = 0;
21
22  // Invoked from the destructor of the BookmarkModel.
23  virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {}
24
25  // Invoked when a node has moved.
26  virtual void BookmarkNodeMoved(BookmarkModel* model,
27                                 const BookmarkNode* old_parent,
28                                 int old_index,
29                                 const BookmarkNode* new_parent,
30                                 int new_index) = 0;
31
32  // Invoked when a node has been added.
33  virtual void BookmarkNodeAdded(BookmarkModel* model,
34                                 const BookmarkNode* parent,
35                                 int index) = 0;
36
37  // Invoked before a node is removed.
38  // |parent| the parent of the node that will be removed.
39  // |old_index| the index of the node about to be removed in |parent|.
40  // |node| is the node to be removed.
41  virtual void OnWillRemoveBookmarks(BookmarkModel* model,
42                                     const BookmarkNode* parent,
43                                     int old_index,
44                                     const BookmarkNode* node) {}
45
46  // Invoked when a node has been removed, the item may still be starred though.
47  // |parent| the parent of the node that was removed.
48  // |old_index| the index of the removed node in |parent| before it was
49  // removed.
50  // |node| is the node that was removed.
51  // |removed_urls| is populated with the urls which no longer have any
52  // bookmarks associated with them.
53  virtual void BookmarkNodeRemoved(BookmarkModel* model,
54                                   const BookmarkNode* parent,
55                                   int old_index,
56                                   const BookmarkNode* node,
57                                   const std::set<GURL>& removed_urls) = 0;
58
59  // Invoked before the title or url of a node is changed.
60  virtual void OnWillChangeBookmarkNode(BookmarkModel* model,
61                                        const BookmarkNode* node) {}
62
63  // Invoked when the title or url of a node changes.
64  virtual void BookmarkNodeChanged(BookmarkModel* model,
65                                   const BookmarkNode* node) = 0;
66
67  // Invoked before the metainfo of a node is changed.
68  virtual void OnWillChangeBookmarkMetaInfo(BookmarkModel* model,
69                                            const BookmarkNode* node) {}
70
71  // Invoked when the metainfo on a node changes.
72  virtual void BookmarkMetaInfoChanged(BookmarkModel* model,
73                                       const BookmarkNode* node) {}
74
75  // Invoked when a favicon has been loaded or changed.
76  virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
77                                          const BookmarkNode* node) = 0;
78
79  // Invoked before the direct children of |node| have been reordered in some
80  // way, such as sorted.
81  virtual void OnWillReorderBookmarkNode(BookmarkModel* model,
82                                         const BookmarkNode* node) {}
83
84  // Invoked when the children (just direct children, not descendants) of
85  // |node| have been reordered in some way, such as sorted.
86  virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
87                                             const BookmarkNode* node) = 0;
88
89  // Invoked before an extensive set of model changes is about to begin.
90  // This tells UI intensive observers to wait until the updates finish to
91  // update themselves.
92  // These methods should only be used for imports and sync.
93  // Observers should still respond to BookmarkNodeRemoved immediately,
94  // to avoid holding onto stale node pointers.
95  virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) {}
96
97  // Invoked after an extensive set of model changes has ended.
98  // This tells observers to update themselves if they were waiting for the
99  // update to finish.
100  virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) {}
101
102  // Invoked before all non-permanent bookmark nodes that are editable by
103  // the user are removed.
104  virtual void OnWillRemoveAllUserBookmarks(BookmarkModel* model) {}
105
106  // Invoked when all non-permanent bookmark nodes that are editable by the
107  // user have been removed.
108  // |removed_urls| is populated with the urls which no longer have any
109  // bookmarks associated with them.
110  virtual void BookmarkAllUserNodesRemoved(
111      BookmarkModel* model,
112      const std::set<GURL>& removed_urls) = 0;
113
114  // Invoked before a set of model changes that is initiated by a single user
115  // action. For example, this is called a single time when pasting from the
116  // clipboard before each pasted bookmark is added to the bookmark model.
117  virtual void GroupedBookmarkChangesBeginning(BookmarkModel* model) {}
118
119  // Invoked after a set of model changes triggered by a single user action has
120  // ended.
121  virtual void GroupedBookmarkChangesEnded(BookmarkModel* model) {}
122
123 protected:
124  virtual ~BookmarkModelObserver() {}
125};
126
127#endif  // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_MODEL_OBSERVER_H_
128