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