OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 |
| 14 namespace base { |
| 15 class DictionaryValue; |
| 16 class ListValue; |
| 17 } |
| 18 |
| 19 // This class converts bookmarks from supervised user settings into a tree of |
| 20 // base::Values, for use in bookmarks::prefs::kSupervisedBookmarks. |
| 21 class SupervisedUserBookmarksHandler { |
| 22 public: |
| 23 static scoped_ptr<base::ListValue> BuildBookmarksTree( |
| 24 const base::DictionaryValue& settings); |
| 25 |
| 26 // Public for testing only. |
| 27 struct Folder { |
| 28 Folder(int id, const std::string& name, int parent_id); |
| 29 |
| 30 int id; |
| 31 std::string name; |
| 32 int parent_id; |
| 33 }; |
| 34 |
| 35 struct Link { |
| 36 Link(const std::string& url, const std::string& name, int parent_id); |
| 37 |
| 38 std::string url; |
| 39 std::string name; |
| 40 int parent_id; |
| 41 }; |
| 42 |
| 43 private: |
| 44 friend class SupervisedUserBookmarksHandlerTest; |
| 45 |
| 46 SupervisedUserBookmarksHandler(); |
| 47 ~SupervisedUserBookmarksHandler(); |
| 48 |
| 49 void ParseSettings(const base::DictionaryValue& settings); |
| 50 void ParseFolders(const base::DictionaryValue& folders); |
| 51 void ParseLinks(const base::DictionaryValue& links); |
| 52 scoped_ptr<base::ListValue> BuildTree(); |
| 53 void AddFoldersToTree(); |
| 54 void AddLinksToTree(); |
| 55 bool AddNodeToTree(int parent_id, scoped_ptr<base::DictionaryValue> node); |
| 56 |
| 57 const std::vector<Folder>& folders_for_testing() const { return folders_; } |
| 58 const std::vector<Link>& links_for_testing() const { return links_; } |
| 59 |
| 60 std::vector<Folder> folders_; |
| 61 std::vector<Link> links_; |
| 62 |
| 63 scoped_ptr<base::ListValue> root_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(SupervisedUserBookmarksHandler); |
| 66 }; |
| 67 |
| 68 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_ |
OLD | NEW |