Commit eedd8b84 authored by kkimlabs's avatar kkimlabs Committed by Commit bot

[Android] Use the correct enhanced bookmarks enabling logic.

Previously, Android's enhanced bookmarks feature depended on
--manual-enhanced-bookmarks flag and nothing else. But the
correct way is to use UpdateBookmarksExperimentState function's logic,
which desktop has been using.

BUG=386785

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

Cr-Commit-Position: refs/heads/master@{#293509}
parent daece84f
...@@ -344,6 +344,10 @@ public class BookmarksBridge { ...@@ -344,6 +344,10 @@ public class BookmarksBridge {
return nativeIsEditBookmarksEnabled(); return nativeIsEditBookmarksEnabled();
} }
public static boolean isEnhancedBookmarksEnabled(Profile profile) {
return nativeIsEnhancedBookmarksFeatureEnabled(profile);
}
@CalledByNative @CalledByNative
private void bookmarkModelLoaded() { private void bookmarkModelLoaded() {
mIsNativeBookmarkModelLoaded = true; mIsNativeBookmarkModelLoaded = true;
...@@ -474,6 +478,7 @@ public class BookmarksBridge { ...@@ -474,6 +478,7 @@ public class BookmarksBridge {
private native void nativeMoveBookmark(long nativeBookmarksBridge, BookmarkId bookmarkId, private native void nativeMoveBookmark(long nativeBookmarksBridge, BookmarkId bookmarkId,
BookmarkId newParentId, int index); BookmarkId newParentId, int index);
private static native long nativeGetNativeBookmarkModel(Profile profile); private static native long nativeGetNativeBookmarkModel(Profile profile);
private static native boolean nativeIsEnhancedBookmarksFeatureEnabled(Profile profile);
private native long nativeInit(Profile profile); private native long nativeInit(Profile profile);
private native void nativeDestroy(long nativeBookmarksBridge); private native void nativeDestroy(long nativeBookmarksBridge);
private static native boolean nativeIsEditBookmarksEnabled(); private static native boolean nativeIsEditBookmarksEnabled();
......
...@@ -1594,7 +1594,7 @@ const Experiment kExperiments[] = { ...@@ -1594,7 +1594,7 @@ const Experiment kExperiments[] = {
"enhanced-bookmarks-experiment", "enhanced-bookmarks-experiment",
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME,
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION,
kOsDesktop, kOsDesktop | kOsAndroid,
ENABLE_DISABLE_VALUE_TYPE_AND_VALUE( ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(
switches::kEnhancedBookmarksExperiment, "1", switches::kEnhancedBookmarksExperiment, "1",
switches::kEnhancedBookmarksExperiment, "0") switches::kEnhancedBookmarksExperiment, "0")
...@@ -1603,14 +1603,14 @@ const Experiment kExperiments[] = { ...@@ -1603,14 +1603,14 @@ const Experiment kExperiments[] = {
"manual-enhanced-bookmarks", "manual-enhanced-bookmarks",
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME,
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION,
kOsDesktop, kOsDesktop | kOsAndroid,
SINGLE_VALUE_TYPE(switches::kManualEnhancedBookmarks) SINGLE_VALUE_TYPE(switches::kManualEnhancedBookmarks)
}, },
{ {
"manual-enhanced-bookmarks-optout", "manual-enhanced-bookmarks-optout",
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_NAME,
IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION, IDS_FLAGS_ENABLE_ENHANCED_BOOKMARKS_DESCRIPTION,
kOsDesktop, kOsDesktop | kOsAndroid,
SINGLE_VALUE_TYPE(switches::kManualEnhancedBookmarksOptout) SINGLE_VALUE_TYPE(switches::kManualEnhancedBookmarksOptout)
}, },
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
#include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h" #include "chrome/browser/profiles/profile_android.h"
...@@ -124,11 +125,18 @@ static jlong Init(JNIEnv* env, jobject obj, jobject j_profile) { ...@@ -124,11 +125,18 @@ static jlong Init(JNIEnv* env, jobject obj, jobject j_profile) {
static jlong GetNativeBookmarkModel(JNIEnv* env, static jlong GetNativeBookmarkModel(JNIEnv* env,
jclass caller, jclass caller,
jobject j_profile) { jobject j_profile) {
Profile *profile = ProfileAndroid::FromProfileAndroid(j_profile); Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
BookmarkModel *bookmark_model_ = BookmarkModelFactory::GetForProfile(profile); BookmarkModel *bookmark_model_ = BookmarkModelFactory::GetForProfile(profile);
return reinterpret_cast<jlong>(bookmark_model_); return reinterpret_cast<jlong>(bookmark_model_);
} }
static jboolean IsEnhancedBookmarksFeatureEnabled(JNIEnv* env,
jclass clazz,
jobject j_profile) {
Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
return IsEnhancedBookmarksEnabled(profile->GetPrefs());
}
static bool IsEditBookmarksEnabled() { static bool IsEditBookmarksEnabled() {
return ProfileManager::GetLastUsedProfile()->GetPrefs()->GetBoolean( return ProfileManager::GetLastUsedProfile()->GetPrefs()->GetBoolean(
bookmarks::prefs::kEditBookmarksEnabled); bookmarks::prefs::kEditBookmarksEnabled);
......
...@@ -179,8 +179,8 @@ bool IsEnhancedBookmarksExperimentEnabled() { ...@@ -179,8 +179,8 @@ bool IsEnhancedBookmarksExperimentEnabled() {
} }
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
bool IsEnhancedBookmarkImageFetchingEnabled() { bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs) {
if (IsEnhancedBookmarksExperimentEnabled()) if (IsEnhancedBookmarksEnabled(user_prefs))
return true; return true;
// Salient images are collected from visited bookmarked pages even if the // Salient images are collected from visited bookmarked pages even if the
...@@ -192,6 +192,14 @@ bool IsEnhancedBookmarkImageFetchingEnabled() { ...@@ -192,6 +192,14 @@ bool IsEnhancedBookmarkImageFetchingEnabled() {
kFieldTrialName, "DisableImagesFetching"); kFieldTrialName, "DisableImagesFetching");
return disable_fetching.empty(); return disable_fetching.empty();
} }
bool IsEnhancedBookmarksEnabled(const PrefService* user_prefs) {
BookmarksExperimentState bookmarks_experiment_state =
static_cast<BookmarksExperimentState>(user_prefs->GetInteger(
sync_driver::prefs::kEnhancedBookmarksExperimentEnabled));
return bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED ||
bookmarks_experiment_state == BOOKMARKS_EXPERIMENT_ENABLED_FROM_FINCH;
}
#endif #endif
bool IsEnableDomDistillerSet() { bool IsEnableDomDistillerSet() {
......
...@@ -43,12 +43,20 @@ void ForceFinchBookmarkExperimentIfNeeded( ...@@ -43,12 +43,20 @@ void ForceFinchBookmarkExperimentIfNeeded(
PrefService* local_state, PrefService* local_state,
BookmarksExperimentState bookmarks_experiment_state); BookmarksExperimentState bookmarks_experiment_state);
// Returns true if enhanced bookmarks experiment is enabled. // Returns true if enhanced bookmarks experiment is running.
// Experiment could be enable from Chrome sync or from Finch. // Experiment could run by Chrome sync or by Finch.
// Note that this doesn't necessarily mean that enhanced bookmarks
// is enabled, e.g., user can opt out using a flag.
bool IsEnhancedBookmarksExperimentEnabled(); bool IsEnhancedBookmarksExperimentEnabled();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
bool IsEnhancedBookmarkImageFetchingEnabled(); // Returns true if enhanced bookmark salient image prefetching is enabled.
// This can be controlled by field trial.
bool IsEnhancedBookmarkImageFetchingEnabled(const PrefService* user_prefs);
// Returns true if enhanced bookmarks is enabled.
bool IsEnhancedBookmarksEnabled(const PrefService* user_prefs);
#endif #endif
// Returns true when flag enable-dom-distiller is set or enabled from Finch. // Returns true when flag enable-dom-distiller is set or enabled from Finch.
......
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