Commit 0f86ce86 authored by Yue Li's avatar Yue Li Committed by Commit Bot

[Assistant Prefs Migration] AssistantDisabledByPolicy

This cl migrates kAssistantDisabledByPolicy preference from
assistant_pref_util.h to assistant_prefs.h

Also, removes the file assistant_pref_util.h and updates related tests.

Detailed design doc: https://goto.google.com/assistant-prefs

Bug: b/110211045
Test: Run existing tests
Change-Id: Id41932cc6aeb9dc9ac5926dd764ca8c468412341
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1705109
Commit-Queue: Yue Li <updowndota@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678578}
parent f091e9b6
......@@ -124,6 +124,7 @@ source_set("chromeos") {
"//chromeos/login/login_state",
"//chromeos/login/session",
"//chromeos/network",
"//chromeos/services/assistant/public/cpp:prefs",
"//chromeos/services/cros_healthd/public/cpp",
"//chromeos/services/cros_healthd/public/mojom",
"//chromeos/services/device_sync/public/cpp",
......
......@@ -9,7 +9,6 @@
#include "base/files/scoped_temp_dir.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chrome/test/base/chrome_ash_test_base.h"
#include "chrome/test/base/testing_profile.h"
#include "components/arc/arc_prefs.h"
......
......@@ -11,8 +11,8 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/account_info.h"
......@@ -88,7 +88,7 @@ ash::mojom::AssistantAllowedState IsAssistantAllowedForProfile(
return ash::mojom::AssistantAllowedState::DISALLOWED_BY_LOCALE;
}
if (prefs->GetBoolean(::assistant::prefs::kAssistantDisabledByPolicy))
if (prefs->GetBoolean(chromeos::assistant::prefs::kAssistantDisabledByPolicy))
return ash::mojom::AssistantAllowedState::DISALLOWED_BY_POLICY;
// Bypass the account type check when using fake gaia login, e.g. in Tast
......
......@@ -24,7 +24,6 @@
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chrome/browser/ui/webui/chromeos/login/assistant_optin_flow_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/common/chrome_paths.h"
......@@ -1094,8 +1093,7 @@ IN_PROC_BROWSER_TEST_F(AssistantOptInFlowTest, AssistantDisabledByPolicy) {
ExpectCollectedOptIns({});
PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
EXPECT_TRUE(
prefs->GetBoolean(::assistant::prefs::kAssistantDisabledByPolicy));
EXPECT_TRUE(prefs->GetBoolean(assistant::prefs::kAssistantDisabledByPolicy));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionHotwordEnabled));
EXPECT_FALSE(prefs->GetBoolean(arc::prefs::kVoiceInteractionContextEnabled));
......
......@@ -53,7 +53,6 @@
#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_method_short.h"
#include "chrome/browser/extensions/api/settings_private/chromeos_resolve_time_zone_by_geolocation_on_off.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#include "chromeos/settings/cros_settings_names.h"
......@@ -420,7 +419,7 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
// Google Assistant.
(*s_whitelist)[chromeos::assistant::prefs::kAssistantConsentStatus] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_whitelist)[::assistant::prefs::kAssistantDisabledByPolicy] =
(*s_whitelist)[chromeos::assistant::prefs::kAssistantDisabledByPolicy] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[arc::prefs::kVoiceInteractionEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
......
......@@ -314,7 +314,6 @@
#include "extensions/browser/api/lock_screen_data/lock_screen_item_storage.h"
#if BUILDFLAG(ENABLE_CROS_ASSISTANT)
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
#endif
......@@ -873,9 +872,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
::onc::RegisterProfilePrefs(registry);
#if BUILDFLAG(ENABLE_CROS_ASSISTANT)
// TODO(b/110211045): Merge these two methods after migrating other Assistant
// related prefs.
assistant::prefs::RegisterProfilePrefs(registry);
chromeos::assistant::prefs::RegisterProfilePrefsForBrowser(registry);
#endif
......
......@@ -3597,8 +3597,6 @@ jumbo_split_static_library("ui") {
"ash/assistant/assistant_context_util.h",
"ash/assistant/assistant_image_downloader.cc",
"ash/assistant/assistant_image_downloader.h",
"ash/assistant/assistant_pref_util.cc",
"ash/assistant/assistant_pref_util.h",
"ash/assistant/assistant_setup.cc",
"ash/assistant/assistant_setup.h",
"ash/assistant/device_actions.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include <string>
#include "components/arc/arc_prefs.h"
#include "components/prefs/pref_registry_simple.h"
namespace assistant {
namespace prefs {
// A preference that indicates the Assistant has been disabled by domain policy.
// If true, the Assistant will always been disabled and user cannot enable it.
const char kAssistantDisabledByPolicy[] =
"settings.assistant.disabled_by_policy";
void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kAssistantDisabledByPolicy, false);
}
} // namespace prefs
} // namespace assistant
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_PREF_UTIL_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_PREF_UTIL_H_
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
#include "components/prefs/pref_service.h"
class PrefRegistrySimple;
namespace assistant {
namespace prefs {
extern const char kAssistantDisabledByPolicy[];
// Registers Assistant specific profile preferences.
void RegisterProfilePrefs(PrefRegistrySimple* registry);
} // namespace prefs
} // namespace assistant
#endif // CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_PREF_UTIL_H_
......@@ -15,7 +15,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chrome/browser/ui/views/chrome_web_dialog_view.h"
#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
#include "chrome/common/url_constants.h"
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/ash/assistant/assistant_pref_util.h"
#include "chrome/browser/ui/webui/chromeos/assistant_optin/assistant_optin_utils.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/services/assistant/public/cpp/assistant_prefs.h"
......@@ -209,7 +208,7 @@ void AssistantOptInFlowScreenHandler::SetupAssistantConnection() {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
// If Assistant is disabled by domain admin, end the flow.
if (prefs->GetBoolean(::assistant::prefs::kAssistantDisabledByPolicy)) {
if (prefs->GetBoolean(assistant::prefs::kAssistantDisabledByPolicy)) {
HandleFlowFinished();
return;
}
......@@ -339,7 +338,7 @@ void AssistantOptInFlowScreenHandler::OnGetSettingsResponse(
DVLOG(1) << "Assistant is disabled by domain policy. Skip Assistant "
"opt-in flow.";
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(::assistant::prefs::kAssistantDisabledByPolicy, true);
prefs->SetBoolean(assistant::prefs::kAssistantDisabledByPolicy, true);
prefs->SetBoolean(arc::prefs::kVoiceInteractionEnabled, false);
HandleFlowFinished();
return;
......
......@@ -16,10 +16,17 @@ namespace prefs {
// This preference should only be changed in browser.
const char kAssistantConsentStatus[] =
"settings.voice_interaction.activity_control.consent_status";
// A preference that indicates the Assistant has been disabled by domain policy.
// If true, the Assistant will always been disabled and user cannot enable it.
// This preference should only be changed in browser.
const char kAssistantDisabledByPolicy[] =
"settings.assistant.disabled_by_policy";
void RegisterProfilePrefsForBrowser(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(kAssistantConsentStatus,
ConsentStatus::kUnknown, PrefRegistry::PUBLIC);
registry->RegisterBooleanPref(kAssistantDisabledByPolicy, false,
PrefRegistry::PUBLIC);
}
void RegisterProfilePrefsForeign(PrefRegistrySimple* registry, bool for_test) {
......@@ -30,6 +37,7 @@ void RegisterProfilePrefsForeign(PrefRegistrySimple* registry, bool for_test) {
return;
}
registry->RegisterForeignPref(kAssistantConsentStatus);
registry->RegisterForeignPref(kAssistantDisabledByPolicy);
}
} // namespace prefs
......
......@@ -31,6 +31,7 @@ enum ConsentStatus {
};
extern const char kAssistantConsentStatus[];
extern const char kAssistantDisabledByPolicy[];
// Registers Assistant specific profile preferences for browser prefs.
void RegisterProfilePrefsForBrowser(PrefRegistrySimple* registry);
......
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