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_helper.h" | 8 #include "base/android/jni_helper.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 18 matching lines...) Expand all Loading... |
29 // Note that node->GetTitle() returns an original (unmodified) title. | 29 // Note that node->GetTitle() returns an original (unmodified) title. |
30 class PartnerBookmarksShim : public base::SupportsUserData::Data { | 30 class PartnerBookmarksShim : public base::SupportsUserData::Data { |
31 public: | 31 public: |
32 // Returns an instance of the shim for a given |browser_context|. | 32 // Returns an instance of the shim for a given |browser_context|. |
33 static PartnerBookmarksShim* BuildForBrowserContext( | 33 static PartnerBookmarksShim* BuildForBrowserContext( |
34 content::BrowserContext* browser_context); | 34 content::BrowserContext* browser_context); |
35 | 35 |
36 // Registers preferences. | 36 // Registers preferences. |
37 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 37 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
38 | 38 |
| 39 // Disables the editing and stops any edits from being applied. |
| 40 // The user will start to see the original (unedited) partner bookmarks. |
| 41 // Edits are stored in the user profile, so once the editing is enabled |
| 42 // ("not disabled") the user would see the edited partner bookmarks. |
| 43 // This method should be called as early as possible: it does NOT send any |
| 44 // notifications to already existing shims. |
| 45 static void DisablePartnerBookmarksEditing(); |
| 46 |
39 // Returns true if everything got loaded. | 47 // Returns true if everything got loaded. |
40 bool IsLoaded() const; | 48 bool IsLoaded() const; |
41 | 49 |
42 // Returns true if there are partner bookmarks. | 50 // Returns true if there are partner bookmarks. |
43 bool HasPartnerBookmarks() const; | 51 bool HasPartnerBookmarks() const; |
44 | 52 |
45 // Returns true if a given bookmark is reachable (i.e. neither the bookmark, | 53 // Returns true if a given bookmark is reachable (i.e. neither the bookmark, |
46 // nor any of its parents were "removed"). | 54 // nor any of its parents were "removed"). |
47 bool IsReachable(const BookmarkNode* node) const; | 55 bool IsReachable(const BookmarkNode* node) const; |
48 | 56 |
| 57 // Returns true if a given node is editable and if editing is allowed. |
| 58 bool IsEditable(const BookmarkNode* node) const; |
| 59 |
49 // Removes a given bookmark. | 60 // Removes a given bookmark. |
50 // Makes the |node| (and, consequently, all its children) unreachable. | 61 // Makes the |node| (and, consequently, all its children) unreachable. |
51 void RemoveBookmark(const BookmarkNode* node); | 62 void RemoveBookmark(const BookmarkNode* node); |
52 | 63 |
53 // Renames a given bookmark. | 64 // Renames a given bookmark. |
54 void RenameBookmark(const BookmarkNode* node, const base::string16& title); | 65 void RenameBookmark(const BookmarkNode* node, const base::string16& title); |
55 | 66 |
56 // For Loaded/Changed/ShimBeingDeleted notifications | 67 // For Loaded/Changed/ShimBeingDeleted notifications |
57 class Observer { | 68 class Observer { |
58 public: | 69 public: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 }; | 108 }; |
98 typedef std::map<NodeRenamingMapKey, base::string16> NodeRenamingMap; | 109 typedef std::map<NodeRenamingMapKey, base::string16> NodeRenamingMap; |
99 | 110 |
100 // For testing: clears an instance of the shim in a given |browser_context|. | 111 // For testing: clears an instance of the shim in a given |browser_context|. |
101 static void ClearInBrowserContextForTesting( | 112 static void ClearInBrowserContextForTesting( |
102 content::BrowserContext* browser_context); | 113 content::BrowserContext* browser_context); |
103 | 114 |
104 // For testing: clears partner bookmark model data. | 115 // For testing: clears partner bookmark model data. |
105 static void ClearPartnerModelForTesting(); | 116 static void ClearPartnerModelForTesting(); |
106 | 117 |
| 118 // For testing: re-enables partner bookmarks editing. |
| 119 static void EnablePartnerBookmarksEditing(); |
| 120 |
107 private: | 121 private: |
108 explicit PartnerBookmarksShim(PrefService* prefs); | 122 explicit PartnerBookmarksShim(PrefService* prefs); |
109 virtual ~PartnerBookmarksShim(); | 123 virtual ~PartnerBookmarksShim(); |
110 | 124 |
111 const BookmarkNode* GetNodeByID(const BookmarkNode* parent, int64 id) const; | 125 const BookmarkNode* GetNodeByID(const BookmarkNode* parent, int64 id) const; |
112 void ReloadNodeMapping(); | 126 void ReloadNodeMapping(); |
113 void SaveNodeMapping(); | 127 void SaveNodeMapping(); |
114 | 128 |
115 scoped_ptr<BookmarkNode> partner_bookmarks_root_; | 129 scoped_ptr<BookmarkNode> partner_bookmarks_root_; |
116 PrefService* prefs_; | 130 PrefService* prefs_; |
117 NodeRenamingMap node_rename_remove_map_; | 131 NodeRenamingMap node_rename_remove_map_; |
118 | 132 |
119 // The observers. | 133 // The observers. |
120 ObserverList<Observer> observers_; | 134 ObserverList<Observer> observers_; |
121 | 135 |
122 DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim); | 136 DISALLOW_COPY_AND_ASSIGN(PartnerBookmarksShim); |
123 }; | 137 }; |
124 | 138 |
125 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ | 139 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_PARTNER_BOOKMARKS_SHIM_H_ |
OLD | NEW |