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_
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"
21 // The delegate to fetch bookmarks information for the Android native
22 // bookmark page. This fetches the bookmarks, title, urls, folder
24 class BookmarksBridge
: public BaseBookmarkModelObserver
,
25 public PartnerBookmarksShim::Observer
{
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(
40 void GetPermanentNodeIDs(JNIEnv
* env
,
42 jobject j_result_obj
);
44 void GetTopLevelFolderParentIDs(JNIEnv
* env
,
46 jobject j_result_obj
);
48 void GetTopLevelFolderIDs(JNIEnv
* env
,
52 jobject j_result_obj
);
54 void GetUncategorizedBookmarkIDs(JNIEnv
* env
,
56 jobject j_result_obj
);
57 void GetAllFoldersWithDepths(JNIEnv
* env
,
59 jobject j_folders_obj
,
60 jobject j_depths_obj
);
62 base::android::ScopedJavaLocalRef
<jobject
> GetMobileFolderId(JNIEnv
* env
,
65 void GetChildIDs(JNIEnv
* env
,
70 jboolean get_bookmarks
,
71 jobject j_result_obj
);
73 void GetAllBookmarkIDsOrderedByCreationDate(JNIEnv
* env
,
75 jobject j_result_obj
);
77 void SetBookmarkTitle(JNIEnv
* env
,
83 void SetBookmarkUrl(JNIEnv
* env
,
89 bool DoesBookmarkExist(JNIEnv
* env
, jobject obj
, jlong id
, jint type
);
91 void GetBookmarksForFolder(JNIEnv
* env
,
93 jobject j_folder_id_obj
,
94 jobject j_callback_obj
,
95 jobject j_result_obj
);
97 void GetCurrentFolderHierarchy(JNIEnv
* env
,
99 jobject j_folder_id_obj
,
100 jobject j_callback_obj
,
101 jobject j_result_obj
);
103 void DeleteBookmark(JNIEnv
* env
,
105 jobject j_bookmark_id_obj
);
107 void MoveBookmark(JNIEnv
* env
,
109 jobject j_bookmark_id_obj
,
110 jobject j_parent_id_obj
,
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
,
146 const BookmarkNode
* new_parent
,
147 int new_index
) OVERRIDE
;
148 virtual void BookmarkNodeAdded(BookmarkModel
* model
,
149 const BookmarkNode
* parent
,
151 virtual void BookmarkNodeRemoved(BookmarkModel
* model
,
152 const BookmarkNode
* parent
,
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
;
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_