// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_ #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_ #include #include #include "base/macros.h" #include "base/memory/scoped_ptr.h" namespace base { class DictionaryValue; class ListValue; } // This class converts bookmarks from supervised user settings into a tree of // base::Values, for use in bookmarks::prefs::kSupervisedBookmarks. class SupervisedUserBookmarksHandler { public: static scoped_ptr BuildBookmarksTree( const base::DictionaryValue& settings); // Public for testing only. struct Folder { Folder(int id, const std::string& name, int parent_id); int id; std::string name; int parent_id; }; struct Link { Link(const std::string& url, const std::string& name, int parent_id); std::string url; std::string name; int parent_id; }; private: friend class SupervisedUserBookmarksHandlerTest; SupervisedUserBookmarksHandler(); ~SupervisedUserBookmarksHandler(); void ParseSettings(const base::DictionaryValue& settings); void ParseFolders(const base::DictionaryValue& folders); void ParseLinks(const base::DictionaryValue& links); scoped_ptr BuildTree(); void AddFoldersToTree(); void AddLinksToTree(); bool AddNodeToTree(int parent_id, scoped_ptr node); const std::vector& folders_for_testing() const { return folders_; } const std::vector& links_for_testing() const { return links_; } std::vector folders_; std::vector links_; scoped_ptr root_; DISALLOW_COPY_AND_ASSIGN(SupervisedUserBookmarksHandler); }; #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_BOOKMARKS_HANDLER_H_