| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ |
| 6 #define COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ | 6 #define COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "components/bookmarks/browser/bookmark_client.h" | 9 #include "components/bookmarks/browser/bookmark_client.h" |
| 10 | 10 |
| 11 namespace bookmarks { | 11 namespace bookmarks { |
| 12 | 12 |
| 13 class BookmarkModel; | 13 class BookmarkModel; |
| 14 | 14 |
| 15 class TestBookmarkClient : public BookmarkClient { | 15 class TestBookmarkClient : public BookmarkClient { |
| 16 public: | 16 public: |
| 17 TestBookmarkClient(); | 17 // Creates a BookmarkModel with a TestBookmarkClient initialized with |
| 18 ~TestBookmarkClient() override; | 18 // |extra_nodes| and return the TestBookmarkClient via |client| if non-null. |
| 19 static scoped_ptr<BookmarkModel> CreateModel( |
| 20 BookmarkPermanentNodeList extra_nodes, |
| 21 TestBookmarkClient** client, |
| 22 bool no_load); |
| 19 | 23 |
| 20 // Create a BookmarkModel using this object as its client. The returned | 24 // Helper for CreateModel passing an empty BookmarkPermanentNodeList. |
| 21 // BookmarkModel* is owned by the caller. | 25 static scoped_ptr<BookmarkModel> CreateModel(TestBookmarkClient** client); |
| 22 scoped_ptr<BookmarkModel> CreateModel(); | 26 static scoped_ptr<BookmarkModel> CreateModel(); |
| 23 | |
| 24 // Sets the list of extra nodes to be returned by the next call to | |
| 25 // CreateModel() or GetLoadExtraNodesCallback(). | |
| 26 void SetExtraNodesToLoad(BookmarkPermanentNodeList extra_nodes); | |
| 27 | 27 |
| 28 // Returns the current extra_nodes, set via SetExtraNodesToLoad(). | 28 // Returns the current extra_nodes, set via SetExtraNodesToLoad(). |
| 29 const std::vector<BookmarkPermanentNode*>& extra_nodes() { | 29 const std::vector<BookmarkPermanentNode*>& extra_nodes() { |
| 30 return extra_nodes_; | 30 return extra_nodes_; |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Returns true if |node| is one of the |extra_nodes_|. | 33 // Returns true if |node| is one of the |extra_nodes_|. |
| 34 bool IsExtraNodeRoot(const BookmarkNode* node); | 34 bool IsExtraNodeRoot(const BookmarkNode* node); |
| 35 | 35 |
| 36 // Returns true if |node| belongs to the tree of one of the |extra_nodes_|. | 36 // Returns true if |node| belongs to the tree of one of the |extra_nodes_|. |
| 37 bool IsAnExtraNode(const BookmarkNode* node); | 37 bool IsAnExtraNode(const BookmarkNode* node); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 TestBookmarkClient(); |
| 41 ~TestBookmarkClient() override; |
| 42 |
| 43 // Sets the list of extra nodes to be returned by the next call to |
| 44 // CreateModel() or GetLoadExtraNodesCallback(). |
| 45 void SetExtraNodesToLoad(BookmarkPermanentNodeList extra_nodes); |
| 46 |
| 40 // BookmarkClient: | 47 // BookmarkClient: |
| 48 void Init(BookmarkModel* bookmark_model) override; |
| 49 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( |
| 50 const GURL& page_url, |
| 51 favicon_base::IconType type, |
| 52 const favicon_base::FaviconImageCallback& callback, |
| 53 base::CancelableTaskTracker* tracker) override; |
| 54 bool SupportsTypedCountForNodes() override; |
| 55 void GetTypedCountForNodes( |
| 56 const NodeSet& nodes, |
| 57 NodeTypedCountPairs* node_typed_count_pairs) override; |
| 41 void RecordAction(const base::UserMetricsAction& action) override; | 58 void RecordAction(const base::UserMetricsAction& action) override; |
| 42 LoadExtraCallback GetLoadExtraNodesCallback( | 59 LoadExtraCallback GetLoadExtraNodesCallback( |
| 43 scoped_ptr<BookmarkPermanentNode> managed_node, | 60 scoped_ptr<BookmarkPermanentNode> managed_node, |
| 44 scoped_ptr<BookmarkPermanentNode> supervised_node, | 61 scoped_ptr<BookmarkPermanentNode> supervised_node, |
| 45 const ExtraNodeLoadedCallback& callback) override; | 62 const ExtraNodeLoadedCallback& callback) override; |
| 46 void DoneLoading(BookmarkPermanentNode* managed_node, | 63 void DoneLoading(BookmarkPermanentNode* managed_node, |
| 47 BookmarkPermanentNode* supervised_node) override; | 64 BookmarkPermanentNode* supervised_node) override; |
| 48 | 65 |
| 49 // Helpers for GetLoadExtraNodesCallback(). | 66 // Helpers for GetLoadExtraNodesCallback(). |
| 50 static BookmarkPermanentNodeList LoadExtraNodes( | 67 static BookmarkPermanentNodeList LoadExtraNodes( |
| 51 BookmarkPermanentNodeList extra_nodes, | 68 BookmarkPermanentNodeList extra_nodes, |
| 52 int64* next_id); | 69 int64* next_id); |
| 53 | 70 |
| 54 BookmarkPermanentNodeList extra_nodes_to_load_; | 71 BookmarkPermanentNodeList extra_nodes_to_load_; |
| 55 std::vector<BookmarkPermanentNode*> extra_nodes_; | 72 std::vector<BookmarkPermanentNode*> extra_nodes_; |
| 56 | 73 |
| 57 DISALLOW_COPY_AND_ASSIGN(TestBookmarkClient); | 74 DISALLOW_COPY_AND_ASSIGN(TestBookmarkClient); |
| 58 }; | 75 }; |
| 59 | 76 |
| 60 } // namespace bookmarks | 77 } // namespace bookmarks |
| 61 | 78 |
| 62 #endif // COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ | 79 #endif // COMPONENTS_BOOKMARKS_TEST_TEST_BOOKMARK_CLIENT_H_ |
| OLD | NEW |