Skip to content

Commit

Permalink
🧇 Cleanup LocaleManager API
Browse files Browse the repository at this point in the history
Removes methods unnecessarily exposed by locale.LocaleManager. Their
implementation from the delegate becomes either private, protected, or
can be entirely removed because it was not used anymore.

Bug: 1475236
Change-Id: I81df8a549d4060ac05e8f67468e417dfa5e5ee48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4802606
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Reviewed-by: Tomasz Wiszkowski <ender@google.com>
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1187709}
  • Loading branch information
Nicolas Dossou-Gbete authored and Chromium LUCI CQ committed Aug 24, 2023
1 parent c94bf36 commit 53e8200
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 174 deletions.
12 changes: 0 additions & 12 deletions chrome/browser/android/locale/locale_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "chrome/browser/locale/jni_headers/LocaleManager_jni.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "url/gurl.h"

// static
std::string LocaleManager::GetYandexReferralID() {
Expand All @@ -31,13 +29,3 @@ std::string LocaleManager::GetMailRUReferralID() {
return base::android::ConvertJavaStringToUTF8(
env, Java_LocaleManager_getMailRUReferralId(env, jlocale_manager));
}

// static
void LocaleManager::RecordUserTypeMetrics() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> jlocale_manager =
Java_LocaleManager_getInstance(env);
if (jlocale_manager.is_null())
return;
return Java_LocaleManager_recordUserTypeMetrics(env, jlocale_manager);
}
1 change: 0 additions & 1 deletion chrome/browser/android/locale/locale_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class LocaleManager {

static std::string GetYandexReferralID();
static std::string GetMailRUReferralID();
static void RecordUserTypeMetrics();
};

#endif // CHROME_BROWSER_ANDROID_LOCALE_LOCALE_MANAGER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.Activity;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import org.chromium.base.Callback;
import org.chromium.base.ThreadUtils;
Expand All @@ -25,7 +26,7 @@
* TODO(https://crbug.com/1198923) Turn this into a per-activity object.
*/
public class LocaleManager implements DefaultSearchEngineDialogHelper.Delegate {
private static LocaleManager sInstance = new LocaleManager();
private static final LocaleManager sInstance = new LocaleManager();

private LocaleManagerDelegate mDelegate;

Expand All @@ -41,7 +42,7 @@ public static LocaleManager getInstance() {
/**
* Default constructor.
*/
public LocaleManager() {
private LocaleManager() {
mDelegate = new LocaleManagerDelegateImpl();
mDelegate.setDefaulSearchEngineDelegate(this);
}
Expand All @@ -67,35 +68,9 @@ public void recordStartupMetrics() {
mDelegate.recordStartupMetrics();
}

/** Returns whether the Chrome instance is running in a special locale. */
public boolean isSpecialLocaleEnabled() {
return mDelegate.isSpecialLocaleEnabled();
}

/**
* @return The country id of the special locale.
*/
public String getSpecialLocaleId() {
return mDelegate.getSpecialLocaleId();
}

/**
* Adds local search engines for special locale.
*/
public void addSpecialSearchEngines() {
mDelegate.addSpecialSearchEngines();
}

/**
* Removes local search engines for special locale.
*/
public void removeSpecialSearchEngines() {
mDelegate.removeSpecialSearchEngines();
}

/**
* Shows a promotion dialog about search engines depending on Locale and other conditions.
* See {@link LocaleManager#getSearchEnginePromoShowType()} for possible types and logic.
* See {@link LocaleManager#getSearchEnginePromoShowType} for possible types and logic.
*
* @param activity Activity showing the dialog.
* @param onSearchEngineFinalized Notified when the search engine has been finalized. This can
Expand Down Expand Up @@ -162,36 +137,6 @@ public void onUserSearchEngineChoice(
mDelegate.onUserSearchEngineChoiceFromPromoDialog(type, keywords, keyword);
}

/**
* To be called when the search engine promo dialog is dismissed without the user confirming
* a valid search engine selection.
*/
public void onUserLeavePromoDialogWithNoConfirmedChoice(@SearchEnginePromoType int type) {
mDelegate.onUserLeavePromoDialogWithNoConfirmedChoice(type);
}

/** Set a LocaleManager instance. This is called only by AppHooks. */
public static void setInstance(LocaleManager instance) {
sInstance = instance;
}

/**
* Record any locale based metrics related with the search widget. Recorded on initialization
* only.
* @param widgetPresent Whether there is at least one search widget on home screen.
*/
public void recordLocaleBasedSearchWidgetMetrics(boolean widgetPresent) {
mDelegate.recordLocaleBasedSearchWidgetMetrics(widgetPresent);
}

/**
* Returns whether the search engine promo has been shown and the user selected a valid option
* and successfully completed the promo.
*/
public boolean hasCompletedSearchEnginePromo() {
return mDelegate.hasCompletedSearchEnginePromo();
}

/** Returns whether the search engine promo has been shown in this session. */
public boolean hasShownSearchEnginePromoThisSession() {
return mDelegate.hasShownSearchEnginePromoThisSession();
Expand All @@ -213,22 +158,8 @@ public void recordLocaleBasedSearchMetrics(
mDelegate.recordLocaleBasedSearchMetrics(isFromSearchWidget, url, transition);
}

/**
* Returns whether the user requires special handling.
*/
public boolean isSpecialUser() {
return mDelegate.isSpecialUser();
}

/**
* Record metrics related to user type.
*/
@CalledByNative
public void recordUserTypeMetrics() {
mDelegate.recordUserTypeMetrics();
}

/** Set a LocaleManagerDelegate to be used for testing. */
@VisibleForTesting
public void setDelegateForTest(LocaleManagerDelegate delegate) {
mDelegate = delegate;
mDelegate.setDefaulSearchEngineDelegate(this);
Expand Down

0 comments on commit 53e8200

Please sign in to comment.