Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / android / provider / chrome_browser_provider.h
blob80da75ebea7e7dfb77868aa8343a77c964bfc6d3
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;
19 class Profile;
21 namespace favicon {
22 class FaviconService;
25 namespace history {
26 class TopSites;
29 namespace sql {
30 class Statement;
33 // This class implements the native methods of ChromeBrowserProvider.java
34 class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
35 public history::HistoryServiceObserver {
36 public:
37 ChromeBrowserProvider(JNIEnv* env, jobject obj);
38 void Destroy(JNIEnv*, jobject);
40 // JNI registration.
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
46 // bar.
47 jlong AddBookmark(JNIEnv* env, jobject,
48 jstring jurl,
49 jstring jtitle,
50 jboolean is_folder,
51 jlong parent_id);
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
60 // child.
61 jint UpdateBookmark(JNIEnv* env,
62 jobject,
63 jlong id,
64 jstring url,
65 jstring title,
66 jlong parent_id);
68 // The below are methods to support Android public API.
69 // Bookmark and history APIs. -----------------------------------------------
70 jlong AddBookmarkFromAPI(JNIEnv* env,
71 jobject obj,
72 jstring url,
73 jobject created,
74 jobject isBookmark,
75 jobject date,
76 jbyteArray favicon,
77 jstring title,
78 jobject visits,
79 jlong parent_id);
81 base::android::ScopedJavaLocalRef<jobject> QueryBookmarkFromAPI(
82 JNIEnv* env,
83 jobject obj,
84 jobjectArray projection,
85 jstring selections,
86 jobjectArray selection_args,
87 jstring sort_order);
89 jint UpdateBookmarkFromAPI(JNIEnv* env,
90 jobject obj,
91 jstring url,
92 jobject created,
93 jobject isBookmark,
94 jobject date,
95 jbyteArray favicon,
96 jstring title,
97 jobject visits,
98 jlong parent_id,
99 jstring selections,
100 jobjectArray selection_args);
102 jint RemoveBookmarkFromAPI(JNIEnv* env,
103 jobject obj,
104 jstring selections,
105 jobjectArray selection_args);
107 jint RemoveHistoryFromAPI(JNIEnv* env,
108 jobject obj,
109 jstring selections,
110 jobjectArray selection_args);
112 jlong AddSearchTermFromAPI(JNIEnv* env,
113 jobject obj,
114 jstring search_term,
115 jobject date);
117 base::android::ScopedJavaLocalRef<jobject> QuerySearchTermFromAPI(
118 JNIEnv* env,
119 jobject obj,
120 jobjectArray projection,
121 jstring selections,
122 jobjectArray selection_args,
123 jstring sort_order);
125 jint RemoveSearchTermFromAPI(JNIEnv* env,
126 jobject obj,
127 jstring selections,
128 jobjectArray selection_args);
130 jint UpdateSearchTermFromAPI(JNIEnv* env,
131 jobject obj,
132 jstring search_term,
133 jobject date,
134 jstring selections,
135 jobjectArray selection_args);
137 // Custom provider API methods. ---------------------------------------------
138 jlong CreateBookmarksFolderOnce(JNIEnv* env,
139 jobject obj,
140 jstring title,
141 jlong parent_id);
143 void RemoveAllUserBookmarks(JNIEnv* env, jobject obj);
145 base::android::ScopedJavaLocalRef<jobject> GetEditableBookmarkFolders(
146 JNIEnv* env,
147 jobject obj);
149 base::android::ScopedJavaLocalRef<jobject> GetBookmarkNode(
150 JNIEnv* env,
151 jobject obj,
152 jlong id,
153 jboolean get_parent,
154 jboolean get_children);
156 base::android::ScopedJavaLocalRef<jobject> GetMobileBookmarksFolder(
157 JNIEnv* env,
158 jobject obj);
160 jboolean IsBookmarkInMobileBookmarksBranch(JNIEnv* env,
161 jobject obj,
162 jlong id);
164 jboolean BookmarkNodeExists(JNIEnv* env,
165 jobject obj,
166 jlong id);
168 base::android::ScopedJavaLocalRef<jbyteArray> GetFaviconOrTouchIcon(
169 JNIEnv* env,
170 jobject obj,
171 jstring url);
173 base::android::ScopedJavaLocalRef<jbyteArray> GetThumbnail(JNIEnv* env,
174 jobject obj,
175 jstring url);
177 private:
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,
196 bool all_history,
197 bool expired,
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
213 // alive.
214 Profile* profile_;
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_