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