Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / bookmarks / managed / managed_bookmark_service.h
blob8841c0deeef52e973fcb4734c77e9591c95e2717
1 // Copyright 2015 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 COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARK_SERVICE_H_
6 #define COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARK_SERVICE_H_
8 #include <string>
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
14 #include "components/bookmarks/browser/bookmark_node.h"
15 #include "components/bookmarks/browser/bookmark_storage.h"
16 #include "components/keyed_service/core/keyed_service.h"
18 class PrefService;
20 namespace bookmarks {
22 class BookmarkModel;
23 class ManagedBookmarksTracker;
25 // ManagedBookmarkService manages the bookmark folder controlled by enterprise
26 // policy or custodian of supervised users.
27 class ManagedBookmarkService : public KeyedService,
28 public BaseBookmarkModelObserver {
29 public:
30 typedef base::Callback<std::string()> GetManagementDomainCallback;
32 ManagedBookmarkService(PrefService* prefs,
33 const GetManagementDomainCallback& callback);
34 ~ManagedBookmarkService() override;
36 // Called upon creation of the BookmarkModel.
37 void BookmarkModelCreated(BookmarkModel* bookmark_model);
39 // Returns a task that will be used to load any additional root nodes. This
40 // task will be invoked in the Profile's IO task runner.
41 LoadExtraCallback GetLoadExtraNodesCallback();
43 // Returns true if the |node| can have its title updated.
44 bool CanSetPermanentNodeTitle(const BookmarkNode* node);
46 // Returns true if |node| should sync.
47 bool CanSyncNode(const BookmarkNode* node);
49 // Returns true if |node| can be edited by the user.
50 // TODO(joaodasilva): the model should check this more aggressively, and
51 // should give the client a means to temporarily disable those checks.
52 // http://crbug.com/49598
53 bool CanBeEditedByUser(const BookmarkNode* node);
55 // Top-level managed bookmarks folder, defined by an enterprise policy; may be
56 // null.
57 const BookmarkNode* managed_node() { return managed_node_; }
59 // Top-level supervised bookmarks folder, defined by the custodian of a
60 // supervised user; may be null.
61 const BookmarkNode* supervised_node() { return supervised_node_; }
63 private:
64 // KeyedService implementation.
65 void Shutdown() override;
67 // BaseBookmarkModelObserver implementation.
68 void BookmarkModelChanged() override;
70 // BookmarkModelObserver implementation.
71 void BookmarkModelLoaded(bookmarks::BookmarkModel* bookmark_model,
72 bool ids_reassigned) override;
73 void BookmarkModelBeingDeleted(BookmarkModel* bookmark_model) override;
75 // Cleanup, called when service is shutdown or when BookmarkModel is being
76 // destroyed.
77 void Cleanup();
79 // Pointer to the PrefService. Must outlive ManagedBookmarkService.
80 PrefService* prefs_;
82 // Pointer to the BookmarkModel; may be null. Only valid between the calls to
83 // BookmarkModelCreated() and to BookmarkModelBeingDestroyed().
84 BookmarkModel* bookmark_model_;
86 // Managed bookmarks are defined by an enterprise policy. The lifetime of the
87 // BookmarkPermanentNode is controlled by BookmarkModel.
88 scoped_ptr<ManagedBookmarksTracker> managed_bookmarks_tracker_;
89 GetManagementDomainCallback managed_domain_callback_;
90 BookmarkPermanentNode* managed_node_;
92 // Supervised bookmarks are defined by the custodian of a supervised user. The
93 // lifetime of the BookmarkPermanentNode is controlled by BookmarkModel.
94 scoped_ptr<ManagedBookmarksTracker> supervised_bookmarks_tracker_;
95 BookmarkPermanentNode* supervised_node_;
97 DISALLOW_COPY_AND_ASSIGN(ManagedBookmarkService);
100 } // namespace bookmarks
102 #endif // COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARK_SERVICE_H_