Commit d8178964 authored by danduong's avatar danduong Committed by Commit bot

Add BookmarkUndoService to Android build

Adding build support and JNI hooks for undoing
bookmark actions.

BUG=415411

Review URL: https://codereview.chromium.org/586913002

Cr-Commit-Position: refs/heads/master@{#296135}
parent 1511c019
......@@ -450,6 +450,29 @@ public class BookmarksBridge {
return nativeAddBookmark(mNativeBookmarksBridge, parent, index, title, url);
}
/**
* Undo the last undoable action on the top of the bookmark undo stack
*/
public void undo() {
nativeUndo(mNativeBookmarksBridge);
}
/**
* Start grouping actions for a single undo operation
* Note: This only works with BookmarkModel, not partner bookmarks.
*/
public void startGroupingUndos() {
nativeStartGroupingUndos(mNativeBookmarksBridge);
}
/**
* End grouping actions for a single undo operation
* Note: This only works with BookmarkModel, not partner bookmarks.
*/
public void endGroupingUndos() {
nativeEndGroupingUndos(mNativeBookmarksBridge);
}
/**
* A bridge function to BookmarkModelFactory::GetForProfile.
*/
......@@ -618,9 +641,13 @@ public class BookmarksBridge {
BookmarkId newParentId, int index);
private native BookmarkId nativeAddBookmark(long nativeBookmarksBridge, BookmarkId parent,
int index, String title, String url);
private native void nativeUndo(long nativeBookmarksBridge);
private native void nativeStartGroupingUndos(long nativeBookmarksBridge);
private native void nativeEndGroupingUndos(long nativeBookmarksBridge);
private static native long nativeGetNativeBookmarkModel(Profile profile);
private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profile profile);
private native void nativeLoadEmptyPartnerBookmarkShimForTesting(long nativeBookmarksBridge);
private native long nativeInit(Profile profile);
private native boolean nativeIsDoingExtensiveChanges(long nativeBookmarksBridge);
private native void nativeDestroy(long nativeBookmarksBridge);
......
......@@ -131,6 +131,9 @@ static_library("browser") {
"//sync",
]
sources += rebase_path(gypi_values.chrome_browser_undo_sources,
".", "//chrome")
if (!is_ios) {
sources += rebase_path(gypi_values.chrome_browser_non_ios_sources,
".", "//chrome")
......
......@@ -16,9 +16,13 @@
#include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/undo/bookmark_undo_service.h"
#include "chrome/browser/undo/bookmark_undo_service_factory.h"
#include "chrome/browser/undo/undo_manager.h"
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/browser/scoped_group_bookmark_actions.h"
#include "components/bookmarks/common/android/bookmark_type.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
......@@ -669,6 +673,30 @@ ScopedJavaLocalRef<jobject> BookmarksBridge::AddBookmark(
return new_java_obj;
}
void BookmarksBridge::Undo(JNIEnv* env, jobject obj) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(IsLoaded());
BookmarkUndoService* undo_service =
BookmarkUndoServiceFactory::GetForProfile(profile_);
UndoManager* undo_manager = undo_service->undo_manager();
undo_manager->Undo();
}
void BookmarksBridge::StartGroupingUndos(JNIEnv* env, jobject obj) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(IsLoaded());
DCHECK(!grouped_bookmark_actions_.get()); // shouldn't have started already
grouped_bookmark_actions_.reset(
new bookmarks::ScopedGroupBookmarkActions(bookmark_model_));
}
void BookmarksBridge::EndGroupingUndos(JNIEnv* env, jobject obj) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(IsLoaded());
DCHECK(grouped_bookmark_actions_.get()); // should only call after start
grouped_bookmark_actions_.reset();
}
ScopedJavaLocalRef<jobject> BookmarksBridge::CreateJavaBookmark(
const BookmarkNode* node) {
JNIEnv* env = AttachCurrentThread();
......
......@@ -16,6 +16,10 @@
#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/bookmarks/common/android/bookmark_id.h"
namespace bookmarks {
class ScopedGroupBookmarkActions;
}
class Profile;
// The delegate to fetch bookmarks information for the Android native
......@@ -130,6 +134,12 @@ class BookmarksBridge : public BaseBookmarkModelObserver,
jstring j_title,
jstring j_url);
void Undo(JNIEnv* env, jobject obj);
void StartGroupingUndos(JNIEnv* env, jobject obj);
void EndGroupingUndos(JNIEnv* env, jobject obj);
private:
virtual ~BookmarksBridge();
......@@ -189,6 +199,7 @@ class BookmarksBridge : public BaseBookmarkModelObserver,
JavaObjectWeakGlobalRef weak_java_ref_;
BookmarkModel* bookmark_model_; // weak
ChromeBookmarkClient* client_; // weak
scoped_ptr<bookmarks::ScopedGroupBookmarkActions> grouped_bookmark_actions_;
// Information about the Partner bookmarks (must check for IsLoaded()).
// This is owned by profile.
......
......@@ -67,9 +67,8 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
->GetBookmarkTaskRunner(),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI));
#if !defined(OS_ANDROID)
bool register_bookmark_undo_service_as_observer = true;
#if !defined(OS_IOS)
#if !defined(OS_IOS) && !defined(OS_ANDROID)
register_bookmark_undo_service_as_observer =
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBookmarkUndo);
......@@ -78,7 +77,6 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
bookmark_model->AddObserver(
BookmarkUndoServiceFactory::GetForProfile(profile));
}
#endif // !defined(OS_ANDROID)
return bookmark_model;
}
......
......@@ -163,9 +163,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
BackgroundContentsServiceFactory::GetInstance();
#endif
BookmarkModelFactory::GetInstance();
#if !defined(OS_ANDROID)
BookmarkUndoServiceFactory::GetInstance();
#endif
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
CaptivePortalServiceFactory::GetInstance();
#endif
......
......@@ -530,9 +530,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel(
model->RemoveObserver(this);
// Changes made to the bookmark model due to sync should not be undoable.
#if !defined(OS_ANDROID)
ScopedSuspendBookmarkUndo suspend_undo(profile_);
#endif
// Notify UI intensive observers of BookmarkModel that we are about to make
// potentially significant changes to it, so the updates may be batched. For
......
......@@ -402,9 +402,8 @@ syncer::SyncError BookmarkModelAssociator::AssociateModels(
syncer::SyncMergeResult* syncer_merge_result) {
// Since any changes to the bookmark model made here are not user initiated,
// these change should not be undoable and so suspend the undo tracking.
#if !defined(OS_ANDROID)
ScopedSuspendBookmarkUndo suspend_undo(profile_);
#endif
syncer::SyncError error = CheckModelSyncState(local_merge_result,
syncer_merge_result);
if (error.IsSet())
......
......@@ -2162,14 +2162,6 @@
'browser/sync/sync_ui_util.h',
'browser/tab_contents/background_contents.cc',
'browser/tab_contents/background_contents.h',
'browser/undo/bookmark_undo_service.cc',
'browser/undo/bookmark_undo_service_factory.cc',
'browser/undo/bookmark_undo_service_factory.h',
'browser/undo/bookmark_undo_service.h',
'browser/undo/bookmark_undo_utils.cc',
'browser/undo/bookmark_undo_utils.h',
'browser/undo/undo_manager.cc',
'browser/undo/undo_manager.h',
],
# Cross-platform Aura files.
'chrome_browser_aura_sources': [
......@@ -2320,6 +2312,16 @@
'browser/supervised_user/supervised_user_url_filter.h',
'browser/supervised_user/supervised_users.h',
],
'chrome_browser_undo_sources': [
'browser/undo/bookmark_undo_service.cc',
'browser/undo/bookmark_undo_service_factory.cc',
'browser/undo/bookmark_undo_service_factory.h',
'browser/undo/bookmark_undo_service.h',
'browser/undo/bookmark_undo_utils.cc',
'browser/undo/bookmark_undo_utils.h',
'browser/undo/undo_manager.cc',
'browser/undo/undo_manager.h',
],
'chrome_browser_webrtc_sources': [
# TODO(brettw) should webrtc_log_list.cc go here?
'browser/media/webrtc_log_uploader.cc',
......@@ -2876,6 +2878,10 @@
'../sql/sql.gyp:sql',
'../sync/sync.gyp:sync',
],
# sources applied to all configurations
'sources': [
'<@(chrome_browser_undo_sources)',
],
'conditions': [
['OS != "ios"', {
'dependencies': [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment