diff options
author | danduong <danduong@chromium.org> | 2014-09-22 19:50:00 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-23 02:50:09 +0000 |
commit | d817896458c8d1eaea1e09b3549126ab52658e3d (patch) | |
tree | 77aabd7f52649b5facd82e8a0ba151afefde357c /chrome | |
parent | 1511c019fae487232a2b8402c27a2834be2491e3 (diff) | |
download | chromium_src-d817896458c8d1eaea1e09b3549126ab52658e3d.zip chromium_src-d817896458c8d1eaea1e09b3549126ab52658e3d.tar.gz chromium_src-d817896458c8d1eaea1e09b3549126ab52658e3d.tar.bz2 |
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}
Diffstat (limited to 'chrome')
9 files changed, 85 insertions, 17 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java index 6a79fa5..7ee7158 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/BookmarksBridge.java @@ -451,6 +451,29 @@ public class BookmarksBridge { } /** + * 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. */ public static long getNativeBookmarkModel(Profile profile) { @@ -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); diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 63544ad..6499aa0 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -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") diff --git a/chrome/browser/android/bookmarks/bookmarks_bridge.cc b/chrome/browser/android/bookmarks/bookmarks_bridge.cc index fe7c99b..6dcb559 100644 --- a/chrome/browser/android/bookmarks/bookmarks_bridge.cc +++ b/chrome/browser/android/bookmarks/bookmarks_bridge.cc @@ -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(); diff --git a/chrome/browser/android/bookmarks/bookmarks_bridge.h b/chrome/browser/android/bookmarks/bookmarks_bridge.h index 91fc2f0..8a14d63 100644 --- a/chrome/browser/android/bookmarks/bookmarks_bridge.h +++ b/chrome/browser/android/bookmarks/bookmarks_bridge.h @@ -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. diff --git a/chrome/browser/bookmarks/bookmark_model_factory.cc b/chrome/browser/bookmarks/bookmark_model_factory.cc index 3ad36d5..d20e52f 100644 --- a/chrome/browser/bookmarks/bookmark_model_factory.cc +++ b/chrome/browser/bookmarks/bookmark_model_factory.cc @@ -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; } diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc index d75ad43..d6f53e4 100644 --- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc +++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc @@ -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 diff --git a/chrome/browser/sync/glue/bookmark_change_processor.cc b/chrome/browser/sync/glue/bookmark_change_processor.cc index 4a4b701..ae0e854 100644 --- a/chrome/browser/sync/glue/bookmark_change_processor.cc +++ b/chrome/browser/sync/glue/bookmark_change_processor.cc @@ -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 diff --git a/chrome/browser/sync/glue/bookmark_model_associator.cc b/chrome/browser/sync/glue/bookmark_model_associator.cc index c77bf96..69e4a7f0 100644 --- a/chrome/browser/sync/glue/bookmark_model_associator.cc +++ b/chrome/browser/sync/glue/bookmark_model_associator.cc @@ -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()) diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b24537d..e847295 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -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': [ |