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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_
12 #include "base/callback_forward.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "components/bookmarks/browser/bookmark_storage.h"
15 #include "components/favicon_base/favicon_callback.h"
16 #include "components/favicon_base/favicon_types.h"
17 #include "components/keyed_service/core/keyed_service.h"
20 class BookmarkPermanentNode
;
24 struct UserMetricsAction
;
29 // This class abstracts operations that depends on the embedder's environment,
31 class BookmarkClient
: public KeyedService
{
33 // Types representing a set of BookmarkNode and a mapping from BookmarkNode
34 // to the number of time the corresponding URL has been typed by the user in
36 typedef std::set
<const BookmarkNode
*> NodeSet
;
37 typedef std::pair
<const BookmarkNode
*, int> NodeTypedCountPair
;
38 typedef std::vector
<NodeTypedCountPair
> NodeTypedCountPairs
;
40 // Returns true if the embedder favors touch icons over favicons.
41 virtual bool PreferTouchIcon();
43 // Requests a favicon from the history cache for the web page at |page_url|.
44 // |callback| is run when the favicon has been fetched. If |type| is:
45 // - favicon_base::FAVICON, the returned gfx::Image is a multi-resolution
46 // image of gfx::kFaviconSize DIP width and height. The data from the
47 // history cache is resized if need be.
48 // - not favicon_base::FAVICON, the returned gfx::Image is a single-resolution
49 // image with the largest bitmap in the history cache for |page_url| and
51 virtual base::CancelableTaskTracker::TaskId
GetFaviconImageForPageURL(
53 favicon_base::IconType type
,
54 const favicon_base::FaviconImageCallback
& callback
,
55 base::CancelableTaskTracker
* tracker
);
57 // Returns true if the embedder supports typed count for URL.
58 virtual bool SupportsTypedCountForNodes();
60 // Retrieves the number of time each BookmarkNode URL has been typed in
61 // the Omnibox by the user.
62 virtual void GetTypedCountForNodes(
64 NodeTypedCountPairs
* node_typed_count_pairs
);
66 // Returns whether the embedder wants permanent node |node|
67 // to always be visible or to only show them when not empty.
68 virtual bool IsPermanentNodeVisible(const BookmarkPermanentNode
* node
) = 0;
70 // Wrapper around RecordAction defined in base/metrics/user_metrics.h
71 // that ensure that the action is posted from the correct thread.
72 virtual void RecordAction(const base::UserMetricsAction
& action
) = 0;
74 // Returns a task that will be used to load any additional root nodes. This
75 // task will be invoked in the Profile's IO task runner.
76 virtual LoadExtraCallback
GetLoadExtraNodesCallback() = 0;
78 // Returns true if the |permanent_node| can have its title updated.
79 virtual bool CanSetPermanentNodeTitle(const BookmarkNode
* permanent_node
) = 0;
81 // Returns true if |node| should sync.
82 virtual bool CanSyncNode(const BookmarkNode
* node
) = 0;
84 // Returns true if this node can be edited by the user.
85 // TODO(joaodasilva): the model should check this more aggressively, and
86 // should give the client a means to temporarily disable those checks.
87 // http://crbug.com/49598
88 virtual bool CanBeEditedByUser(const BookmarkNode
* node
) = 0;
91 ~BookmarkClient() override
{}
94 } // namespace bookmarks
96 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_