| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ |
| 6 #define CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ | 6 #define CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_weak_ref.h" | 8 #include "base/android/jni_weak_ref.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 static void DisablePartnerBookmarksEditing(); | 46 static void DisablePartnerBookmarksEditing(); |
| 47 | 47 |
| 48 // Returns true if everything got loaded. | 48 // Returns true if everything got loaded. |
| 49 bool IsLoaded() const; | 49 bool IsLoaded() const; |
| 50 | 50 |
| 51 // Returns true if there are partner bookmarks. | 51 // Returns true if there are partner bookmarks. |
| 52 bool HasPartnerBookmarks() const; | 52 bool HasPartnerBookmarks() const; |
| 53 | 53 |
| 54 // Returns true if a given bookmark is reachable (i.e. neither the bookmark, | 54 // Returns true if a given bookmark is reachable (i.e. neither the bookmark, |
| 55 // nor any of its parents were "removed"). | 55 // nor any of its parents were "removed"). |
| 56 bool IsReachable(const BookmarkNode* node) const; | 56 bool IsReachable(const bookmarks::BookmarkNode* node) const; |
| 57 | 57 |
| 58 // Returns true if a given node is editable and if editing is allowed. | 58 // Returns true if a given node is editable and if editing is allowed. |
| 59 bool IsEditable(const BookmarkNode* node) const; | 59 bool IsEditable(const bookmarks::BookmarkNode* node) const; |
| 60 | 60 |
| 61 // Removes a given bookmark. | 61 // Removes a given bookmark. |
| 62 // Makes the |node| (and, consequently, all its children) unreachable. | 62 // Makes the |node| (and, consequently, all its children) unreachable. |
| 63 void RemoveBookmark(const BookmarkNode* node); | 63 void RemoveBookmark(const bookmarks::BookmarkNode* node); |
| 64 | 64 |
| 65 // Renames a given bookmark. | 65 // Renames a given bookmark. |
| 66 void RenameBookmark(const BookmarkNode* node, const base::string16& title); | 66 void RenameBookmark(const bookmarks::BookmarkNode* node, |
| 67 const base::string16& title); |
| 67 | 68 |
| 68 // For Loaded/Changed/ShimBeingDeleted notifications | 69 // For Loaded/Changed/ShimBeingDeleted notifications |
| 69 class Observer { | 70 class Observer { |
| 70 public: | 71 public: |
| 71 // Called when the set of bookmarks, or their values/visibility changes | 72 // Called when the set of bookmarks, or their values/visibility changes |
| 72 virtual void PartnerShimChanged(PartnerBookmarksShim*) {} | 73 virtual void PartnerShimChanged(PartnerBookmarksShim*) {} |
| 73 // Called when everything is loaded | 74 // Called when everything is loaded |
| 74 virtual void PartnerShimLoaded(PartnerBookmarksShim*) {} | 75 virtual void PartnerShimLoaded(PartnerBookmarksShim*) {} |
| 75 // Called just before everything got destroyed | 76 // Called just before everything got destroyed |
| 76 virtual void ShimBeingDeleted(PartnerBookmarksShim*) {} | 77 virtual void ShimBeingDeleted(PartnerBookmarksShim*) {} |
| 77 protected: | 78 protected: |
| 78 virtual ~Observer() {} | 79 virtual ~Observer() {} |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 void AddObserver(Observer* observer); | 82 void AddObserver(Observer* observer); |
| 82 void RemoveObserver(Observer* observer); | 83 void RemoveObserver(Observer* observer); |
| 83 | 84 |
| 84 // PartnerBookmarksShim versions of BookmarkModel/BookmarkNode methods | 85 // PartnerBookmarksShim versions of BookmarkModel/BookmarkNode methods |
| 85 const BookmarkNode* GetNodeByID(int64 id) const; | 86 const bookmarks::BookmarkNode* GetNodeByID(int64 id) const; |
| 86 base::string16 GetTitle(const BookmarkNode* node) const; | 87 base::string16 GetTitle(const bookmarks::BookmarkNode* node) const; |
| 87 | 88 |
| 88 bool IsPartnerBookmark(const BookmarkNode* node) const; | 89 bool IsPartnerBookmark(const bookmarks::BookmarkNode* node) const; |
| 89 const BookmarkNode* GetPartnerBookmarksRoot() const; | 90 const bookmarks::BookmarkNode* GetPartnerBookmarksRoot() const; |
| 90 | 91 |
| 91 // Sets the root node of the partner bookmarks and notifies any observers that | 92 // Sets the root node of the partner bookmarks and notifies any observers that |
| 92 // the shim has now been loaded. Takes ownership of |root_node|. | 93 // the shim has now been loaded. Takes ownership of |root_node|. |
| 93 void SetPartnerBookmarksRoot(BookmarkNode* root_node); | 94 void SetPartnerBookmarksRoot(bookmarks::BookmarkNode* root_node); |
| 94 | 95 |
| 95 // Used as a "unique" identifier of the partner bookmark node for the purposes | 96 // Used as a "unique" identifier of the partner bookmark node for the purposes |
| 96 // of node deletion and title editing. Two bookmarks with the same URLs and | 97 // of node deletion and title editing. Two bookmarks with the same URLs and |
| 97 // titles are considered indistinguishable. | 98 // titles are considered indistinguishable. |
| 98 class NodeRenamingMapKey { | 99 class NodeRenamingMapKey { |
| 99 public: | 100 public: |
| 100 NodeRenamingMapKey(const GURL& url, const base::string16& provider_title); | 101 NodeRenamingMapKey(const GURL& url, const base::string16& provider_title); |
| 101 ~NodeRenamingMapKey(); | 102 ~NodeRenamingMapKey(); |
| 102 const GURL& url() const { return url_; } | 103 const GURL& url() const { return url_; } |
| 103 const base::string16& provider_title() const { return provider_title_; } | 104 const base::string16& provider_title() const { return provider_title_; } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 // For testing: clears partner bookmark model data. | 117 // For testing: clears partner bookmark model data. |
| 117 static void ClearPartnerModelForTesting(); | 118 static void ClearPartnerModelForTesting(); |
| 118 | 119 |
| 119 // For testing: re-enables partner bookmarks editing. | 120 // For testing: re-enables partner bookmarks editing. |
| 120 static void EnablePartnerBookmarksEditing(); | 121 static void EnablePartnerBookmarksEditing(); |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 explicit PartnerBookmarksShim(PrefService* prefs); | 124 explicit PartnerBookmarksShim(PrefService* prefs); |
| 124 ~PartnerBookmarksShim() override; | 125 ~PartnerBookmarksShim() override; |
| 125 | 126 |
| 126 const BookmarkNode* GetNodeByID(const BookmarkNode* parent, int64 id) const; | 127 const bookmarks::BookmarkNode* GetNodeByID( |
| 128 const bookmarks::BookmarkNode* parent, |
| 129 int64 id) const; |
| 127 void ReloadNodeMapping(); | 130 void ReloadNodeMapping(); |
| 128 void SaveNodeMapping(); | 131 void SaveNodeMapping(); |
| 129 | 132 |
| 130 scoped_ptr<BookmarkNode> partner_bookmarks_root_; | 133 scoped_ptr<bookmarks::BookmarkNode> partner_bookmarks_root_; |
| 131 PrefService* prefs_; | 134 PrefService* prefs_; |
| 132 NodeRenamingMap node_rename_remove_map_; | 135 NodeRenamingMap node_rename_remove_map_; |
| 133 | 136 |
| 134 // The observers. | 137 // The observers. |
| 135 ObserverList<Observer> observers_; | 138 ObserverList<Observer> observers_; |
| 136 | 139 |
| 137 DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim); | 140 DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim); |
| 138 }; | 141 }; |
| 139 | 142 |
| 140 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ | 143 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ |
| OLD | NEW |