Popular sites on the NTP: Try to keep the ordering constant
[chromium-blink-merge.git] / components / bookmarks / browser / bookmark_expanded_state_tracker.h
bloba632226522c41b2b715e00dedd058fe6626fba10
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.
5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_EXPANDED_STATE_TRACKER_H_
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_EXPANDED_STATE_TRACKER_H_
8 #include <set>
10 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
12 class PrefService;
14 namespace bookmarks {
16 class BookmarkModel;
17 class BookmarkNode;
19 // BookmarkExpandedStateTracker is used to track a set of expanded nodes. The
20 // nodes are persisted in preferences. If an expanded node is removed from the
21 // model BookmarkExpandedStateTracker removes the node.
22 class BookmarkExpandedStateTracker : public BaseBookmarkModelObserver {
23 public:
24 typedef std::set<const BookmarkNode*> Nodes;
26 BookmarkExpandedStateTracker(BookmarkModel* bookmark_model,
27 PrefService* pref_service);
28 ~BookmarkExpandedStateTracker() override;
30 // The set of expanded nodes.
31 void SetExpandedNodes(const Nodes& nodes);
32 Nodes GetExpandedNodes();
34 private:
35 // BaseBookmarkModelObserver:
36 void BookmarkModelLoaded(BookmarkModel* model, bool ids_reassigned) override;
37 void BookmarkModelChanged() override;
38 void BookmarkModelBeingDeleted(BookmarkModel* model) override;
39 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 void BookmarkAllUserNodesRemoved(BookmarkModel* model,
45 const std::set<GURL>& removed_urls) override;
47 // Updates the value for |prefs::kBookmarkEditorExpandedNodes| from
48 // GetExpandedNodes().
49 void UpdatePrefs(const Nodes& nodes);
51 BookmarkModel* bookmark_model_;
52 PrefService* pref_service_;
54 DISALLOW_COPY_AND_ASSIGN(BookmarkExpandedStateTracker);
57 } // namespace bookmarks
59 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_EXPANDED_STATE_TRACKER_H_