Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / bookmarks / bookmarks_bridge.h
blob0d208372b11a24d8871e96ecb46c501ec444610e
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_ANDROID_BOOKMARKS_BOOKMARKS_BRIDGE_H_
6 #define CHROME_BROWSER_ANDROID_BOOKMARKS_BOOKMARKS_BRIDGE_H_
8 #include <jni.h>
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_weak_ref.h"
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "chrome/browser/android/bookmarks/partner_bookmarks_shim.h"
15 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
16 #include "components/bookmarks/common/android/bookmark_id.h"
18 namespace bookmarks {
19 class BookmarkModel;
20 class ManagedBookmarkService;
21 class ScopedGroupBookmarkActions;
24 class Profile;
26 // The delegate to fetch bookmarks information for the Android native
27 // bookmark page. This fetches the bookmarks, title, urls, folder
28 // hierarchy.
29 class BookmarksBridge : public bookmarks::BaseBookmarkModelObserver,
30 public PartnerBookmarksShim::Observer {
31 public:
32 BookmarksBridge(JNIEnv* env, jobject obj, jobject j_profile);
33 void Destroy(JNIEnv*, jobject);
35 static bool RegisterBookmarksBridge(JNIEnv* env);
37 bool IsDoingExtensiveChanges(JNIEnv* env, jobject obj);
39 jboolean IsEditBookmarksEnabled(JNIEnv* env, jobject obj);
41 void LoadEmptyPartnerBookmarkShimForTesting(JNIEnv* env, jobject obj);
43 base::android::ScopedJavaLocalRef<jobject> GetBookmarkByID(
44 JNIEnv* env,
45 jobject obj,
46 jlong id,
47 jint type);
49 void GetPermanentNodeIDs(JNIEnv* env,
50 jobject obj,
51 jobject j_result_obj);
53 void GetTopLevelFolderParentIDs(JNIEnv* env,
54 jobject obj,
55 jobject j_result_obj);
57 void GetTopLevelFolderIDs(JNIEnv* env,
58 jobject obj,
59 jboolean get_special,
60 jboolean get_normal,
61 jobject j_result_obj);
63 void GetAllFoldersWithDepths(JNIEnv* env,
64 jobject obj,
65 jobject j_folders_obj,
66 jobject j_depths_obj);
68 base::android::ScopedJavaLocalRef<jobject> GetRootFolderId(JNIEnv* env,
69 jobject obj);
71 base::android::ScopedJavaLocalRef<jobject> GetMobileFolderId(JNIEnv* env,
72 jobject obj);
74 base::android::ScopedJavaLocalRef<jobject> GetOtherFolderId(JNIEnv* env,
75 jobject obj);
77 base::android::ScopedJavaLocalRef<jobject> GetDesktopFolderId(JNIEnv* env,
78 jobject obj);
80 void GetChildIDs(JNIEnv* env,
81 jobject obj,
82 jlong id,
83 jint type,
84 jboolean get_folders,
85 jboolean get_bookmarks,
86 jobject j_result_obj);
88 base::android::ScopedJavaLocalRef<jobject> GetChildAt(JNIEnv* env,
89 jobject obj,
90 jlong id,
91 jint type,
92 jint index);
94 void GetAllBookmarkIDsOrderedByCreationDate(JNIEnv* env,
95 jobject obj,
96 jobject j_result_obj);
98 void SetBookmarkTitle(JNIEnv* env,
99 jobject obj,
100 jlong id,
101 jint type,
102 jstring title);
104 void SetBookmarkUrl(JNIEnv* env,
105 jobject obj,
106 jlong id,
107 jint type,
108 jstring url);
110 bool DoesBookmarkExist(JNIEnv* env, jobject obj, jlong id, jint type);
112 void GetBookmarksForFolder(JNIEnv* env,
113 jobject obj,
114 jobject j_folder_id_obj,
115 jobject j_callback_obj,
116 jobject j_result_obj);
118 jboolean IsFolderVisible(JNIEnv* env, jobject obj, jlong id, jint type);
120 void GetCurrentFolderHierarchy(JNIEnv* env,
121 jobject obj,
122 jobject j_folder_id_obj,
123 jobject j_callback_obj,
124 jobject j_result_obj);
125 void SearchBookmarks(JNIEnv* env,
126 jobject obj,
127 jobject j_list,
128 jstring j_query,
129 jint max_results);
131 base::android::ScopedJavaLocalRef<jobject> AddFolder(JNIEnv* env,
132 jobject obj,
133 jobject j_parent_id_obj,
134 jint index,
135 jstring j_title);
137 void DeleteBookmark(JNIEnv* env, jobject obj, jobject j_bookmark_id_obj);
139 void MoveBookmark(JNIEnv* env,
140 jobject obj,
141 jobject j_bookmark_id_obj,
142 jobject j_parent_id_obj,
143 jint index);
145 base::android::ScopedJavaLocalRef<jobject> AddBookmark(
146 JNIEnv* env,
147 jobject obj,
148 jobject j_parent_id_obj,
149 jint index,
150 jstring j_title,
151 jstring j_url);
153 void Undo(JNIEnv* env, jobject obj);
155 void StartGroupingUndos(JNIEnv* env, jobject obj);
157 void EndGroupingUndos(JNIEnv* env, jobject obj);
159 base::string16 GetTitle(const bookmarks::BookmarkNode* node) const;
161 private:
162 ~BookmarksBridge() override;
164 base::android::ScopedJavaLocalRef<jobject> CreateJavaBookmark(
165 const bookmarks::BookmarkNode* node);
166 void ExtractBookmarkNodeInformation(const bookmarks::BookmarkNode* node,
167 jobject j_result_obj);
168 const bookmarks::BookmarkNode* GetNodeByID(long node_id, int type);
169 const bookmarks::BookmarkNode* GetFolderWithFallback(long folder_id,
170 int type);
171 bool IsEditBookmarksEnabled() const;
172 // Returns whether |node| can be modified by the user.
173 bool IsEditable(const bookmarks::BookmarkNode* node) const;
174 // Returns whether |node| is a managed bookmark.
175 bool IsManaged(const bookmarks::BookmarkNode* node) const;
176 const bookmarks::BookmarkNode* GetParentNode(
177 const bookmarks::BookmarkNode* node);
178 int GetBookmarkType(const bookmarks::BookmarkNode* node);
179 bool IsReachable(const bookmarks::BookmarkNode* node) const;
180 bool IsLoaded() const;
181 bool IsFolderAvailable(const bookmarks::BookmarkNode* folder) const;
182 void NotifyIfDoneLoading();
184 // Override bookmarks::BaseBookmarkModelObserver.
185 // Called when there are changes to the bookmark model that don't trigger
186 // any of the other callback methods. For example, this is called when
187 // partner bookmarks change.
188 void BookmarkModelChanged() override;
189 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
190 bool ids_reassigned) override;
191 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
192 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
193 const bookmarks::BookmarkNode* old_parent,
194 int old_index,
195 const bookmarks::BookmarkNode* new_parent,
196 int new_index) override;
197 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
198 const bookmarks::BookmarkNode* parent,
199 int index) override;
200 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
201 const bookmarks::BookmarkNode* parent,
202 int old_index,
203 const bookmarks::BookmarkNode* node,
204 const std::set<GURL>& removed_urls) override;
205 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
206 const std::set<GURL>& removed_urls) override;
207 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
208 const bookmarks::BookmarkNode* node) override;
209 void BookmarkNodeChildrenReordered(
210 bookmarks::BookmarkModel* model,
211 const bookmarks::BookmarkNode* node) override;
212 void ExtensiveBookmarkChangesBeginning(
213 bookmarks::BookmarkModel* model) override;
214 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override;
216 // Override PartnerBookmarksShim::Observer
217 void PartnerShimChanged(PartnerBookmarksShim* shim) override;
218 void PartnerShimLoaded(PartnerBookmarksShim* shim) override;
219 void ShimBeingDeleted(PartnerBookmarksShim* shim) override;
221 Profile* profile_;
222 JavaObjectWeakGlobalRef weak_java_ref_;
223 bookmarks::BookmarkModel* bookmark_model_; // weak
224 bookmarks::ManagedBookmarkService* managed_bookmark_service_; // weak
225 scoped_ptr<bookmarks::ScopedGroupBookmarkActions> grouped_bookmark_actions_;
227 // Information about the Partner bookmarks (must check for IsLoaded()).
228 // This is owned by profile.
229 PartnerBookmarksShim* partner_bookmarks_shim_;
231 DISALLOW_COPY_AND_ASSIGN(BookmarksBridge);
234 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_BOOKMARKS_BRIDGE_H_