| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ |
| 6 #define CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ | 6 #define CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/deferred_sequenced_task_runner.h" | 10 #include "base/deferred_sequenced_task_runner.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 13 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
| 14 #include "components/bookmarks/browser/bookmark_client.h" | 14 #include "components/bookmarks/browser/bookmark_client.h" |
| 15 #include "components/keyed_service/core/keyed_service.h" | |
| 16 #include "components/policy/core/browser/managed_bookmarks_tracker.h" | 15 #include "components/policy/core/browser/managed_bookmarks_tracker.h" |
| 17 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 19 | 18 |
| 20 class BookmarkModel; | 19 class BookmarkModel; |
| 21 class Profile; | 20 class Profile; |
| 22 | 21 |
| 23 class ChromeBookmarkClient : public BookmarkClient, | 22 class ChromeBookmarkClient : public BookmarkClient, |
| 24 public content::NotificationObserver, | 23 public content::NotificationObserver, |
| 25 public KeyedService, | |
| 26 public BaseBookmarkModelObserver { | 24 public BaseBookmarkModelObserver { |
| 27 public: | 25 public: |
| 28 // |index_urls| says whether URLs should be stored in the BookmarkIndex | 26 explicit ChromeBookmarkClient(Profile* profile); |
| 29 // in addition to bookmark titles. | |
| 30 ChromeBookmarkClient(Profile* profile, bool index_urls); | |
| 31 virtual ~ChromeBookmarkClient(); | 27 virtual ~ChromeBookmarkClient(); |
| 32 | 28 |
| 33 // Returns the BookmarkModel that corresponds to this ChromeBookmarkClient. | 29 void Init(BookmarkModel* model); |
| 34 BookmarkModel* model() { return model_.get(); } | 30 |
| 31 // KeyedService: |
| 32 virtual void Shutdown() OVERRIDE; |
| 35 | 33 |
| 36 // Returns the managed_node. | 34 // Returns the managed_node. |
| 37 const BookmarkNode* managed_node() { return managed_node_; } | 35 const BookmarkNode* managed_node() { return managed_node_; } |
| 38 | 36 |
| 39 // Returns true if the given node belongs to the managed bookmarks tree. | 37 // Returns true if the given node belongs to the managed bookmarks tree. |
| 40 bool IsDescendantOfManagedNode(const BookmarkNode* node); | 38 bool IsDescendantOfManagedNode(const BookmarkNode* node); |
| 41 | 39 |
| 42 // Returns true if there is at least one managed node in the |list|. | 40 // Returns true if there is at least one managed node in the |list|. |
| 43 bool HasDescendantsOfManagedNode( | 41 bool HasDescendantsOfManagedNode( |
| 44 const std::vector<const BookmarkNode*>& list); | 42 const std::vector<const BookmarkNode*>& list); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 62 virtual bool CanSetPermanentNodeTitle( | 60 virtual bool CanSetPermanentNodeTitle( |
| 63 const BookmarkNode* permanent_node) OVERRIDE; | 61 const BookmarkNode* permanent_node) OVERRIDE; |
| 64 virtual bool CanSyncNode(const BookmarkNode* node) OVERRIDE; | 62 virtual bool CanSyncNode(const BookmarkNode* node) OVERRIDE; |
| 65 virtual bool CanBeEditedByUser(const BookmarkNode* node) OVERRIDE; | 63 virtual bool CanBeEditedByUser(const BookmarkNode* node) OVERRIDE; |
| 66 | 64 |
| 67 // content::NotificationObserver: | 65 // content::NotificationObserver: |
| 68 virtual void Observe(int type, | 66 virtual void Observe(int type, |
| 69 const content::NotificationSource& source, | 67 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) OVERRIDE; | 68 const content::NotificationDetails& details) OVERRIDE; |
| 71 | 69 |
| 72 // KeyedService: | |
| 73 virtual void Shutdown() OVERRIDE; | |
| 74 | |
| 75 private: | 70 private: |
| 76 // BaseBookmarkModelObserver: | 71 // BaseBookmarkModelObserver: |
| 77 virtual void BookmarkModelChanged() OVERRIDE; | 72 virtual void BookmarkModelChanged() OVERRIDE; |
| 78 virtual void BookmarkNodeRemoved(BookmarkModel* model, | 73 virtual void BookmarkNodeRemoved(BookmarkModel* model, |
| 79 const BookmarkNode* parent, | 74 const BookmarkNode* parent, |
| 80 int old_index, | 75 int old_index, |
| 81 const BookmarkNode* node, | 76 const BookmarkNode* node, |
| 82 const std::set<GURL>& removed_urls) OVERRIDE; | 77 const std::set<GURL>& removed_urls) OVERRIDE; |
| 83 virtual void BookmarkAllUserNodesRemoved( | 78 virtual void BookmarkAllUserNodesRemoved( |
| 84 BookmarkModel* model, | 79 BookmarkModel* model, |
| 85 const std::set<GURL>& removed_urls) OVERRIDE; | 80 const std::set<GURL>& removed_urls) OVERRIDE; |
| 86 virtual void BookmarkModelLoaded(BookmarkModel* model, | 81 virtual void BookmarkModelLoaded(BookmarkModel* model, |
| 87 bool ids_reassigned) OVERRIDE; | 82 bool ids_reassigned) OVERRIDE; |
| 88 | 83 |
| 89 // Helper for GetLoadExtraNodesCallback(). | 84 // Helper for GetLoadExtraNodesCallback(). |
| 90 static bookmarks::BookmarkPermanentNodeList LoadExtraNodes( | 85 static bookmarks::BookmarkPermanentNodeList LoadExtraNodes( |
| 91 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, | 86 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, |
| 92 BookmarkPermanentNode* managed_node, | 87 BookmarkPermanentNode* managed_node, |
| 93 scoped_ptr<base::ListValue> initial_managed_bookmarks, | 88 scoped_ptr<base::ListValue> initial_managed_bookmarks, |
| 94 int64* next_node_id); | 89 int64* next_node_id); |
| 95 | 90 |
| 96 // Returns the management domain that configured the managed bookmarks, | 91 // Returns the management domain that configured the managed bookmarks, |
| 97 // or an empty string. | 92 // or an empty string. |
| 98 std::string GetManagedBookmarksDomain(); | 93 std::string GetManagedBookmarksDomain(); |
| 99 | 94 |
| 100 Profile* profile_; | 95 Profile* profile_; |
| 101 | 96 |
| 102 content::NotificationRegistrar registrar_; | 97 content::NotificationRegistrar registrar_; |
| 103 | 98 |
| 104 scoped_ptr<BookmarkModel> model_; | 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_; |
| 105 | 102 |
| 106 policy::ManagedBookmarksTracker managed_bookmarks_tracker_; | 103 scoped_ptr<policy::ManagedBookmarksTracker> managed_bookmarks_tracker_; |
| 107 BookmarkPermanentNode* managed_node_; | 104 BookmarkPermanentNode* managed_node_; |
| 108 | 105 |
| 109 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient); | 106 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClient); |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 #endif // CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ | 109 #endif // CHROME_BROWSER_BOOKMARKS_CHROME_BOOKMARK_CLIENT_H_ |
| OLD | NEW |