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 CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_
6 #define CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_
11 #include "base/callback_list.h"
12 #include "base/deferred_sequenced_task_runner.h"
13 #include "base/macros.h"
14 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
15 #include "components/bookmarks/browser/bookmark_client.h"
18 class HistoryServiceFactory
;
28 class BookmarkPermanentNode
;
29 class ManagedBookmarksTracker
;
36 class ChromeBookmarkClient
: public bookmarks::BookmarkClient
,
37 public bookmarks::BaseBookmarkModelObserver
{
39 explicit ChromeBookmarkClient(Profile
* profile
);
40 ~ChromeBookmarkClient() override
;
42 void Init(bookmarks::BookmarkModel
* model
);
45 void Shutdown() override
;
47 // The top-level managed bookmarks folder, defined by an enterprise policy.
48 const bookmarks::BookmarkNode
* managed_node() { return managed_node_
; }
49 // The top-level supervised bookmarks folder, defined by the custodian of a
51 const bookmarks::BookmarkNode
* supervised_node() { return supervised_node_
; }
53 // bookmarks::BookmarkClient:
54 bool PreferTouchIcon() override
;
55 base::CancelableTaskTracker::TaskId
GetFaviconImageForPageURL(
57 favicon_base::IconType type
,
58 const favicon_base::FaviconImageCallback
& callback
,
59 base::CancelableTaskTracker
* tracker
) override
;
60 bool SupportsTypedCountForNodes() override
;
61 void GetTypedCountForNodes(
63 NodeTypedCountPairs
* node_typed_count_pairs
) override
;
64 bool IsPermanentNodeVisible(
65 const bookmarks::BookmarkPermanentNode
* node
) override
;
66 void RecordAction(const base::UserMetricsAction
& action
) override
;
67 bookmarks::LoadExtraCallback
GetLoadExtraNodesCallback() override
;
68 bool CanSetPermanentNodeTitle(
69 const bookmarks::BookmarkNode
* permanent_node
) override
;
70 bool CanSyncNode(const bookmarks::BookmarkNode
* node
) override
;
71 bool CanBeEditedByUser(const bookmarks::BookmarkNode
* node
) override
;
74 friend class HistoryServiceFactory
;
75 void SetHistoryService(history::HistoryService
* history_service
);
77 // bookmarks::BaseBookmarkModelObserver:
78 void BookmarkModelChanged() override
;
79 void BookmarkNodeRemoved(bookmarks::BookmarkModel
* model
,
80 const bookmarks::BookmarkNode
* parent
,
82 const bookmarks::BookmarkNode
* node
,
83 const std::set
<GURL
>& removed_urls
) override
;
84 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel
* model
,
85 const std::set
<GURL
>& removed_urls
) override
;
86 void BookmarkModelLoaded(bookmarks::BookmarkModel
* model
,
87 bool ids_reassigned
) override
;
89 // Helper for GetLoadExtraNodesCallback().
90 static bookmarks::BookmarkPermanentNodeList
LoadExtraNodes(
91 scoped_ptr
<bookmarks::BookmarkPermanentNode
> managed_node
,
92 scoped_ptr
<base::ListValue
> initial_managed_bookmarks
,
93 scoped_ptr
<bookmarks::BookmarkPermanentNode
> supervised_node
,
94 scoped_ptr
<base::ListValue
> initial_supervised_bookmarks
,
97 // Returns the management domain that configured the managed bookmarks,
98 // or an empty string.
99 std::string
GetManagedBookmarksDomain();
103 // HistoryService associated to the Profile. Due to circular dependency, this
104 // cannot be passed to the constructor, nor lazily fetched. Instead the value
105 // is initialized from HistoryServiceFactory.
106 history::HistoryService
* history_service_
;
108 scoped_ptr
<base::CallbackList
<void(const std::set
<GURL
>&)>::Subscription
>
109 favicon_changed_subscription_
;
111 // Pointer to the BookmarkModel. Will be non-NULL from the call to Init to
112 // the call to Shutdown. Must be valid for the whole interval.
113 bookmarks::BookmarkModel
* model_
;
115 // Managed bookmarks are defined by an enterprise policy.
116 scoped_ptr
<bookmarks::ManagedBookmarksTracker
> managed_bookmarks_tracker_
;
117 // The top-level managed bookmarks folder.
118 bookmarks::BookmarkPermanentNode
* managed_node_
;
120 // Supervised bookmarks are defined by the custodian of a supervised user.
121 scoped_ptr
<bookmarks::ManagedBookmarksTracker
> supervised_bookmarks_tracker_
;
122 // The top-level supervised bookmarks folder.
123 bookmarks::BookmarkPermanentNode
* supervised_node_
;
125 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient
);
128 #endif // CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_