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"
16 #include "components/policy/core/browser/managed_bookmarks_tracker.h"
20 class HistoryServiceFactory
;
27 class ChromeBookmarkClient
: public bookmarks::BookmarkClient
,
28 public bookmarks::BaseBookmarkModelObserver
{
30 explicit ChromeBookmarkClient(Profile
* profile
);
31 ~ChromeBookmarkClient() override
;
33 void Init(bookmarks::BookmarkModel
* model
);
36 void Shutdown() override
;
38 // The top-level managed bookmarks folder, defined by an enterprise policy.
39 const bookmarks::BookmarkNode
* managed_node() { return managed_node_
; }
40 // The top-level supervised bookmarks folder, defined by the custodian of a
42 const bookmarks::BookmarkNode
* supervised_node() { return supervised_node_
; }
44 // bookmarks::BookmarkClient:
45 bool PreferTouchIcon() override
;
46 base::CancelableTaskTracker::TaskId
GetFaviconImageForPageURL(
48 favicon_base::IconType type
,
49 const favicon_base::FaviconImageCallback
& callback
,
50 base::CancelableTaskTracker
* tracker
) override
;
51 bool SupportsTypedCountForNodes() override
;
52 void GetTypedCountForNodes(
54 NodeTypedCountPairs
* node_typed_count_pairs
) override
;
55 bool IsPermanentNodeVisible(
56 const bookmarks::BookmarkPermanentNode
* node
) override
;
57 void RecordAction(const base::UserMetricsAction
& action
) override
;
58 bookmarks::LoadExtraCallback
GetLoadExtraNodesCallback() override
;
59 bool CanSetPermanentNodeTitle(
60 const bookmarks::BookmarkNode
* permanent_node
) override
;
61 bool CanSyncNode(const bookmarks::BookmarkNode
* node
) override
;
62 bool CanBeEditedByUser(const bookmarks::BookmarkNode
* node
) override
;
65 friend class HistoryServiceFactory
;
66 void SetHistoryService(HistoryService
* history_service
);
68 // bookmarks::BaseBookmarkModelObserver:
69 void BookmarkModelChanged() override
;
70 void BookmarkNodeRemoved(bookmarks::BookmarkModel
* model
,
71 const bookmarks::BookmarkNode
* parent
,
73 const bookmarks::BookmarkNode
* node
,
74 const std::set
<GURL
>& removed_urls
) override
;
75 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel
* model
,
76 const std::set
<GURL
>& removed_urls
) override
;
77 void BookmarkModelLoaded(bookmarks::BookmarkModel
* model
,
78 bool ids_reassigned
) override
;
80 // Helper for GetLoadExtraNodesCallback().
81 static bookmarks::BookmarkPermanentNodeList
LoadExtraNodes(
82 scoped_ptr
<bookmarks::BookmarkPermanentNode
> managed_node
,
83 scoped_ptr
<base::ListValue
> initial_managed_bookmarks
,
84 scoped_ptr
<bookmarks::BookmarkPermanentNode
> supervised_node
,
85 scoped_ptr
<base::ListValue
> initial_supervised_bookmarks
,
88 // Returns the management domain that configured the managed bookmarks,
89 // or an empty string.
90 std::string
GetManagedBookmarksDomain();
94 // HistoryService associated to the Profile. Due to circular dependency, this
95 // cannot be passed to the constructor, nor lazily fetched. Instead the value
96 // is initialized from HistoryServiceFactory.
97 HistoryService
* history_service_
;
99 scoped_ptr
<base::CallbackList
<void(const std::set
<GURL
>&)>::Subscription
>
100 favicon_changed_subscription_
;
102 // Pointer to the BookmarkModel. Will be non-NULL from the call to Init to
103 // the call to Shutdown. Must be valid for the whole interval.
104 bookmarks::BookmarkModel
* model_
;
106 // Managed bookmarks are defined by an enterprise policy.
107 scoped_ptr
<policy::ManagedBookmarksTracker
> managed_bookmarks_tracker_
;
108 // The top-level managed bookmarks folder.
109 bookmarks::BookmarkPermanentNode
* managed_node_
;
111 // Supervised bookmarks are defined by the custodian of a supervised user.
112 scoped_ptr
<policy::ManagedBookmarksTracker
> supervised_bookmarks_tracker_
;
113 // The top-level supervised bookmarks folder.
114 bookmarks::BookmarkPermanentNode
* supervised_node_
;
116 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient
);
119 #endif // CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_