• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_
6 #define CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_
7 
8 #include <vector>
9 
10 #include "base/deferred_sequenced_task_runner.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
14 #include "components/bookmarks/browser/bookmark_client.h"
15 #include "components/policy/core/browser/managed_bookmarks_tracker.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 
19 class BookmarkModel;
20 class Profile;
21 
22 class ChromeBookmarkClient : public BookmarkClient,
23                              public content::NotificationObserver,
24                              public BaseBookmarkModelObserver {
25  public:
26   explicit ChromeBookmarkClient(Profile* profile);
27   virtual ~ChromeBookmarkClient();
28 
29   void Init(BookmarkModel* model);
30 
31   // KeyedService:
32   virtual void Shutdown() OVERRIDE;
33 
34   // Returns the managed_node.
managed_node()35   const BookmarkNode* managed_node() { return managed_node_; }
36 
37   // Returns true if the given node belongs to the managed bookmarks tree.
38   bool IsDescendantOfManagedNode(const BookmarkNode* node);
39 
40   // Returns true if there is at least one managed node in the |list|.
41   bool HasDescendantsOfManagedNode(
42       const std::vector<const BookmarkNode*>& list);
43 
44   // BookmarkClient:
45   virtual bool PreferTouchIcon() OVERRIDE;
46   virtual base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
47       const GURL& page_url,
48       int icon_types,
49       int desired_size_in_dip,
50       const favicon_base::FaviconImageCallback& callback,
51       base::CancelableTaskTracker* tracker) OVERRIDE;
52   virtual bool SupportsTypedCountForNodes() OVERRIDE;
53   virtual void GetTypedCountForNodes(
54       const NodeSet& nodes,
55       NodeTypedCountPairs* node_typed_count_pairs) OVERRIDE;
56   virtual bool IsPermanentNodeVisible(
57       const BookmarkPermanentNode* node) OVERRIDE;
58   virtual void RecordAction(const base::UserMetricsAction& action) OVERRIDE;
59   virtual bookmarks::LoadExtraCallback GetLoadExtraNodesCallback() OVERRIDE;
60   virtual bool CanSetPermanentNodeTitle(
61       const BookmarkNode* permanent_node) OVERRIDE;
62   virtual bool CanSyncNode(const BookmarkNode* node) OVERRIDE;
63   virtual bool CanBeEditedByUser(const BookmarkNode* node) OVERRIDE;
64 
65   // content::NotificationObserver:
66   virtual void Observe(int type,
67                        const content::NotificationSource& source,
68                        const content::NotificationDetails& details) OVERRIDE;
69 
70  private:
71   // BaseBookmarkModelObserver:
72   virtual void BookmarkModelChanged() OVERRIDE;
73   virtual void BookmarkNodeRemoved(BookmarkModel* model,
74                                    const BookmarkNode* parent,
75                                    int old_index,
76                                    const BookmarkNode* node,
77                                    const std::set<GURL>& removed_urls) OVERRIDE;
78   virtual void BookmarkAllUserNodesRemoved(
79       BookmarkModel* model,
80       const std::set<GURL>& removed_urls) OVERRIDE;
81   virtual void BookmarkModelLoaded(BookmarkModel* model,
82                                    bool ids_reassigned) OVERRIDE;
83 
84   // Helper for GetLoadExtraNodesCallback().
85   static bookmarks::BookmarkPermanentNodeList LoadExtraNodes(
86       const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner,
87       BookmarkPermanentNode* managed_node,
88       scoped_ptr<base::ListValue> initial_managed_bookmarks,
89       int64* next_node_id);
90 
91   // Returns the management domain that configured the managed bookmarks,
92   // or an empty string.
93   std::string GetManagedBookmarksDomain();
94 
95   Profile* profile_;
96 
97   content::NotificationRegistrar registrar_;
98 
99   // Pointer to the BookmarkModel. Will be non-NULL from the call to Init to
100   // the call to Shutdown. Must be valid for the whole interval.
101   BookmarkModel* model_;
102 
103   scoped_ptr<policy::ManagedBookmarksTracker> managed_bookmarks_tracker_;
104   BookmarkPermanentNode* managed_node_;
105 
106   DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient);
107 };
108 
109 #endif  // CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_
110