// 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/macros.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/browser/android/android_history_types.h" #include "components/history/core/browser/history_service_observer.h" class AndroidHistoryProviderService; class Profile; namespace favicon { class FaviconService; } namespace history { class TopSites; } namespace sql { class Statement; } // This class implements the native methods of ChromeBrowserProvider.java class ChromeBrowserProvider : public bookmarks::BaseBookmarkModelObserver, public history::HistoryServiceObserver { public: ChromeBrowserProvider(JNIEnv* env, jobject obj); void Destroy(JNIEnv*, const base::android::JavaParamRef&); // 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, const base::android::JavaParamRef&, const base::android::JavaParamRef& jurl, const base::android::JavaParamRef& jtitle, jboolean is_folder, jlong parent_id); // Removes a bookmark (or folder) with the specified ID. jint RemoveBookmark(JNIEnv*, const base::android::JavaParamRef&, 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, const base::android::JavaParamRef&, jlong id, const base::android::JavaParamRef& url, const base::android::JavaParamRef& title, jlong parent_id); // The below are methods to support Android public API. // Bookmark and history APIs. ----------------------------------------------- jlong AddBookmarkFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& url, const base::android::JavaParamRef& created, const base::android::JavaParamRef& isBookmark, const base::android::JavaParamRef& date, const base::android::JavaParamRef& favicon, const base::android::JavaParamRef& title, const base::android::JavaParamRef& visits, jlong parent_id); base::android::ScopedJavaLocalRef QueryBookmarkFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& projection, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args, const base::android::JavaParamRef& sort_order); jint UpdateBookmarkFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& url, const base::android::JavaParamRef& created, const base::android::JavaParamRef& isBookmark, const base::android::JavaParamRef& date, const base::android::JavaParamRef& favicon, const base::android::JavaParamRef& title, const base::android::JavaParamRef& visits, jlong parent_id, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args); jint RemoveBookmarkFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args); jint RemoveHistoryFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args); jlong AddSearchTermFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& search_term, const base::android::JavaParamRef& date); base::android::ScopedJavaLocalRef QuerySearchTermFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& projection, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args, const base::android::JavaParamRef& sort_order); jint RemoveSearchTermFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args); jint UpdateSearchTermFromAPI( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& search_term, const base::android::JavaParamRef& date, const base::android::JavaParamRef& selections, const base::android::JavaParamRef& selection_args); // Custom provider API methods. --------------------------------------------- jlong CreateBookmarksFolderOnce( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& title, jlong parent_id); void RemoveAllUserBookmarks(JNIEnv* env, const base::android::JavaParamRef& obj); base::android::ScopedJavaLocalRef GetEditableBookmarkFolders( JNIEnv* env, const base::android::JavaParamRef& obj); base::android::ScopedJavaLocalRef GetBookmarkNode( JNIEnv* env, const base::android::JavaParamRef& obj, jlong id, jboolean get_parent, jboolean get_children); base::android::ScopedJavaLocalRef GetMobileBookmarksFolder( JNIEnv* env, const base::android::JavaParamRef& obj); jboolean IsBookmarkInMobileBookmarksBranch( JNIEnv* env, const base::android::JavaParamRef& obj, jlong id); jboolean BookmarkNodeExists(JNIEnv* env, const base::android::JavaParamRef& obj, jlong id); base::android::ScopedJavaLocalRef GetFaviconOrTouchIcon( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& url); base::android::ScopedJavaLocalRef GetThumbnail( JNIEnv* env, const base::android::JavaParamRef& obj, const base::android::JavaParamRef& url); private: ~ChromeBrowserProvider() override; // Override bookmarks::BaseBookmarkModelObserver. void BookmarkModelChanged() override; void ExtensiveBookmarkChangesBeginning( bookmarks::BookmarkModel* model) override; void ExtensiveBookmarkChangesEnded(bookmarks::BookmarkModel* model) override; // Deals with updates to the history service. void OnHistoryChanged(); // Override history::HistoryServiceObserver. void OnURLVisited(history::HistoryService* history_service, ui::PageTransition transition, const history::URLRow& row, const history::RedirectList& redirects, base::Time visit_time) override; void OnURLsDeleted(history::HistoryService* history_service, bool all_history, bool expired, const history::URLRows& deleted_rows, const std::set& favicon_urls) override; void OnKeywordSearchTermUpdated(history::HistoryService* history_service, const history::URLRow& row, history::KeywordID keyword_id, const base::string16& term) override; void OnKeywordSearchTermDeleted(history::HistoryService* history_service, history::URLID url_id) 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_; bookmarks::BookmarkModel* bookmark_model_; scoped_refptr top_sites_; favicon::FaviconService* favicon_service_; scoped_ptr service_; base::CancelableTaskTracker cancelable_task_tracker_; ScopedObserver history_service_observer_; bool handling_extensive_changes_; DISALLOW_COPY_AND_ASSIGN(ChromeBrowserProvider); }; #endif // CHROME_BROWSER_ANDROID_PROVIDER_CHROME_BROWSER_PROVIDER_H_