1 // Copyright (c) 2012 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_PROVIDER_CHROME_BROWSER_PROVIDER_H_
6 #define CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_
8 #include "base/android/jni_weak_ref.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/scoped_observer.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
15 #include "components/history/core/browser/android/android_history_types.h"
16 #include "components/history/core/browser/history_service_observer.h"
18 class AndroidHistoryProviderService
;
33 // This class implements the native methods of ChromeBrowserProvider.java
34 class ChromeBrowserProvider
: public bookmarks::BaseBookmarkModelObserver
,
35 public history::HistoryServiceObserver
{
37 ChromeBrowserProvider(JNIEnv
* env
, jobject obj
);
38 void Destroy(JNIEnv
*, jobject
);
41 static bool RegisterChromeBrowserProvider(JNIEnv
* env
);
43 // Adds either a new bookmark or bookmark folder based on |is_folder|. The
44 // bookmark is added to the beginning of the specified parent and if the
45 // parent ID is not valid (i.e. < 0) then it will be added to the bookmark
47 jlong
AddBookmark(JNIEnv
* env
, jobject
,
53 // Removes a bookmark (or folder) with the specified ID.
54 jint
RemoveBookmark(JNIEnv
*, jobject
, jlong id
);
56 // Updates a bookmark (or folder) with the the new title and new URL.
57 // The |url| field will be ignored if the bookmark node is a folder.
58 // If a valid |parent_id| (>= 0) different from the currently specified
59 // parent is given, the node will be moved to that folder as the first
61 jint
UpdateBookmark(JNIEnv
* env
,
68 // The below are methods to support Android public API.
69 // Bookmark and history APIs. -----------------------------------------------
70 jlong
AddBookmarkFromAPI(JNIEnv
* env
,
81 base::android::ScopedJavaLocalRef
<jobject
> QueryBookmarkFromAPI(
84 jobjectArray projection
,
86 jobjectArray selection_args
,
89 jint
UpdateBookmarkFromAPI(JNIEnv
* env
,
100 jobjectArray selection_args
);
102 jint
RemoveBookmarkFromAPI(JNIEnv
* env
,
105 jobjectArray selection_args
);
107 jint
RemoveHistoryFromAPI(JNIEnv
* env
,
110 jobjectArray selection_args
);
112 jlong
AddSearchTermFromAPI(JNIEnv
* env
,
117 base::android::ScopedJavaLocalRef
<jobject
> QuerySearchTermFromAPI(
120 jobjectArray projection
,
122 jobjectArray selection_args
,
125 jint
RemoveSearchTermFromAPI(JNIEnv
* env
,
128 jobjectArray selection_args
);
130 jint
UpdateSearchTermFromAPI(JNIEnv
* env
,
135 jobjectArray selection_args
);
137 // Custom provider API methods. ---------------------------------------------
138 jlong
CreateBookmarksFolderOnce(JNIEnv
* env
,
143 void RemoveAllUserBookmarks(JNIEnv
* env
, jobject obj
);
145 base::android::ScopedJavaLocalRef
<jobject
> GetEditableBookmarkFolders(
149 base::android::ScopedJavaLocalRef
<jobject
> GetBookmarkNode(
154 jboolean get_children
);
156 base::android::ScopedJavaLocalRef
<jobject
> GetMobileBookmarksFolder(
160 jboolean
IsBookmarkInMobileBookmarksBranch(JNIEnv
* env
,
164 jboolean
BookmarkNodeExists(JNIEnv
* env
,
168 base::android::ScopedJavaLocalRef
<jbyteArray
> GetFaviconOrTouchIcon(
173 base::android::ScopedJavaLocalRef
<jbyteArray
> GetThumbnail(JNIEnv
* env
,
178 ~ChromeBrowserProvider() override
;
180 // Override bookmarks::BaseBookmarkModelObserver.
181 void BookmarkModelChanged() override
;
182 void ExtensiveBookmarkChangesBeginning(
183 bookmarks::BookmarkModel
* model
) override
;
184 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel
* model
) override
;
186 // Deals with updates to the history service.
187 void OnHistoryChanged();
189 // Override history::HistoryServiceObserver.
190 void OnURLVisited(history::HistoryService
* history_service
,
191 ui::PageTransition transition
,
192 const history::URLRow
& row
,
193 const history::RedirectList
& redirects
,
194 base::Time visit_time
) override
;
195 void OnURLsDeleted(history::HistoryService
* history_service
,
198 const history::URLRows
& deleted_rows
,
199 const std::set
<GURL
>& favicon_urls
) override
;
200 void OnKeywordSearchTermUpdated(history::HistoryService
* history_service
,
201 const history::URLRow
& row
,
202 history::KeywordID keyword_id
,
203 const base::string16
& term
) override
;
204 void OnKeywordSearchTermDeleted(history::HistoryService
* history_service
,
205 history::URLID url_id
) override
;
207 JavaObjectWeakGlobalRef weak_java_provider_
;
209 // Profile must outlive this object.
211 // BookmarkModel, HistoryService and history::TopSites lifetime is bound to
212 // the lifetime of Profile, they are safe to use as long as the Profile is
215 bookmarks::BookmarkModel
* bookmark_model_
;
216 scoped_refptr
<history::TopSites
> top_sites_
;
217 favicon::FaviconService
* favicon_service_
;
219 scoped_ptr
<AndroidHistoryProviderService
> service_
;
221 base::CancelableTaskTracker cancelable_task_tracker_
;
223 ScopedObserver
<history::HistoryService
, history::HistoryServiceObserver
>
224 history_service_observer_
;
226 bool handling_extensive_changes_
;
228 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProvider
);
231 #endif // CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_