Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / bookmarks / managed / managed_bookmarks_tracker.h
blobecd157d79a83a7045b4468e4e3be01c1c47c4816
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_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_
6 #define COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_
8 #include "base/callback_forward.h"
9 #include "base/macros.h"
10 #include "base/prefs/pref_change_registrar.h"
11 #include "base/strings/string16.h"
13 class GURL;
14 class PrefService;
16 namespace base {
17 class ListValue;
20 namespace bookmarks {
22 class BookmarkModel;
23 class BookmarkNode;
24 class BookmarkPermanentNode;
26 // Tracks either the Managed Bookmarks pref (set by policy) or the Supervised
27 // Bookmarks pref (set for a supervised user by their custodian) and makes the
28 // managed_node()/supervised_node() in the BookmarkModel follow the
29 // policy/custodian-defined bookmark tree.
30 class ManagedBookmarksTracker {
31 public:
32 typedef base::Callback<std::string()> GetManagementDomainCallback;
34 // Shared constants used in the policy configuration.
35 static const char kName[];
36 static const char kUrl[];
37 static const char kChildren[];
39 // If |is_supervised| is true, this will track supervised bookmarks rather
40 // than managed bookmarks.
41 ManagedBookmarksTracker(bookmarks::BookmarkModel* model,
42 PrefService* prefs,
43 bool is_supervised,
44 const GetManagementDomainCallback& callback);
45 ~ManagedBookmarksTracker();
47 // Returns the initial list of managed bookmarks, which can be passed to
48 // LoadInitial() to do the initial load.
49 scoped_ptr<base::ListValue> GetInitialManagedBookmarks();
51 // Loads the initial managed/supervised bookmarks in |list| into |folder|.
52 // New nodes will be assigned IDs starting at |next_node_id|.
53 // Returns the next node ID to use.
54 static int64 LoadInitial(bookmarks::BookmarkNode* folder,
55 const base::ListValue* list,
56 int64 next_node_id);
58 // Starts tracking the pref for updates to the managed/supervised bookmarks.
59 // Should be called after loading the initial bookmarks.
60 void Init(bookmarks::BookmarkPermanentNode* managed_node);
62 bool is_supervised() const { return is_supervised_; }
64 // Public for testing.
65 static const char* GetPrefName(bool is_supervised);
67 private:
68 const char* GetPrefName() const;
69 base::string16 GetBookmarksFolderTitle() const;
71 void ReloadManagedBookmarks();
73 void UpdateBookmarks(const bookmarks::BookmarkNode* folder,
74 const base::ListValue* list);
75 static bool LoadBookmark(const base::ListValue* list,
76 size_t index,
77 base::string16* title,
78 GURL* url,
79 const base::ListValue** children);
81 bookmarks::BookmarkModel* model_;
82 const bool is_supervised_;
83 bookmarks::BookmarkPermanentNode* managed_node_;
84 PrefService* prefs_;
85 PrefChangeRegistrar registrar_;
86 GetManagementDomainCallback get_management_domain_callback_;
88 DISALLOW_COPY_AND_ASSIGN(ManagedBookmarksTracker);
91 } // namespace bookmarks
93 #endif // COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_