1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_
#define CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/memory/scoped_ptr.h"
#include "base/scoped_observer.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/history/core/android/android_history_types.h"
#include "components/history/core/browser/history_service_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class AndroidHistoryProviderService;
class FaviconService;
class Profile;
namespace history {
class TopSites;
}
namespace sql {
class Statement;
}
// This class implements the native methods of ChromeBrowserProvider.java
class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver,
public content::NotificationObserver,
public history::HistoryServiceObserver {
public:
ChromeBrowserProvider(JNIEnv* env, jobject obj);
void Destroy(JNIEnv*, jobject);
// JNI registration.
static bool RegisterChromeBrowserProvider(JNIEnv* env);
// Adds either a new bookmark or bookmark folder based on |is_folder|. The
// bookmark is added to the beginning of the specified parent and if the
// parent ID is not valid (i.e. < 0) then it will be added to the bookmark
// bar.
jlong AddBookmark(JNIEnv* env, jobject,
jstring jurl,
jstring jtitle,
jboolean is_folder,
jlong parent_id);
// Removes a bookmark (or folder) with the specified ID.
jint RemoveBookmark(JNIEnv*, jobject, jlong id);
// Updates a bookmark (or folder) with the the new title and new URL.
// The |url| field will be ignored if the bookmark node is a folder.
// If a valid |parent_id| (>= 0) different from the currently specified
// parent is given, the node will be moved to that folder as the first
// child.
jint UpdateBookmark(JNIEnv* env,
jobject,
jlong id,
jstring url,
jstring title,
jlong parent_id);
// The below are methods to support Android public API.
// Bookmark and history APIs. -----------------------------------------------
jlong AddBookmarkFromAPI(JNIEnv* env,
jobject obj,
jstring url,
jobject created,
jobject isBookmark,
jobject date,
jbyteArray favicon,
jstring title,
jobject visits,
jlong parent_id);
base::android::ScopedJavaLocalRef<jobject> QueryBookmarkFromAPI(
JNIEnv* env,
jobject obj,
jobjectArray projection,
jstring selections,
jobjectArray selection_args,
jstring sort_order);
jint UpdateBookmarkFromAPI(JNIEnv* env,
jobject obj,
jstring url,
jobject created,
jobject isBookmark,
jobject date,
jbyteArray favicon,
jstring title,
jobject visits,
jlong parent_id,
jstring selections,
jobjectArray selection_args);
jint RemoveBookmarkFromAPI(JNIEnv* env,
jobject obj,
jstring selections,
jobjectArray selection_args);
jint RemoveHistoryFromAPI(JNIEnv* env,
jobject obj,
jstring selections,
jobjectArray selection_args);
jlong AddSearchTermFromAPI(JNIEnv* env,
jobject obj,
jstring search_term,
jobject date);
base::android::ScopedJavaLocalRef<jobject> QuerySearchTermFromAPI(
JNIEnv* env,
jobject obj,
jobjectArray projection,
jstring selections,
jobjectArray selection_args,
jstring sort_order);
jint RemoveSearchTermFromAPI(JNIEnv* env,
jobject obj,
jstring selections,
jobjectArray selection_args);
jint UpdateSearchTermFromAPI(JNIEnv* env,
jobject obj,
jstring search_term,
jobject date,
jstring selections,
jobjectArray selection_args);
// Custom provider API methods. ---------------------------------------------
jlong CreateBookmarksFolderOnce(JNIEnv* env,
jobject obj,
jstring title,
jlong parent_id);
void RemoveAllUserBookmarks(JNIEnv* env, jobject obj);
base::android::ScopedJavaLocalRef<jobject> GetEditableBookmarkFolders(
JNIEnv* env,
jobject obj);
base::android::ScopedJavaLocalRef<jobject> GetBookmarkNode(
JNIEnv* env,
jobject obj,
jlong id,
jboolean get_parent,
jboolean get_children);
base::android::ScopedJavaLocalRef<jobject> GetMobileBookmarksFolder(
JNIEnv* env,
jobject obj);
jboolean IsBookmarkInMobileBookmarksBranch(JNIEnv* env,
jobject obj,
jlong id);
jboolean BookmarkNodeExists(JNIEnv* env,
jobject obj,
jlong id);
base::android::ScopedJavaLocalRef<jbyteArray> GetFaviconOrTouchIcon(
JNIEnv* env,
jobject obj,
jstring url);
base::android::ScopedJavaLocalRef<jbyteArray> GetThumbnail(JNIEnv* env,
jobject obj,
jstring url);
private:
virtual ~ChromeBrowserProvider();
// Override bookmarks::BaseBookmarkModelObserver.
virtual void BookmarkModelChanged() override;
virtual void ExtensiveBookmarkChangesBeginning(BookmarkModel* model) override;
virtual void ExtensiveBookmarkChangesEnded(BookmarkModel* model) override;
// Deals with updates to the history service.
void OnHistoryChanged();
// Override history::HistoryServiceObserver.
virtual void OnURLVisited(HistoryService* history_service,
ui::PageTransition transition,
const history::URLRow& row,
const history::RedirectList& redirects,
base::Time visit_time) override;
// Override content::NotificationObserver.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
JavaObjectWeakGlobalRef weak_java_provider_;
// Profile must outlive this object.
//
// BookmarkModel, HistoryService and history::TopSites lifetime is bound to
// the lifetime of Profile, they are safe to use as long as the Profile is
// alive.
Profile* profile_;
BookmarkModel* bookmark_model_;
history::TopSites* top_sites_;
FaviconService* favicon_service_;
scoped_ptr<AndroidHistoryProviderService> service_;
base::CancelableTaskTracker cancelable_task_tracker_;
// Used to register/unregister notification observer.
content::NotificationRegistrar notification_registrar_;
ScopedObserver<HistoryService, HistoryServiceObserver>
history_service_observer_;
bool handling_extensive_changes_;
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProvider);
};
#endif // CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_
|