[Android] Make BookmarkModelObserver more convenient.
[chromium-blink-merge.git] / chrome / browser / android / bookmarks / bookmarks_bridge.h
blob84a3e9bf1e98e227cebe4ca34b5390fe66ac81f9
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 class Profile;
21 // The delegate to fetch bookmarks information for the Android native
22 // bookmark page. This fetches the bookmarks, title, urls, folder
23 // hierarchy.
24 class BookmarksBridge : public BaseBookmarkModelObserver,
25 public PartnerBookmarksShim::Observer {
26 public:
27 BookmarksBridge(JNIEnv* env, jobject obj, jobject j_profile);
28 void Destroy(JNIEnv*, jobject);
30 static bool RegisterBookmarksBridge(JNIEnv* env);
32 bool IsDoingExtensiveChanges(JNIEnv* env, jobject obj);
34 base::android::ScopedJavaLocalRef<jobject> GetBookmarkByID(
35 JNIEnv* env,
36 jobject obj,
37 jlong id,
38 jint type);
40 void GetPermanentNodeIDs(JNIEnv* env,
41 jobject obj,
42 jobject j_result_obj);
44 void GetTopLevelFolderParentIDs(JNIEnv* env,
45 jobject obj,
46 jobject j_result_obj);
48 void GetTopLevelFolderIDs(JNIEnv* env,
49 jobject obj,
50 jboolean get_special,
51 jboolean get_normal,
52 jobject j_result_obj);
54 void GetUncategorizedBookmarkIDs(JNIEnv* env,
55 jobject obj,
56 jobject j_result_obj);
57 void GetAllFoldersWithDepths(JNIEnv* env,
58 jobject obj,
59 jobject j_folders_obj,
60 jobject j_depths_obj);
62 base::android::ScopedJavaLocalRef<jobject> GetMobileFolderId(JNIEnv* env,
63 jobject obj);
65 void GetChildIDs(JNIEnv* env,
66 jobject obj,
67 jlong id,
68 jint type,
69 jboolean get_folders,
70 jboolean get_bookmarks,
71 jobject j_result_obj);
73 void GetAllBookmarkIDsOrderedByCreationDate(JNIEnv* env,
74 jobject obj,
75 jobject j_result_obj);
77 void SetBookmarkTitle(JNIEnv* env,
78 jobject obj,
79 jlong id,
80 jint type,
81 jstring title);
83 void SetBookmarkUrl(JNIEnv* env,
84 jobject obj,
85 jlong id,
86 jint type,
87 jstring url);
89 bool DoesBookmarkExist(JNIEnv* env, jobject obj, jlong id, jint type);
91 void GetBookmarksForFolder(JNIEnv* env,
92 jobject obj,
93 jobject j_folder_id_obj,
94 jobject j_callback_obj,
95 jobject j_result_obj);
97 void GetCurrentFolderHierarchy(JNIEnv* env,
98 jobject obj,
99 jobject j_folder_id_obj,
100 jobject j_callback_obj,
101 jobject j_result_obj);
103 void DeleteBookmark(JNIEnv* env,
104 jobject obj,
105 jobject j_bookmark_id_obj);
107 void MoveBookmark(JNIEnv* env,
108 jobject obj,
109 jobject j_bookmark_id_obj,
110 jobject j_parent_id_obj,
111 jint index);
113 private:
114 virtual ~BookmarksBridge();
116 base::android::ScopedJavaLocalRef<jobject> CreateJavaBookmark(
117 const BookmarkNode* node);
118 void ExtractBookmarkNodeInformation(
119 const BookmarkNode* node,
120 jobject j_result_obj);
121 const BookmarkNode* GetNodeByID(long node_id, int type);
122 const BookmarkNode* GetFolderWithFallback(long folder_id, int type);
123 // Returns whether |node| can be modified by the user.
124 bool IsEditable(const BookmarkNode* node) const;
125 // Returns whether |node| is a managed bookmark.
126 bool IsManaged(const BookmarkNode* node) const;
127 const BookmarkNode* GetParentNode(const BookmarkNode* node);
128 int GetBookmarkType(const BookmarkNode* node);
129 base::string16 GetTitle(const BookmarkNode* node) const;
130 bool IsReachable(const BookmarkNode* node) const;
131 bool IsLoaded() const;
132 bool IsFolderAvailable(const BookmarkNode* folder) const;
133 void NotifyIfDoneLoading();
135 // Override BaseBookmarkModelObserver.
136 // Called when there are changes to the bookmark model that don't trigger
137 // any of the other callback methods. For example, this is called when
138 // partner bookmarks change.
139 virtual void BookmarkModelChanged() OVERRIDE;
140 virtual void BookmarkModelLoaded(BookmarkModel* model,
141 bool ids_reassigned) OVERRIDE;
142 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
143 virtual void BookmarkNodeMoved(BookmarkModel* model,
144 const BookmarkNode* old_parent,
145 int old_index,
146 const BookmarkNode* new_parent,
147 int new_index) OVERRIDE;
148 virtual void BookmarkNodeAdded(BookmarkModel* model,
149 const BookmarkNode* parent,
150 int index) OVERRIDE;
151 virtual void BookmarkNodeRemoved(BookmarkModel* model,
152 const BookmarkNode* parent,
153 int old_index,
154 const BookmarkNode* node,
155 const std::set<GURL>& removed_urls) OVERRIDE;
156 virtual void BookmarkNodeChanged(BookmarkModel* model,
157 const BookmarkNode* node) OVERRIDE;
158 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
159 const BookmarkNode* node) OVERRIDE;
160 virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE;
161 virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) OVERRIDE;
163 // Override PartnerBookmarksShim::Observer
164 virtual void PartnerShimChanged(PartnerBookmarksShim* shim) OVERRIDE;
165 virtual void PartnerShimLoaded(PartnerBookmarksShim* shim) OVERRIDE;
166 virtual void ShimBeingDeleted(PartnerBookmarksShim* shim) OVERRIDE;
168 Profile* profile_;
169 JavaObjectWeakGlobalRef weak_java_ref_;
170 BookmarkModel* bookmark_model_; // weak
171 ChromeBookmarkClient* client_; // weak
173 // Information about the Partner bookmarks (must check for IsLoaded()).
174 // This is owned by profile.
175 PartnerBookmarksShim* partner_bookmarks_shim_;
177 DISALLOW_COPY_AND_ASSIGN(BookmarksBridge);
180 #endif // CHROME_BROWSER_ANDROID_BOOKMARKS_BOOKMARKS_BRIDGE_H_