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; ...@@ -8,33 +8,24 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import org.chromium.base.IntentUtils; import org.chromium.base.IntentUtils;
/** /**
* A utility class for launching Chrome Settings. * A utility class for launching Chrome Settings.
*/ */
public class SettingsLauncher { public class SettingsLauncher {
private static SettingsLauncher sSettingsLauncher = new SettingsLauncher(); public SettingsLauncher() {}
private static SettingsLauncher sInstanceForTests;
@VisibleForTesting
protected 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() { public static SettingsLauncher getInstance() {
return sInstanceForTests == null ? sSettingsLauncher : sInstanceForTests; return new SettingsLauncher();
}
@VisibleForTesting
public void setInstanceForTests(SettingsLauncher getter) {
sInstanceForTests = getter;
} }
/** /**
......
...@@ -66,6 +66,8 @@ public class HomeButton extends ChromeImageButton ...@@ -66,6 +66,8 @@ public class HomeButton extends ChromeImageButton
private static boolean sSaveContextMenuForTests; private static boolean sSaveContextMenuForTests;
private ContextMenu mMenuForTests; private ContextMenu mMenuForTests;
private SettingsLauncher mSettingsLauncher;
public HomeButton(Context context, AttributeSet attrs) { public HomeButton(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
...@@ -85,6 +87,8 @@ public class HomeButton extends ChromeImageButton ...@@ -85,6 +87,8 @@ public class HomeButton extends ChromeImageButton
} }
} }
}; };
mSettingsLauncher = new SettingsLauncher();
} }
public void destroy() { public void destroy() {
...@@ -143,7 +147,7 @@ public class HomeButton extends ChromeImageButton ...@@ -143,7 +147,7 @@ public class HomeButton extends ChromeImageButton
assert !isManagedByPolicy(); assert !isManagedByPolicy();
if (isHomepageSettingsUIConversionEnabled()) { if (isHomepageSettingsUIConversionEnabled()) {
assert item.getItemId() == ID_SETTINGS; assert item.getItemId() == ID_SETTINGS;
SettingsLauncher.getInstance().launchSettingsPage(getContext(), HomepageSettings.class); mSettingsLauncher.launchSettingsPage(getContext(), HomepageSettings.class);
} else { } else {
assert item.getItemId() == ID_REMOVE; assert item.getItemId() == ID_REMOVE;
HomepageManager.getInstance().setPrefHomepageEnabled(false); HomepageManager.getInstance().setPrefHomepageEnabled(false);
...@@ -255,4 +259,9 @@ public class HomeButton extends ChromeImageButton ...@@ -255,4 +259,9 @@ public class HomeButton extends ChromeImageButton
public ContextMenu getMenuForTests() { public ContextMenu getMenuForTests() {
return mMenuForTests; return mMenuForTests;
} }
@VisibleForTesting
public void setSettingsLauncherForTests(SettingsLauncher settingsLauncher) {
mSettingsLauncher = settingsLauncher;
}
} }
...@@ -71,7 +71,6 @@ public class HomeButtonTest extends DummyUiActivityTestCase { ...@@ -71,7 +71,6 @@ public class HomeButtonTest extends DummyUiActivityTestCase {
super.setUpTest(); super.setUpTest();
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
SettingsLauncher.getInstance().setInstanceForTests(mSettingsLauncher);
// Set the default test status for homepage button tests. // Set the default test status for homepage button tests.
// By default, the homepage is <b>enabled</b> and with customized URL. // By default, the homepage is <b>enabled</b> and with customized URL.
...@@ -84,6 +83,7 @@ public class HomeButtonTest extends DummyUiActivityTestCase { ...@@ -84,6 +83,7 @@ public class HomeButtonTest extends DummyUiActivityTestCase {
mIdHomeButton = View.generateViewId(); mIdHomeButton = View.generateViewId();
mHomeButton = new HomeButton(getActivity(), null); mHomeButton = new HomeButton(getActivity(), null);
mHomeButton.setId(mIdHomeButton); mHomeButton.setId(mIdHomeButton);
mHomeButton.setSettingsLauncherForTests(mSettingsLauncher);
HomeButton.setSaveContextMenuForTests(true); HomeButton.setSaveContextMenuForTests(true);
content.addView(mHomeButton); 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