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 { ...@@ -450,6 +450,29 @@ public class BookmarksBridge {
return nativeAddBookmark(mNativeBookmarksBridge, parent, index, title, url); 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. * A bridge function to BookmarkModelFactory::GetForProfile.
*/ */
...@@ -618,9 +641,13 @@ public class BookmarksBridge { ...@@ -618,9 +641,13 @@ public class BookmarksBridge {
BookmarkId newParentId, int index); BookmarkId newParentId, int index);
private native BookmarkId nativeAddBookmark(long nativeBookmarksBridge, BookmarkId parent, private native BookmarkId nativeAddBookmark(long nativeBookmarksBridge, BookmarkId parent,
int index, String title, String url); 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 long nativeGetNativeBookmarkModel(Profile profile);
private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profile profile); private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profile profile);
private native void nativeLoadEmptyPartnerBookmarkShimForTesting(long nativeBookmarksBridge); private native void nativeLoadEmptyPartnerBookmarkShimForTesting(long nativeBookmarksBridge);
private native long nativeInit(Profile profile); private native long nativeInit(Profile profile);
private native boolean nativeIsDoingExtensiveChanges(long nativeBookmarksBridge); private native boolean nativeIsDoingExtensiveChanges(long nativeBookmarksBridge);
private native void nativeDestroy(long nativeBookmarksBridge); private native void nativeDestroy(long nativeBookmarksBridge);
......
...@@ -131,6 +131,9 @@ static_library("browser") { ...@@ -131,6 +131,9 @@ static_library("browser") {
"//sync", "//sync",
] ]
sources += rebase_path(gypi_values.chrome_browser_undo_sources,
".", "//chrome")
if (!is_ios) { if (!is_ios) {
sources += rebase_path(gypi_values.chrome_browser_non_ios_sources, sources += rebase_path(gypi_values.chrome_browser_non_ios_sources,
".", "//chrome") ".", "//chrome")
......
...@@ -16,9 +16,13 @@ ...@@ -16,9 +16,13 @@
#include "chrome/browser/profiles/profile_android.h" #include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.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 "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.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/bookmarks/common/android/bookmark_type.h"
#include "components/signin/core/browser/signin_manager.h" #include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -669,6 +673,30 @@ ScopedJavaLocalRef<jobject> BookmarksBridge::AddBookmark( ...@@ -669,6 +673,30 @@ ScopedJavaLocalRef<jobject> BookmarksBridge::AddBookmark(
return new_java_obj; 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( ScopedJavaLocalRef<jobject> BookmarksBridge::CreateJavaBookmark(
const BookmarkNode* node) { const BookmarkNode* node) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "components/bookmarks/browser/base_bookmark_model_observer.h" #include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/bookmarks/common/android/bookmark_id.h" #include "components/bookmarks/common/android/bookmark_id.h"
namespace bookmarks {
class ScopedGroupBookmarkActions;
}
class Profile; class Profile;
// The delegate to fetch bookmarks information for the Android native // The delegate to fetch bookmarks information for the Android native
...@@ -130,6 +134,12 @@ class BookmarksBridge : public BaseBookmarkModelObserver, ...@@ -130,6 +134,12 @@ class BookmarksBridge : public BaseBookmarkModelObserver,
jstring j_title, jstring j_title,
jstring j_url); jstring j_url);
void Undo(JNIEnv* env, jobject obj);
void StartGroupingUndos(JNIEnv* env, jobject obj);
void EndGroupingUndos(JNIEnv* env, jobject obj);
private: private:
virtual ~BookmarksBridge(); virtual ~BookmarksBridge();
...@@ -189,6 +199,7 @@ class BookmarksBridge : public BaseBookmarkModelObserver, ...@@ -189,6 +199,7 @@ class BookmarksBridge : public BaseBookmarkModelObserver,
JavaObjectWeakGlobalRef weak_java_ref_; JavaObjectWeakGlobalRef weak_java_ref_;
BookmarkModel* bookmark_model_; // weak BookmarkModel* bookmark_model_; // weak
ChromeBookmarkClient* client_; // weak ChromeBookmarkClient* client_; // weak
scoped_ptr<bookmarks::ScopedGroupBookmarkActions> grouped_bookmark_actions_;
// Information about the Partner bookmarks (must check for IsLoaded()). // Information about the Partner bookmarks (must check for IsLoaded()).
// This is owned by profile. // This is owned by profile.
......
...@@ -67,9 +67,8 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( ...@@ -67,9 +67,8 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
->GetBookmarkTaskRunner(), ->GetBookmarkTaskRunner(),
content::BrowserThread::GetMessageLoopProxyForThread( content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::UI)); content::BrowserThread::UI));
#if !defined(OS_ANDROID)
bool register_bookmark_undo_service_as_observer = true; 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 = register_bookmark_undo_service_as_observer =
CommandLine::ForCurrentProcess()->HasSwitch( CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBookmarkUndo); switches::kEnableBookmarkUndo);
...@@ -78,7 +77,6 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( ...@@ -78,7 +77,6 @@ KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
bookmark_model->AddObserver( bookmark_model->AddObserver(
BookmarkUndoServiceFactory::GetForProfile(profile)); BookmarkUndoServiceFactory::GetForProfile(profile));
} }
#endif // !defined(OS_ANDROID)
return bookmark_model; return bookmark_model;
} }
......
...@@ -163,9 +163,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -163,9 +163,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
BackgroundContentsServiceFactory::GetInstance(); BackgroundContentsServiceFactory::GetInstance();
#endif #endif
BookmarkModelFactory::GetInstance(); BookmarkModelFactory::GetInstance();
#if !defined(OS_ANDROID)
BookmarkUndoServiceFactory::GetInstance(); BookmarkUndoServiceFactory::GetInstance();
#endif
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
CaptivePortalServiceFactory::GetInstance(); CaptivePortalServiceFactory::GetInstance();
#endif #endif
......
...@@ -530,9 +530,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel( ...@@ -530,9 +530,7 @@ void BookmarkChangeProcessor::ApplyChangesFromSyncModel(
model->RemoveObserver(this); model->RemoveObserver(this);
// Changes made to the bookmark model due to sync should not be undoable. // Changes made to the bookmark model due to sync should not be undoable.
#if !defined(OS_ANDROID)
ScopedSuspendBookmarkUndo suspend_undo(profile_); ScopedSuspendBookmarkUndo suspend_undo(profile_);
#endif
// Notify UI intensive observers of BookmarkModel that we are about to make // Notify UI intensive observers of BookmarkModel that we are about to make
// potentially significant changes to it, so the updates may be batched. For // potentially significant changes to it, so the updates may be batched. For
......
...@@ -402,9 +402,8 @@ syncer::SyncError BookmarkModelAssociator::AssociateModels( ...@@ -402,9 +402,8 @@ syncer::SyncError BookmarkModelAssociator::AssociateModels(
syncer::SyncMergeResult* syncer_merge_result) { syncer::SyncMergeResult* syncer_merge_result) {
// Since any changes to the bookmark model made here are not user initiated, // 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. // these change should not be undoable and so suspend the undo tracking.
#if !defined(OS_ANDROID)
ScopedSuspendBookmarkUndo suspend_undo(profile_); ScopedSuspendBookmarkUndo suspend_undo(profile_);
#endif
syncer::SyncError error = CheckModelSyncState(local_merge_result, syncer::SyncError error = CheckModelSyncState(local_merge_result,
syncer_merge_result); syncer_merge_result);
if (error.IsSet()) if (error.IsSet())
......
...@@ -2162,14 +2162,6 @@ ...@@ -2162,14 +2162,6 @@
'browser/sync/sync_ui_util.h', 'browser/sync/sync_ui_util.h',
'browser/tab_contents/background_contents.cc', 'browser/tab_contents/background_contents.cc',
'browser/tab_contents/background_contents.h', '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. # Cross-platform Aura files.
'chrome_browser_aura_sources': [ 'chrome_browser_aura_sources': [
...@@ -2320,6 +2312,16 @@ ...@@ -2320,6 +2312,16 @@
'browser/supervised_user/supervised_user_url_filter.h', 'browser/supervised_user/supervised_user_url_filter.h',
'browser/supervised_user/supervised_users.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': [ 'chrome_browser_webrtc_sources': [
# TODO(brettw) should webrtc_log_list.cc go here? # TODO(brettw) should webrtc_log_list.cc go here?
'browser/media/webrtc_log_uploader.cc', 'browser/media/webrtc_log_uploader.cc',
...@@ -2876,6 +2878,10 @@ ...@@ -2876,6 +2878,10 @@
'../sql/sql.gyp:sql', '../sql/sql.gyp:sql',
'../sync/sync.gyp:sync', '../sync/sync.gyp:sync',
], ],
# sources applied to all configurations
'sources': [
'<@(chrome_browser_undo_sources)',
],
'conditions': [ 'conditions': [
['OS != "ios"', { ['OS != "ios"', {
'dependencies': [ '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