bookmark_client.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
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.
4
5#ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_
6#define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_
7
8#include <set>
9#include <utility>
10#include <vector>
11
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
17class BookmarkNode;
18class BookmarkPermanentNode;
19class GURL;
20
21namespace base {
22struct UserMetricsAction;
23}
24
25// This class abstracts operations that depends on the embedder's environment,
26// e.g. Chrome.
27class BookmarkClient {
28 public:
29  // Types representing a set of BookmarkNode and a mapping from BookmarkNode
30  // to the number of time the corresponding URL has been typed by the user in
31  // the Omnibox.
32  typedef std::set<const BookmarkNode*> NodeSet;
33  typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair;
34  typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs;
35
36  // Returns true if the embedder favors touch icons over favicons.
37  virtual bool PreferTouchIcon();
38
39  // Requests the favicon of any of |icon_types| whose pixel sizes most
40  // closely match |desired_size_in_dip| (if value is 0, the largest favicon
41  // is returned) and desired scale factor for |page_url|. |callback| is run
42  // when the bits have been fetched. |icon_types| can be any combination of
43  // IconType value, but only one icon will be returned.
44  virtual base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
45      const GURL& page_url,
46      int icon_types,
47      int desired_size_in_dip,
48      const favicon_base::FaviconImageCallback& callback,
49      base::CancelableTaskTracker* tracker);
50
51  // Returns true if the embedder supports typed count for URL.
52  virtual bool SupportsTypedCountForNodes();
53
54  // Retrieves the number of time each BookmarkNode URL has been typed in
55  // the Omnibox by the user.
56  virtual void GetTypedCountForNodes(
57      const NodeSet& nodes,
58      NodeTypedCountPairs* node_typed_count_pairs);
59
60  // Returns whether the embedder wants permanent node |node|
61  // to always be visible or to only show them when not empty.
62  virtual bool IsPermanentNodeVisible(const BookmarkPermanentNode* node) = 0;
63
64  // Wrapper around RecordAction defined in base/metrics/user_metrics.h
65  // that ensure that the action is posted from the correct thread.
66  virtual void RecordAction(const base::UserMetricsAction& action) = 0;
67
68  // Returns a task that will be used to load any additional root nodes. This
69  // task will be invoked in the Profile's IO task runner.
70  virtual bookmarks::LoadExtraCallback GetLoadExtraNodesCallback() = 0;
71
72  // Returns true if the |permanent_node| can have its title updated.
73  virtual bool CanSetPermanentNodeTitle(const BookmarkNode* permanent_node) = 0;
74
75  // Returns true if |node| should sync.
76  virtual bool CanSyncNode(const BookmarkNode* node) = 0;
77
78  // Returns true if this node can be edited by the user.
79  // TODO(joaodasilva): the model should check this more aggressively, and
80  // should give the client a means to temporarily disable those checks.
81  // http://crbug.com/49598
82  virtual bool CanBeEditedByUser(const BookmarkNode* node) = 0;
83
84 protected:
85  virtual ~BookmarkClient() {}
86};
87
88#endif  // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_CLIENT_H_
89