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
;
30 // This class implements the native methods of ChromeBrowserProvider.java
31 class ChromeBrowserProvider
: public bookmarks::BaseBookmarkModelObserver
,
32 public history::HistoryServiceObserver
{
34 ChromeBrowserProvider(JNIEnv
* env
, jobject obj
);
35 void Destroy(JNIEnv
*, jobject
);
38 static bool RegisterChromeBrowserProvider(JNIEnv
* env
);
40 // Adds either a new bookmark or bookmark folder based on |is_folder|. The
41 // bookmark is added to the beginning of the specified parent and if the
42 // parent ID is not valid (i.e. < 0) then it will be added to the bookmark
44 jlong
AddBookmark(JNIEnv
* env
, jobject
,
50 // Removes a bookmark (or folder) with the specified ID.
51 jint
RemoveBookmark(JNIEnv
*, jobject
, jlong id
);
53 // Updates a bookmark (or folder) with the the new title and new URL.
54 // The |url| field will be ignored if the bookmark node is a folder.
55 // If a valid |parent_id| (>= 0) different from the currently specified
56 // parent is given, the node will be moved to that folder as the first
58 jint
UpdateBookmark(JNIEnv
* env
,
65 // The below are methods to support Android public API.
66 // Bookmark and history APIs. -----------------------------------------------
67 jlong
AddBookmarkFromAPI(JNIEnv
* env
,
78 base::android::ScopedJavaLocalRef
<jobject
> QueryBookmarkFromAPI(
81 jobjectArray projection
,
83 jobjectArray selection_args
,
86 jint
UpdateBookmarkFromAPI(JNIEnv
* env
,
97 jobjectArray selection_args
);
99 jint
RemoveBookmarkFromAPI(JNIEnv
* env
,
102 jobjectArray selection_args
);
104 jint
RemoveHistoryFromAPI(JNIEnv
* env
,
107 jobjectArray selection_args
);
109 jlong
AddSearchTermFromAPI(JNIEnv
* env
,
114 base::android::ScopedJavaLocalRef
<jobject
> QuerySearchTermFromAPI(
117 jobjectArray projection
,
119 jobjectArray selection_args
,
122 jint
RemoveSearchTermFromAPI(JNIEnv
* env
,
125 jobjectArray selection_args
);
127 jint
UpdateSearchTermFromAPI(JNIEnv
* env
,
132 jobjectArray selection_args
);
134 // Custom provider API methods. ---------------------------------------------
135 jlong
CreateBookmarksFolderOnce(JNIEnv
* env
,
140 void RemoveAllUserBookmarks(JNIEnv
* env
, jobject obj
);
142 base::android::ScopedJavaLocalRef
<jobject
> GetEditableBookmarkFolders(
146 base::android::ScopedJavaLocalRef
<jobject
> GetBookmarkNode(
151 jboolean get_children
);
153 base::android::ScopedJavaLocalRef
<jobject
> GetMobileBookmarksFolder(
157 jboolean
IsBookmarkInMobileBookmarksBranch(JNIEnv
* env
,
161 jboolean
BookmarkNodeExists(JNIEnv
* env
,
165 base::android::ScopedJavaLocalRef
<jbyteArray
> GetFaviconOrTouchIcon(
170 base::android::ScopedJavaLocalRef
<jbyteArray
> GetThumbnail(JNIEnv
* env
,
175 ~ChromeBrowserProvider() override
;
177 // Override bookmarks::BaseBookmarkModelObserver.
178 void BookmarkModelChanged() override
;
179 void ExtensiveBookmarkChangesBeginning(
180 bookmarks::BookmarkModel
* model
) override
;
181 void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel
* model
) override
;
183 // Deals with updates to the history service.
184 void OnHistoryChanged();
186 // Override history::HistoryServiceObserver.
187 void OnURLVisited(HistoryService
* history_service
,
188 ui::PageTransition transition
,
189 const history::URLRow
& row
,
190 const history::RedirectList
& redirects
,
191 base::Time visit_time
) override
;
192 void OnURLsDeleted(HistoryService
* history_service
,
195 const history::URLRows
& deleted_rows
,
196 const std::set
<GURL
>& favicon_urls
) override
;
197 void OnKeywordSearchTermUpdated(HistoryService
* history_service
,
198 const history::URLRow
& row
,
199 history::KeywordID keyword_id
,
200 const base::string16
& term
) override
;
201 void OnKeywordSearchTermDeleted(HistoryService
* history_service
,
202 history::URLID url_id
) override
;
204 JavaObjectWeakGlobalRef weak_java_provider_
;
206 // Profile must outlive this object.
208 // BookmarkModel, HistoryService and history::TopSites lifetime is bound to
209 // the lifetime of Profile, they are safe to use as long as the Profile is
212 bookmarks::BookmarkModel
* bookmark_model_
;
213 scoped_refptr
<history::TopSites
> top_sites_
;
214 FaviconService
* favicon_service_
;
216 scoped_ptr
<AndroidHistoryProviderService
> service_
;
218 base::CancelableTaskTracker cancelable_task_tracker_
;
220 ScopedObserver
<HistoryService
, HistoryServiceObserver
>
221 history_service_observer_
;
223 bool handling_extensive_changes_
;
225 DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProvider
);
228 #endif // CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_