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_BROWSER_BOOKMARK_CLIENT_H_ | 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_ |
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_ | 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/task/cancelable_task_tracker.h" | 15 #include "base/task/cancelable_task_tracker.h" |
15 #include "components/bookmarks/browser/bookmark_storage.h" | 16 #include "components/bookmarks/browser/bookmark_storage.h" |
16 #include "components/favicon_base/favicon_callback.h" | 17 #include "components/favicon_base/favicon_callback.h" |
17 #include "components/favicon_base/favicon_types.h" | 18 #include "components/favicon_base/favicon_types.h" |
18 #include "components/keyed_service/core/keyed_service.h" | |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 struct UserMetricsAction; | 23 struct UserMetricsAction; |
24 } | 24 } |
25 | 25 |
26 namespace bookmarks { | 26 namespace bookmarks { |
27 | 27 |
| 28 class BookmarkModel; |
28 class BookmarkNode; | 29 class BookmarkNode; |
29 class BookmarkPermanentNode; | 30 class BookmarkPermanentNode; |
30 | 31 |
31 // This class abstracts operations that depends on the embedder's environment, | 32 // This class abstracts operations that depends on the embedder's environment, |
32 // e.g. Chrome. | 33 // e.g. Chrome. |
33 class BookmarkClient : public KeyedService { | 34 class BookmarkClient { |
34 public: | 35 public: |
35 // Types representing a set of BookmarkNode and a mapping from BookmarkNode | 36 // Types representing a set of BookmarkNode and a mapping from BookmarkNode |
36 // to the number of time the corresponding URL has been typed by the user in | 37 // to the number of time the corresponding URL has been typed by the user in |
37 // the Omnibox. | 38 // the Omnibox. |
38 typedef std::set<const BookmarkNode*> NodeSet; | 39 typedef std::set<const BookmarkNode*> NodeSet; |
39 typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair; | 40 typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair; |
40 typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs; | 41 typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs; |
41 typedef base::Callback<void(BookmarkPermanentNode*, BookmarkPermanentNode*)> | 42 typedef base::Callback<void(BookmarkPermanentNode*, BookmarkPermanentNode*)> |
42 ExtraNodeLoadedCallback; | 43 ExtraNodeLoadedCallback; |
43 | 44 |
| 45 BookmarkClient(); |
| 46 virtual ~BookmarkClient(); |
| 47 |
| 48 // Called upon initialization of BookmarkModel. |
| 49 virtual void Init(BookmarkModel* bookmark_model) = 0; |
| 50 |
44 // Requests a favicon from the history cache for the web page at |page_url|. | 51 // Requests a favicon from the history cache for the web page at |page_url|. |
45 // |callback| is run when the favicon has been fetched. If |type| is: | 52 // |callback| is run when the favicon has been fetched. If |type| is: |
46 // - favicon_base::FAVICON, the returned gfx::Image is a multi-resolution | 53 // - favicon_base::FAVICON, the returned gfx::Image is a multi-resolution |
47 // image of gfx::kFaviconSize DIP width and height. The data from the | 54 // image of gfx::kFaviconSize DIP width and height. The data from the |
48 // history cache is resized if need be. | 55 // history cache is resized if need be. |
49 // - not favicon_base::FAVICON, the returned gfx::Image is a single-resolution | 56 // - not favicon_base::FAVICON, the returned gfx::Image is a single-resolution |
50 // image with the largest bitmap in the history cache for |page_url| and | 57 // image with the largest bitmap in the history cache for |page_url| and |
51 // |type|. | 58 // |type|. |
52 virtual base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( | 59 virtual base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( |
53 const GURL& page_url, | 60 const GURL& page_url, |
54 favicon_base::IconType type, | 61 favicon_base::IconType type, |
55 const favicon_base::FaviconImageCallback& callback, | 62 const favicon_base::FaviconImageCallback& callback, |
56 base::CancelableTaskTracker* tracker); | 63 base::CancelableTaskTracker* tracker) = 0; |
57 | 64 |
58 // Returns true if the embedder supports typed count for URL. | 65 // Returns true if the embedder supports typed count for URL. |
59 virtual bool SupportsTypedCountForNodes(); | 66 virtual bool SupportsTypedCountForNodes() = 0; |
60 | 67 |
61 // Retrieves the number of time each BookmarkNode URL has been typed in | 68 // Retrieves the number of time each BookmarkNode URL has been typed in |
62 // the Omnibox by the user. | 69 // the Omnibox by the user. |
63 virtual void GetTypedCountForNodes( | 70 virtual void GetTypedCountForNodes( |
64 const NodeSet& nodes, | 71 const NodeSet& nodes, |
65 NodeTypedCountPairs* node_typed_count_pairs); | 72 NodeTypedCountPairs* node_typed_count_pairs) = 0; |
66 | 73 |
67 // Wrapper around RecordAction defined in base/metrics/user_metrics.h | 74 // Wrapper around RecordAction defined in base/metrics/user_metrics.h |
68 // that ensure that the action is posted from the correct thread. | 75 // that ensure that the action is posted from the correct thread. |
69 virtual void RecordAction(const base::UserMetricsAction& action) = 0; | 76 virtual void RecordAction(const base::UserMetricsAction& action) = 0; |
70 | 77 |
71 // Returns a task that will be used to load any additional root nodes. This | 78 // Returns a task that will be used to load any additional root nodes. This |
72 // task will be invoked in the Profile's IO task runner. | 79 // task will be invoked in the Profile's IO task runner. |
73 virtual LoadExtraCallback GetLoadExtraNodesCallback( | 80 virtual LoadExtraCallback GetLoadExtraNodesCallback( |
74 scoped_ptr<BookmarkPermanentNode> managed_node, | 81 scoped_ptr<BookmarkPermanentNode> managed_node, |
75 scoped_ptr<BookmarkPermanentNode> supervised_node, | 82 scoped_ptr<BookmarkPermanentNode> supervised_node, |
76 const ExtraNodeLoadedCallback& callback) = 0; | 83 const ExtraNodeLoadedCallback& callback) = 0; |
77 | 84 |
78 // Called when BookmarkModel finished loading. | 85 // Called when BookmarkModel finished loading. |
79 virtual void DoneLoading(BookmarkPermanentNode* managed_node, | 86 virtual void DoneLoading(BookmarkPermanentNode* managed_node, |
80 BookmarkPermanentNode* supervised_node) = 0; | 87 BookmarkPermanentNode* supervised_node) = 0; |
81 | 88 |
82 protected: | 89 private: |
83 ~BookmarkClient() override {} | 90 DISALLOW_COPY_AND_ASSIGN(BookmarkClient); |
84 }; | 91 }; |
85 | 92 |
86 } // namespace bookmarks | 93 } // namespace bookmarks |
87 | 94 |
88 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_ | 95 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_ |
OLD | NEW |