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