Commit 0d2c0688 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Settings] Fix a few issues with existing per-page providers

(1) Both the MultiDevice and Internet pages had some loadTimeData added
    within os_settings_ui.cc, so this CL moves them to their per-page
    provider instead.
(2) Adds explicit dependencies to OsSettingsLocalizedStringsProvider by
    adding relevant KeyedServices to its constructor. As more are added
    in subsequent pages, this will make it easier to track which
    services are used.
(3) Minor changes in tests and const getters.

Bug: 1069849
Change-Id: I49debfaa32375a585c7003932c8d2daa745168eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153700Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759844}
parent 25b3a2ac
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/internet_strings_provider.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/network_config_service.h"
#include "base/bind.h"
#include "base/no_destructor.h"
......@@ -215,6 +216,9 @@ void InternetStringsProvider::AddUiStrings(
chromeos::network_element::AddConfigLocalizedStrings(html_source);
chromeos::network_element::AddErrorLocalizedStrings(html_source);
html_source->AddBoolean("showTechnologyBadge",
!ash::features::IsSeparateNetworkIconsEnabled());
html_source->AddString("networkGoogleNameserversLearnMoreUrl",
chrome::kGoogleNameserversLearnMoreURL);
html_source->AddString(
......
......@@ -6,10 +6,12 @@
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "chromeos/services/multidevice_setup/public/cpp/url_provider.h"
#include "chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.h"
#include "content/public/browser/web_ui_data_source.h"
......@@ -107,6 +109,11 @@ void MultiDeviceStringsProvider::AddUiStrings(
};
AddLocalizedStringsBulk(html_source, kLocalizedStrings);
html_source->AddBoolean(
"multideviceAllowedByPolicy",
chromeos::multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
profile()->GetPrefs()));
html_source->AddString(
"multideviceForgetDeviceSummary",
ui::SubstituteChromeOSDeviceType(
......
......@@ -1942,7 +1942,8 @@ void AddPageVisibilityStrings(content::WebUIDataSource* html_source) {
OsSettingsLocalizedStringsProvider::OsSettingsLocalizedStringsProvider(
Profile* profile,
local_search_service::LocalSearchServiceImpl* local_search_service)
local_search_service::LocalSearchServiceImpl* local_search_service,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client)
: index_(local_search_service->GetIndexImpl(
local_search_service::IndexId::kCrosSettings)) {
// Add per-page string providers.
......@@ -1952,9 +1953,7 @@ OsSettingsLocalizedStringsProvider::OsSettingsLocalizedStringsProvider(
per_page_providers_.push_back(
std::make_unique<BluetoothStringsProvider>(profile, /*delegate=*/this));
per_page_providers_.push_back(std::make_unique<MultiDeviceStringsProvider>(
profile, /*delegate=*/this,
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(
profile)));
profile, /*delegate=*/this, multidevice_setup_client));
}
OsSettingsLocalizedStringsProvider::~OsSettingsLocalizedStringsProvider() =
......
......@@ -25,6 +25,11 @@ class LocalSearchServiceImpl;
} // namespace local_search_service
namespace chromeos {
namespace multidevice_setup {
class MultiDeviceSetupClient;
} // namespace multidevice_setup
namespace settings {
struct SearchConcept;
......@@ -56,7 +61,8 @@ class OsSettingsLocalizedStringsProvider
public:
OsSettingsLocalizedStringsProvider(
Profile* profile,
local_search_service::LocalSearchServiceImpl* local_search_service);
local_search_service::LocalSearchServiceImpl* local_search_service,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
OsSettingsLocalizedStringsProvider(
const OsSettingsLocalizedStringsProvider& other) = delete;
OsSettingsLocalizedStringsProvider& operator=(
......
......@@ -49,8 +49,9 @@ OsSettingsLocalizedStringsProviderFactory::BuildServiceInstanceFor(
return new OsSettingsLocalizedStringsProvider(
profile,
local_search_service::LocalSearchServiceProxyFactory::GetForProfile(
Profile::FromBrowserContext(profile))
->GetLocalSearchServiceImpl());
profile)
->GetLocalSearchServiceImpl(),
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(profile));
}
bool OsSettingsLocalizedStringsProviderFactory::ServiceIsNULLWhileTesting()
......
......@@ -60,6 +60,7 @@ class OsSettingsPerPageStringsProvider {
OsSettingsPerPageStringsProvider(Profile* profile, Delegate* delegate);
Profile* profile() { return profile_; }
const Profile* profile() const { return profile_; }
Delegate* delegate() { return delegate_; }
private:
......
......@@ -388,10 +388,6 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) {
"privacySettingsRedesignEnabled",
base::FeatureList::IsEnabled(::features::kPrivacySettingsRedesign));
html_source->AddBoolean(
"multideviceAllowedByPolicy",
chromeos::multidevice_setup::AreAnyMultiDeviceFeaturesAllowed(
profile->GetPrefs()));
html_source->AddBoolean(
"quickUnlockEnabled",
chromeos::quick_unlock::IsPinEnabled(profile->GetPrefs()));
......@@ -428,8 +424,6 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) {
html_source->AddBoolean(
"lockScreenHideSensitiveNotificationsSupported",
ash::features::IsLockScreenHideSensitiveNotificationsSupported());
html_source->AddBoolean("showTechnologyBadge",
!ash::features::IsSeparateNetworkIconsEnabled());
html_source->AddBoolean("hasInternalStylus",
ash::stylus_utils::HasInternalStylus());
......
......@@ -32,7 +32,7 @@ class SearchHandlerTest : public testing::Test {
provider_ = std::make_unique<OsSettingsLocalizedStringsProvider>(
profile_manager_.CreateTestingProfile("TestingProfile"),
&local_search_service_);
&local_search_service_, /*multidevice_setup_client=*/nullptr);
handler_ = std::make_unique<SearchHandler>(provider_.get(),
&local_search_service_);
......
......@@ -41,7 +41,7 @@ void RegisterFeaturePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kSmartLockEnabledPrefName, true);
}
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service) {
bool AreAnyMultiDeviceFeaturesAllowed(const PrefService* pref_service) {
return pref_service->GetBoolean(kInstantTetheringAllowedPrefName) ||
pref_service->GetBoolean(kMessagesAllowedPrefName) ||
pref_service->GetBoolean(kSmartLockAllowedPrefName);
......
......@@ -36,7 +36,7 @@ extern const char kSmartLockEnabledPrefName[];
extern const char kSmartLockEnabledDeprecatedPrefName[];
void RegisterFeaturePrefs(PrefRegistrySimple* registry);
bool AreAnyMultiDeviceFeaturesAllowed(PrefService* pref_service);
bool AreAnyMultiDeviceFeaturesAllowed(const PrefService* pref_service);
bool IsFeatureAllowed(mojom::Feature feature, PrefService* pref_service);
} // namespace multidevice_setup
......
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