Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / chrome / browser / android / provider / chrome_browser_provider.h
blob3fc4312bd2ac90a99c7541d14647b20728a06d9e
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 FaviconService;
20 class Profile;
22 namespace history {
23 class TopSites;
26 namespace sql {
27 class Statement;
30 // This class implements the native methods of ChromeBrowserProvider.java
31 class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
32 public history::HistoryServiceObserver {
33 public:
34 ChromeBrowserProvider(JNIEnv* env, jobject obj);
35 void Destroy(JNIEnv*, jobject);
37 // JNI registration.
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
43 // bar.
44 jlong AddBookmark(JNIEnv* env, jobject,
45 jstring jurl,
46 jstring jtitle,
47 jboolean is_folder,
48 jlong parent_id);
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
57 // child.
58 jint UpdateBookmark(JNIEnv* env,
59 jobject,
60 jlong id,
61 jstring url,
62 jstring title,
63 jlong parent_id);
65 // The below are methods to support Android public API.
66 // Bookmark and history APIs. -----------------------------------------------
67 jlong AddBookmarkFromAPI(JNIEnv* env,
68 jobject obj,
69 jstring url,
70 jobject created,
71 jobject isBookmark,
72 jobject date,
73 jbyteArray favicon,
74 jstring title,
75 jobject visits,
76 jlong parent_id);
78 base::android::ScopedJavaLocalRef<jobject> QueryBookmarkFromAPI(
79 JNIEnv* env,
80 jobject obj,
81 jobjectArray projection,
82 jstring selections,
83 jobjectArray selection_args,
84 jstring sort_order);
86 jint UpdateBookmarkFromAPI(JNIEnv* env,
87 jobject obj,
88 jstring url,
89 jobject created,
90 jobject isBookmark,
91 jobject date,
92 jbyteArray favicon,
93 jstring title,
94 jobject visits,
95 jlong parent_id,
96 jstring selections,
97 jobjectArray selection_args);
99 jint RemoveBookmarkFromAPI(JNIEnv* env,
100 jobject obj,
101 jstring selections,
102 jobjectArray selection_args);
104 jint RemoveHistoryFromAPI(JNIEnv* env,
105 jobject obj,
106 jstring selections,
107 jobjectArray selection_args);
109 jlong AddSearchTermFromAPI(JNIEnv* env,
110 jobject obj,
111 jstring search_term,
112 jobject date);
114 base::android::ScopedJavaLocalRef<jobject> QuerySearchTermFromAPI(
115 JNIEnv* env,
116 jobject obj,
117 jobjectArray projection,
118 jstring selections,
119 jobjectArray selection_args,
120 jstring sort_order);
122 jint RemoveSearchTermFromAPI(JNIEnv* env,
123 jobject obj,
124 jstring selections,
125 jobjectArray selection_args);
127 jint UpdateSearchTermFromAPI(JNIEnv* env,
128 jobject obj,
129 jstring search_term,
130 jobject date,
131 jstring selections,
132 jobjectArray selection_args);
134 // Custom provider API methods. ---------------------------------------------
135 jlong CreateBookmarksFolderOnce(JNIEnv* env,
136 jobject obj,
137 jstring title,
138 jlong parent_id);
140 void RemoveAllUserBookmarks(JNIEnv* env, jobject obj);
142 base::android::ScopedJavaLocalRef<jobject> GetEditableBookmarkFolders(
143 JNIEnv* env,
144 jobject obj);
146 base::android::ScopedJavaLocalRef<jobject> GetBookmarkNode(
147 JNIEnv* env,
148 jobject obj,
149 jlong id,
150 jboolean get_parent,
151 jboolean get_children);
153 base::android::ScopedJavaLocalRef<jobject> GetMobileBookmarksFolder(
154 JNIEnv* env,
155 jobject obj);
157 jboolean IsBookmarkInMobileBookmarksBranch(JNIEnv* env,
158 jobject obj,
159 jlong id);
161 jboolean BookmarkNodeExists(JNIEnv* env,
162 jobject obj,
163 jlong id);
165 base::android::ScopedJavaLocalRef<jbyteArray> GetFaviconOrTouchIcon(
166 JNIEnv* env,
167 jobject obj,
168 jstring url);
170 base::android::ScopedJavaLocalRef<jbyteArray> GetThumbnail(JNIEnv* env,
171 jobject obj,
172 jstring url);
174 private:
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,
193 bool all_history,
194 bool expired,
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
210 // alive.
211 Profile* profile_;
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_