Commit 99f41046 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

Make SettingsLauncher non-singleton

This is a first step towards modularizing SettingsLauncher.

See go/clank-modularize-settings-launcher for full details.

Bug: 1054193
Change-Id: Ib073e60aacce51ff7948621fc35c3bf2d6d68988
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149885Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759879}
parent be9a5b4e
......@@ -8,33 +8,24 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import org.chromium.base.IntentUtils;
/**
* A utility class for launching Chrome Settings.
*/
public class SettingsLauncher {
private static SettingsLauncher sSettingsLauncher = new SettingsLauncher();
private static SettingsLauncher sInstanceForTests;
@VisibleForTesting
protected SettingsLauncher() {}
public SettingsLauncher() {}
/**
* Returns the singleton instance of this class.
* @return An instance of this class.
* @deprecated New code should construct {@link SettingsLauncher} directly.
*/
// TODO(crbug.com/1054193): Inline and remove this method.
@Deprecated
public static SettingsLauncher getInstance() {
return sInstanceForTests == null ? sSettingsLauncher : sInstanceForTests;
}
@VisibleForTesting
public void setInstanceForTests(SettingsLauncher getter) {
sInstanceForTests = getter;
return new SettingsLauncher();
}
/**
......
......@@ -66,6 +66,8 @@ public class HomeButton extends ChromeImageButton
private static boolean sSaveContextMenuForTests;
private ContextMenu mMenuForTests;
private SettingsLauncher mSettingsLauncher;
public HomeButton(Context context, AttributeSet attrs) {
super(context, attrs);
......@@ -85,6 +87,8 @@ public class HomeButton extends ChromeImageButton
}
}
};
mSettingsLauncher = new SettingsLauncher();
}
public void destroy() {
......@@ -143,7 +147,7 @@ public class HomeButton extends ChromeImageButton
assert !isManagedByPolicy();
if (isHomepageSettingsUIConversionEnabled()) {
assert item.getItemId() == ID_SETTINGS;
SettingsLauncher.getInstance().launchSettingsPage(getContext(), HomepageSettings.class);
mSettingsLauncher.launchSettingsPage(getContext(), HomepageSettings.class);
} else {
assert item.getItemId() == ID_REMOVE;
HomepageManager.getInstance().setPrefHomepageEnabled(false);
......@@ -255,4 +259,9 @@ public class HomeButton extends ChromeImageButton
public ContextMenu getMenuForTests() {
return mMenuForTests;
}
@VisibleForTesting
public void setSettingsLauncherForTests(SettingsLauncher settingsLauncher) {
mSettingsLauncher = settingsLauncher;
}
}
......@@ -71,7 +71,6 @@ public class HomeButtonTest extends DummyUiActivityTestCase {
super.setUpTest();
MockitoAnnotations.initMocks(this);
SettingsLauncher.getInstance().setInstanceForTests(mSettingsLauncher);
// Set the default test status for homepage button tests.
// By default, the homepage is <b>enabled</b> and with customized URL.
......@@ -84,6 +83,7 @@ public class HomeButtonTest extends DummyUiActivityTestCase {
mIdHomeButton = View.generateViewId();
mHomeButton = new HomeButton(getActivity(), null);
mHomeButton.setId(mIdHomeButton);
mHomeButton.setSettingsLauncherForTests(mSettingsLauncher);
HomeButton.setSaveContextMenuForTests(true);
content.addView(mHomeButton);
......
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