| OLD | NEW |
| (Empty) |
| 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_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_ | |
| 6 #define COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_ | |
| 7 | |
| 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" | |
| 13 | |
| 14 class GURL; | |
| 15 class PrefService; | |
| 16 | |
| 17 namespace base { | |
| 18 class ListValue; | |
| 19 } | |
| 20 | |
| 21 namespace bookmarks { | |
| 22 class BookmarkModel; | |
| 23 class BookmarkNode; | |
| 24 class BookmarkPermanentNode; | |
| 25 } | |
| 26 | |
| 27 namespace policy { | |
| 28 | |
| 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 { | |
| 34 public: | |
| 35 typedef base::Callback<std::string()> GetManagementDomainCallback; | |
| 36 | |
| 37 // Shared constants used in the policy configuration. | |
| 38 static const char kName[]; | |
| 39 static const char kUrl[]; | |
| 40 static const char kChildren[]; | |
| 41 | |
| 42 // If |is_supervised| is true, this will track supervised bookmarks rather | |
| 43 // than managed bookmarks. | |
| 44 ManagedBookmarksTracker(bookmarks::BookmarkModel* model, | |
| 45 PrefService* prefs, | |
| 46 bool is_supervised, | |
| 47 const GetManagementDomainCallback& callback); | |
| 48 ~ManagedBookmarksTracker(); | |
| 49 | |
| 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(); | |
| 53 | |
| 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, | |
| 59 int64 next_node_id); | |
| 60 | |
| 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); | |
| 64 | |
| 65 bool is_supervised() const { return is_supervised_; } | |
| 66 | |
| 67 // Public for testing. | |
| 68 static const char* GetPrefName(bool is_supervised); | |
| 69 | |
| 70 private: | |
| 71 const char* GetPrefName() const; | |
| 72 base::string16 GetBookmarksFolderTitle() const; | |
| 73 | |
| 74 void ReloadManagedBookmarks(); | |
| 75 | |
| 76 void UpdateBookmarks(const bookmarks::BookmarkNode* folder, | |
| 77 const base::ListValue* list); | |
| 78 static bool LoadBookmark(const base::ListValue* list, | |
| 79 size_t index, | |
| 80 base::string16* title, | |
| 81 GURL* url, | |
| 82 const base::ListValue** children); | |
| 83 | |
| 84 bookmarks::BookmarkModel* model_; | |
| 85 const bool is_supervised_; | |
| 86 bookmarks::BookmarkPermanentNode* managed_node_; | |
| 87 PrefService* prefs_; | |
| 88 PrefChangeRegistrar registrar_; | |
| 89 GetManagementDomainCallback get_management_domain_callback_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(ManagedBookmarksTracker); | |
| 92 }; | |
| 93 | |
| 94 } // namespace policy | |
| 95 | |
| 96 #endif // COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_ | |
| 97 | |
| OLD | NEW |