Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / android / bookmarks / bookmarks_bridge.h
blob5816c0f260cce17d9d2935ddae3cca781352cfd1
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 "chrome/browser/bookmarks/chrome_bookmark_client.h"
16 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
17 #include "components/bookmarks/common/android/bookmark_id.h"
19 namespace bookmarks {
20 class ScopedGroupBookmarkActions;
23 class Profile;
25 // The delegate to fetch bookmarks information for the Android native
26 // bookmark page. This fetches the bookmarks, title, urls, folder
27 // hierarchy.
28 class BookmarksBridge : public bookmarks::BaseBookmarkModelObserver,
29 public PartnerBookmarksShim::Observer {
30 public:
31 BookmarksBridge(JNIEnv* env, jobject obj, jobject j_profile);
32 void Destroy(JNIEnv*, jobject);
34 static bool RegisterBookmarksBridge(JNIEnv* env);
36 bool IsDoingExtensiveChanges(JNIEnv* env, jobject obj);
38 void LoadEmptyPartnerBookmarkShimForTesting(JNIEnv* env, jobject obj);
40 base::android::ScopedJavaLocalRef<jobject> GetBookmarkByID(
41 JNIEnv* env,
42 jobject obj,
43 jlong id,
44 jint type);
46 void GetPermanentNodeIDs(JNIEnv* env,
47 jobject obj,
48 jobject j_result_obj);
50 void GetTopLevelFolderParentIDs(JNIEnv* env,
51 jobject obj,
52 jobject j_result_obj);
54 void GetTopLevelFolderIDs(JNIEnv* env,
55 jobject obj,
56 jboolean get_special,
57 jboolean get_normal,
58 jobject j_result_obj);
60 void GetAllFoldersWithDepths(JNIEnv* env,
61 jobject obj,
62 jobject j_folders_obj,
63 jobject j_depths_obj);
65 base::android::ScopedJavaLocalRef<jobject> GetRootFolderId(JNIEnv* env,
66 jobject obj);
68 base::android::ScopedJavaLocalRef<jobject> GetMobileFolderId(JNIEnv* env,
69 jobject obj);
71 base::android::ScopedJavaLocalRef<jobject> GetOtherFolderId(JNIEnv* env,
72 jobject obj);
74 base::android::ScopedJavaLocalRef<jobject> GetDesktopFolderId(JNIEnv* env,
75 jobject obj);
77 void GetChildIDs(JNIEnv* env,
78 jobject obj,
79 jlong id,
80 jint type,
81 jboolean get_folders,
82 jboolean get_bookmarks,
83 jobject j_result_obj);
85 base::android::ScopedJavaLocalRef<jobject> GetChildAt(JNIEnv* env,
86 jobject obj,
87 jlong id,
88 jint type,
89 jint index);
91 void GetAllBookmarkIDsOrderedByCreationDate(JNIEnv* env,
92 jobject obj,
93 jobject j_result_obj);
95 void SetBookmarkTitle(JNIEnv* env,
96 jobject obj,
97 jlong id,
98 jint type,
99 jstring title);
101 void SetBookmarkUrl(JNIEnv* env,
102 jobject obj,
103 jlong id,
104 jint type,
105 jstring url);
107 bool DoesBookmarkExist(JNIEnv* env, jobject obj, jlong id, jint type);
109 void GetBookmarksForFolder(JNIEnv* env,
110 jobject obj,
111 jobject j_folder_id_obj,
112 jobject j_callback_obj,
113 jobject j_result_obj);
115 void GetCurrentFolderHierarchy(JNIEnv* env,
116 jobject obj,
117 jobject j_folder_id_obj,
118 jobject j_callback_obj,
119 jobject j_result_obj);
121 void SearchBookmarks(JNIEnv* env,
122 jobject obj,
123 jobject j_list,
124 jstring j_query,
125 jint max_results);
127 base::android::ScopedJavaLocalRef<jobject> AddFolder(JNIEnv* env,
128 jobject obj,
129 jobject j_parent_id_obj,
130 jint index,
131 jstring j_title);
133 void DeleteBookmark(JNIEnv* env, jobject obj, jobject j_bookmark_id_obj);
135 void MoveBookmark(JNIEnv* env,
136 jobject obj,
137 jobject j_bookmark_id_obj,
138 jobject j_parent_id_obj,
139 jint index);
141 base::android::ScopedJavaLocalRef<jobject> AddBookmark(
142 JNIEnv* env,
143 jobject obj,
144 jobject j_parent_id_obj,
145 jint index,
146 jstring j_title,
147 jstring j_url);
149 void Undo(JNIEnv* env, jobject obj);
151 void StartGroupingUndos(JNIEnv* env, jobject obj);
153 void EndGroupingUndos(JNIEnv* env, jobject obj);
155 base::string16 GetTitle(const bookmarks::BookmarkNode* node) const;
157 private:
158 ~BookmarksBridge() override;
160 base::android::ScopedJavaLocalRef<jobject> CreateJavaBookmark(
161 const bookmarks::BookmarkNode* node);
162 void ExtractBookmarkNodeInformation(const bookmarks::BookmarkNode* node,
163 jobject j_result_obj);
164 const bookmarks::BookmarkNode* GetNodeByID(long node_id, int type);
165 const bookmarks::BookmarkNode* GetFolderWithFallback(long folder_id,
166 int type);
167 // Returns whether |node| can be modified by the user.
168 bool IsEditable(const bookmarks::BookmarkNode* node) const;
169 // Returns whether |node| is a managed bookmark.
170 bool IsManaged(const bookmarks::BookmarkNode* node) const;
171 const bookmarks::BookmarkNode* GetParentNode(
172 const bookmarks::BookmarkNode* node);
173 int GetBookmarkType(const bookmarks::BookmarkNode* node);
174 bool IsReachable(const bookmarks::BookmarkNode* node) const;
175 bool IsLoaded() const;
176 bool IsFolderAvailable(const bookmarks::BookmarkNode* folder) const;
177 void NotifyIfDoneLoading();
179 // Override bookmarks::BaseBookmarkModelObserver.
180 // Called when there are changes to the bookmark model that don't trigger
181 // any of the other callback methods. For example, this is called when
182 // partner bookmarks change.
183 void BookmarkModelChanged() override;
184 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
185 bool ids_reassigned) override;
186 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
187 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
188 const bookmarks::BookmarkNode* old_parent,
189 int old_index,
190 const bookmarks::BookmarkNode* new_parent,
191 int new_index) override;
192 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
193 const bookmarks::BookmarkNode* parent,
194 int index) override;
195 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
196 const bookmarks::BookmarkNode* parent,
197 int old_index,
198 const bookmarks::BookmarkNode* node,
199 const std::set<GURL>& removed_urls) override;
200 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
201 const std::set<GURL>& removed_urls) override;
202 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
203 const bookmarks::BookmarkNode* node) override;
204 void BookmarkNodeChildrenReordered(
205 bookmarks::BookmarkModel* model,
206 const bookmarks::BookmarkNode* node) override;
207 void ExtensiveBookmarkChangesBeginning(
208 bookmarks::BookmarkModel* model) override;
209 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override;
211 // Override PartnerBookmarksShim::Observer
212 void PartnerShimChanged(PartnerBookmarksShim* shim) override;
213 void PartnerShimLoaded(PartnerBookmarksShim* shim) override;
214 void ShimBeingDeleted(PartnerBookmarksShim* shim) override;
216 Profile* profile_;
217 JavaObjectWeakGlobalRef weak_java_ref_;
218 bookmarks::BookmarkModel* bookmark_model_; // weak
219 ChromeBookmarkClient* client_; // weak
220 scoped_ptr<bookmarks::ScopedGroupBookmarkActions> grouped_bookmark_actions_;
222 // Information about the Partner bookmarks (must check for IsLoaded()).
223 // This is owned by profile.
224 PartnerBookmarksShim* partner_bookmarks_shim_;
226 DISALLOW_COPY_AND_ASSIGN(BookmarksBridge);
229 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_BOOKMARKS_BRIDGE_H_