Commit 3b24d14e authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

Extract Site Settings logic from LocationSettings

Only a couple methods in LocationSettings were related to Clank Settings
screens, so move them alongside the code that uses them in Site
Settings.

Further simplifications to follow, before the remainder of
LocationSettings is moved to a more appropriate package location.

Bug: 1043229
Change-Id: If8329b0aa9cd069ff8c6947801ca0e2eccc6bc40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008314Reviewed-by: default avatarSky Malice <skym@chromium.org>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732992}
parent 80efdefb
......@@ -13,7 +13,6 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.settings.website.WebsitePreferenceBridge;
import org.chromium.components.location.LocationSettingsDialogContext;
import org.chromium.components.location.LocationSettingsDialogOutcome;
import org.chromium.components.location.LocationUtils;
......@@ -91,21 +90,6 @@ public class LocationSettings {
});
}
/**
* Returns true if location is enabled system-wide and the Chrome location setting is enabled.
*/
public boolean areAllLocationSettingsEnabled() {
return isChromeLocationSettingEnabled()
&& LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
/**
* Returns whether Chrome's user-configurable location setting is enabled.
*/
public boolean isChromeLocationSettingEnabled() {
return WebsitePreferenceBridge.isAllowLocationEnabled();
}
@VisibleForTesting
public static void setInstanceForTesting(LocationSettings instance) {
sInstance = instance;
......
......@@ -10,7 +10,6 @@ import android.content.Intent;
import android.content.res.Resources;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.settings.LocationSettings;
import org.chromium.components.location.LocationUtils;
/**
......@@ -36,12 +35,8 @@ public class LocationCategory extends SiteSettingsCategory {
// The only time we don't want to show location as blocked in system is when Chrome also
// blocks Location by policy (because then turning it on in the system isn't going to
// turn on location in Chrome).
if (!LocationSettings.getInstance().isChromeLocationSettingEnabled()
&& !WebsitePreferenceBridge.isAllowLocationUserModifiable()) {
return false;
}
return true;
return WebsitePreferenceBridge.isAllowLocationEnabled()
|| WebsitePreferenceBridge.isAllowLocationUserModifiable();
}
@Override
......
......@@ -48,7 +48,6 @@ import org.chromium.chrome.browser.settings.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.settings.ChromeBasePreference;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
import org.chromium.chrome.browser.settings.ExpandablePreferenceGroup;
import org.chromium.chrome.browser.settings.LocationSettings;
import org.chromium.chrome.browser.settings.ManagedPreferenceDelegate;
import org.chromium.chrome.browser.settings.ManagedPreferencesUtils;
import org.chromium.chrome.browser.settings.SearchUtils;
......@@ -987,8 +986,7 @@ public class SingleCategorySettings extends PreferenceFragmentCompat
// Set the checked value.
if (mCategory.showSites(SiteSettingsCategory.Type.DEVICE_LOCATION)) {
binaryToggle.setChecked(
LocationSettings.getInstance().isChromeLocationSettingEnabled());
binaryToggle.setChecked(WebsitePreferenceBridge.isAllowLocationEnabled());
} else {
binaryToggle.setChecked(WebsitePreferenceBridge.isCategoryEnabled(contentType));
}
......
......@@ -12,7 +12,6 @@ import org.chromium.base.CommandLine;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.settings.LocationSettings;
import org.chromium.chrome.browser.settings.SettingsUtils;
import org.chromium.chrome.browser.settings.website.SiteSettingsCategory.Type;
import org.chromium.content_public.browser.ContentFeatureList;
......@@ -107,7 +106,7 @@ public class SiteSettings
int setting = ContentSettingValues.DEFAULT;
if (prefCategory == Type.DEVICE_LOCATION) {
checked = LocationSettings.getInstance().areAllLocationSettingsEnabled();
checked = WebsitePreferenceBridge.areAllLocationSettingsEnabled();
} else if (requiresTriStateSetting) {
setting = WebsitePreferenceBridge.getContentSetting(contentType);
} else {
......
......@@ -11,6 +11,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.content_settings.ContentSettingsType;
import org.chromium.components.location.LocationUtils;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -485,6 +486,14 @@ public class WebsitePreferenceBridge {
return WebsitePreferenceBridgeJni.get().getAllowLocationManagedByCustodian();
}
/**
* @return Whether location is enabled system-wide and the Chrome location setting is enabled.
*/
public static boolean areAllLocationSettingsEnabled() {
return isAllowLocationEnabled()
&& LocationUtils.getInstance().isSystemLocationSettingEnabled();
}
/**
* @return Whether the camera/microphone permission is managed
* by the custodian of the supervised account.
......
......@@ -37,7 +37,6 @@ import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.settings.ChromeBaseCheckBoxPreference;
import org.chromium.chrome.browser.settings.ChromeSwitchPreference;
import org.chromium.chrome.browser.settings.LocationSettings;
import org.chromium.chrome.browser.settings.NfcSystemLevelSetting;
import org.chromium.chrome.browser.settings.SettingsActivity;
import org.chromium.chrome.browser.settings.SettingsLauncher;
......@@ -97,7 +96,7 @@ public class SiteSettingsTest {
websitePreferences.onPreferenceChange(location, enabled);
Assert.assertEquals("Location should be " + (enabled ? "allowed" : "blocked"), enabled,
LocationSettings.getInstance().areAllLocationSettingsEnabled());
WebsitePreferenceBridge.areAllLocationSettingsEnabled());
settingsActivity.finish();
});
}
......
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