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_EXPANDED_STATE_TRACKER_H_ 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_EXPANDED_STATE_TRACKER_H_ 7 8 #include <set> 9 10 #include "components/bookmarks/browser/base_bookmark_model_observer.h" 11 12 class BookmarkModel; 13 class BookmarkNode; 14 class PrefService; 15 16 namespace bookmarks { 17 18 // BookmarkExpandedStateTracker is used to track a set of expanded nodes. The 19 // nodes are persisted in preferences. If an expanded node is removed from the 20 // model BookmarkExpandedStateTracker removes the node. 21 class BookmarkExpandedStateTracker : public BaseBookmarkModelObserver { 22 public: 23 typedef std::set<const BookmarkNode*> Nodes; 24 25 BookmarkExpandedStateTracker(BookmarkModel* bookmark_model, 26 PrefService* pref_service); 27 virtual ~BookmarkExpandedStateTracker(); 28 29 // The set of expanded nodes. 30 void SetExpandedNodes(const Nodes& nodes); 31 Nodes GetExpandedNodes(); 32 33 private: 34 // BaseBookmarkModelObserver: 35 virtual void BookmarkModelLoaded(BookmarkModel* model, 36 bool ids_reassigned) OVERRIDE; 37 virtual void BookmarkModelChanged() OVERRIDE; 38 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; 39 virtual void BookmarkNodeRemoved(BookmarkModel* model, 40 const BookmarkNode* parent, 41 int old_index, 42 const BookmarkNode* node, 43 const std::set<GURL>& removed_urls) OVERRIDE; 44 virtual void BookmarkAllUserNodesRemoved( 45 BookmarkModel* model, 46 const std::set<GURL>& removed_urls) OVERRIDE; 47 48 // Updates the value for |prefs::kBookmarkEditorExpandedNodes| from 49 // GetExpandedNodes(). 50 void UpdatePrefs(const Nodes& nodes); 51 52 BookmarkModel* bookmark_model_; 53 PrefService* pref_service_; 54 55 DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTracker); 56 }; 57 58 } // namespace bookmarks 59 60 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_EXPANDED_STATE_TRACKER_H_ 61