Home | History | Annotate | Download | only in bookmarks
      1 // Copyright (c) 2012 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_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_H_
      6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_H_
      7 
      8 class BookmarkModel;
      9 class BookmarkNode;
     10 
     11 // Observer for the BookmarkModel.
     12 class BookmarkModelObserver {
     13  public:
     14   // Invoked when the model has finished loading. |ids_reassigned| mirrors
     15   // that of BookmarkLoadDetails::ids_reassigned. See it for details.
     16   virtual void Loaded(BookmarkModel* model, bool ids_reassigned) = 0;
     17 
     18   // Invoked from the destructor of the BookmarkModel.
     19   virtual void BookmarkModelBeingDeleted(BookmarkModel* model) {}
     20 
     21   // Invoked when a node has moved.
     22   virtual void BookmarkNodeMoved(BookmarkModel* model,
     23                                  const BookmarkNode* old_parent,
     24                                  int old_index,
     25                                  const BookmarkNode* new_parent,
     26                                  int new_index) = 0;
     27 
     28   // Invoked when a node has been added.
     29   virtual void BookmarkNodeAdded(BookmarkModel* model,
     30                                  const BookmarkNode* parent,
     31                                  int index) = 0;
     32 
     33   // Invoked before a node is removed.
     34   // |parent| the parent of the node that will be removed.
     35   // |old_index| the index of the node about to be removed in |parent|.
     36   // |node| is the node to be removed.
     37   virtual void OnWillRemoveBookmarks(BookmarkModel* model,
     38                                      const BookmarkNode* parent,
     39                                      int old_index,
     40                                      const BookmarkNode* node) {}
     41 
     42   // Invoked when a node has been removed, the item may still be starred though.
     43   // |parent| the parent of the node that was removed.
     44   // |old_index| the index of the removed node in |parent| before it was
     45   // removed.
     46   // |node| is the node that was removed.
     47   virtual void BookmarkNodeRemoved(BookmarkModel* model,
     48                                    const BookmarkNode* parent,
     49                                    int old_index,
     50                                    const BookmarkNode* node) = 0;
     51 
     52   // Invoked before the title or url of a node is changed.
     53   virtual void OnWillChangeBookmarkNode(BookmarkModel* model,
     54                                         const BookmarkNode* node) {}
     55 
     56   // Invoked when the title or url of a node changes.
     57   virtual void BookmarkNodeChanged(BookmarkModel* model,
     58                                    const BookmarkNode* node) = 0;
     59 
     60   // Invoked when a favicon has been loaded or changed.
     61   virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
     62                                           const BookmarkNode* node) = 0;
     63 
     64   // Invoked before the direct children of |node| have been reordered in some
     65   // way, such as sorted.
     66   virtual void OnWillReorderBookmarkNode(BookmarkModel* model,
     67                                          const BookmarkNode* node) {}
     68 
     69   // Invoked when the children (just direct children, not descendants) of
     70   // |node| have been reordered in some way, such as sorted.
     71   virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
     72                                              const BookmarkNode* node) = 0;
     73 
     74   // Invoked before an extensive set of model changes is about to begin.
     75   // This tells UI intensive observers to wait until the updates finish to
     76   // update themselves.
     77   // These methods should only be used for imports and sync.
     78   // Observers should still respond to BookmarkNodeRemoved immediately,
     79   // to avoid holding onto stale node pointers.
     80   virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) {}
     81 
     82   // Invoked after an extensive set of model changes has ended.
     83   // This tells observers to update themselves if they were waiting for the
     84   // update to finish.
     85   virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) {}
     86 
     87   // Invoked before all non-permanent bookmark nodes are removed.
     88   virtual void OnWillRemoveAllBookmarks(BookmarkModel* model) {}
     89 
     90   // Invoked when all non-permanent bookmark nodes have been removed.
     91   virtual void BookmarkAllNodesRemoved(BookmarkModel* model) = 0;
     92 
     93  protected:
     94   virtual ~BookmarkModelObserver() {}
     95 };
     96 
     97 #endif  // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_OBSERVER_H_
     98