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_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_
6 #define COMPONENTS_POLICY_CORE_BROWSER_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"
12 #include "components/policy/policy_export.h"
24 class BookmarkPermanentNode
;
29 // Tracks either the Managed Bookmarks pref (set by policy) or the Supervised
30 // Bookmarks pref (set for a supervised user by their custodian) and makes the
31 // managed_node()/supervised_node() in the BookmarkModel follow the
32 // policy/custodian-defined bookmark tree.
33 class POLICY_EXPORT ManagedBookmarksTracker
{
35 typedef base::Callback
<std::string()> GetManagementDomainCallback
;
37 // Shared constants used in the policy configuration.
38 static const char kName
[];
39 static const char kUrl
[];
40 static const char kChildren
[];
42 // If |is_supervised| is true, this will track supervised bookmarks rather
43 // than managed bookmarks.
44 ManagedBookmarksTracker(bookmarks::BookmarkModel
* model
,
47 const GetManagementDomainCallback
& callback
);
48 ~ManagedBookmarksTracker();
50 // Returns the initial list of managed bookmarks, which can be passed to
51 // LoadInitial() to do the initial load.
52 scoped_ptr
<base::ListValue
> GetInitialManagedBookmarks();
54 // Loads the initial managed/supervised bookmarks in |list| into |folder|.
55 // New nodes will be assigned IDs starting at |next_node_id|.
56 // Returns the next node ID to use.
57 static int64
LoadInitial(bookmarks::BookmarkNode
* folder
,
58 const base::ListValue
* list
,
61 // Starts tracking the pref for updates to the managed/supervised bookmarks.
62 // Should be called after loading the initial bookmarks.
63 void Init(bookmarks::BookmarkPermanentNode
* managed_node
);
65 bool is_supervised() const { return is_supervised_
; }
67 // Public for testing.
68 static const char* GetPrefName(bool is_supervised
);
71 const char* GetPrefName() const;
72 base::string16
GetBookmarksFolderTitle() const;
74 void ReloadManagedBookmarks();
76 void UpdateBookmarks(const bookmarks::BookmarkNode
* folder
,
77 const base::ListValue
* list
);
78 static bool LoadBookmark(const base::ListValue
* list
,
80 base::string16
* title
,
82 const base::ListValue
** children
);
84 bookmarks::BookmarkModel
* model_
;
85 const bool is_supervised_
;
86 bookmarks::BookmarkPermanentNode
* managed_node_
;
88 PrefChangeRegistrar registrar_
;
89 GetManagementDomainCallback get_management_domain_callback_
;
91 DISALLOW_COPY_AND_ASSIGN(ManagedBookmarksTracker
);
96 #endif // COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_