coral: apply location and age restrictions
Stop sending grouping and embedding requests when the Generative AI is not available for current profile. To avoid frequently checking the GenAI availability, we use two optional variables to cache the age and location availabilities from the first inquiry of a user session till the start of next user session. During post-login, the data request may happen before identity manager finish loading tokens such that we cannot get age restriction. To solve this problem, we make coral delegate observe identity manager and once all tokens are loaded, the age restriction result will be passed to the inquiry callback. The checked result will be saved in user's pref such that the value can be used in next login. Test: manual test Bug: b:397117574 Change-Id: Iefda41921f3a4bf2d4cccc289603c9eceb6459d3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6279008 Commit-Queue: Xiaodan Zhu <zxdan@chromium.org> Reviewed-by: Xiaoqian Dai <xdai@chromium.org> Reviewed-by: Howard Yang <hcyang@google.com> Cr-Commit-Position: refs/heads/main@{#1426477}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
833679a772
commit
55f81e8dd7
@ -14,6 +14,7 @@
|
||||
#include "ash/app_list/app_list_controller_impl.h"
|
||||
#include "ash/app_list/views/app_list_nudge_controller.h"
|
||||
#include "ash/assistant/assistant_controller_impl.h"
|
||||
#include "ash/birch/birch_coral_provider.h"
|
||||
#include "ash/birch/birch_item.h"
|
||||
#include "ash/birch/birch_model.h"
|
||||
#include "ash/birch/coral_util.h"
|
||||
@ -133,6 +134,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry,
|
||||
AutozoomNudgeController::RegisterProfilePrefs(registry);
|
||||
AmbientController::RegisterProfilePrefs(registry);
|
||||
BirchBarController::RegisterProfilePrefs(registry);
|
||||
BirchCoralProvider::RegisterProfilePrefs(registry);
|
||||
BirchItem::RegisterProfilePrefs(registry);
|
||||
BirchModel::RegisterProfilePrefs(registry);
|
||||
BirchPrivacyNudgeController::RegisterProfilePrefs(registry);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
#include "ash/constants/ash_switches.h"
|
||||
#include "ash/public/cpp/app_types_util.h"
|
||||
#include "ash/public/cpp/coral_delegate.h"
|
||||
#include "ash/public/cpp/saved_desk_delegate.h"
|
||||
#include "ash/public/cpp/tab_cluster/tab_cluster_ui_controller.h"
|
||||
#include "ash/public/cpp/tab_cluster/tab_cluster_ui_item.h"
|
||||
@ -34,6 +35,7 @@
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "chromeos/ash/services/coral/public/mojom/coral_service.mojom.h"
|
||||
#include "chromeos/ui/base/window_properties.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
#include "mojo/public/cpp/bindings/pending_remote.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
@ -342,6 +344,11 @@ BirchCoralProvider* BirchCoralProvider::Get() {
|
||||
return g_instance;
|
||||
}
|
||||
|
||||
// static
|
||||
void BirchCoralProvider::RegisterProfilePrefs(PrefRegistrySimple* registry) {
|
||||
registry->RegisterBooleanPref(prefs::kCoralGenAIAgeAllowed, false);
|
||||
}
|
||||
|
||||
const coral::mojom::GroupPtr& BirchCoralProvider::GetGroupById(
|
||||
const base::Token& group_id) const {
|
||||
// Add crash keys here to track the crash of crbug.com/395130742.
|
||||
@ -427,6 +434,38 @@ void BirchCoralProvider::RemoveObserver(Observer* observer) {
|
||||
observers_.RemoveObserver(observer);
|
||||
}
|
||||
|
||||
bool BirchCoralProvider::GetGenAIAvailability() {
|
||||
// Return true, if using a fake backend or group.
|
||||
auto* current_process = base::CommandLine::ForCurrentProcess();
|
||||
if (current_process->HasSwitch(switches::kForceBirchFakeCoralBackend) ||
|
||||
current_process->HasSwitch(switches::kForceBirchFakeCoralGroup)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto* coral_delegate = Shell::Get()->coral_delegate();
|
||||
if (!is_gen_ai_location_allow_.has_value()) {
|
||||
is_gen_ai_location_allow_ = coral_delegate->GetGenAILocationAvailability();
|
||||
if (!(*is_gen_ai_location_allow_)) {
|
||||
VLOG(1) << "Coral: location is restricted by GenAI";
|
||||
}
|
||||
}
|
||||
|
||||
if (!(*is_gen_ai_location_allow_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If age availability is not checked and the checking result will be returned
|
||||
// asynchronously, use the pref value.
|
||||
if (!is_gen_ai_age_availability_checked_) {
|
||||
coral_delegate->CheckGenAIAgeAvailability(
|
||||
base::BindOnce(&BirchCoralProvider::OnGenAIAgeAvailabilityReceived,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
return (*is_gen_ai_location_allow_) &&
|
||||
GetPrefService()->GetBoolean(prefs::kCoralGenAIAgeAllowed);
|
||||
}
|
||||
|
||||
void BirchCoralProvider::RequestBirchDataFetch() {
|
||||
if (!coral_util::IsCoralAllowedByPolicy(GetPrefService())) {
|
||||
// Coral is disabled by policy.
|
||||
@ -474,6 +513,11 @@ void BirchCoralProvider::RequestBirchDataFetch() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GetGenAIAvailability()) {
|
||||
HandleCoralResponse(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasValidPostLoginData()) {
|
||||
HandlePostLoginDataRequest();
|
||||
} else {
|
||||
@ -578,9 +622,18 @@ void BirchCoralProvider::OnSessionStateChanged(
|
||||
// Clear stale items on login.
|
||||
if (state == session_manager::SessionState::ACTIVE) {
|
||||
Reset();
|
||||
is_gen_ai_age_availability_checked_ = false;
|
||||
is_gen_ai_location_allow_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void BirchCoralProvider::OnActiveUserSessionChanged(
|
||||
const AccountId& account_id) {
|
||||
Reset();
|
||||
is_gen_ai_age_availability_checked_ = false;
|
||||
is_gen_ai_location_allow_.reset();
|
||||
}
|
||||
|
||||
void BirchCoralProvider::OverrideCoralResponseForTest(
|
||||
std::unique_ptr<CoralResponse> response) {
|
||||
fake_response_ = std::move(response);
|
||||
@ -764,7 +817,8 @@ void BirchCoralProvider::MaybeCacheTabEmbedding(TabClusterUIItem* tab_item) {
|
||||
session_controller->GetPrimaryUserPrefService()->GetBoolean(
|
||||
prefs::kBirchUseCoral) &&
|
||||
coral_util::IsCoralAllowedByPolicy(GetPrefService()) &&
|
||||
IsValidTab(tab_item) && ShouldCreateEmbedding(tab_item)) {
|
||||
GetGenAIAvailability() && IsValidTab(tab_item) &&
|
||||
ShouldCreateEmbedding(tab_item)) {
|
||||
CacheTabEmbedding(tab_item);
|
||||
}
|
||||
}
|
||||
@ -782,14 +836,7 @@ void BirchCoralProvider::CacheTabEmbedding(TabClusterUIItem* tab_item) {
|
||||
coral::mojom::Entity::NewTab(std::move(tab_mojom)));
|
||||
CoralRequest request;
|
||||
request.set_content(std::move(active_tab_app_data));
|
||||
Shell::Get()->coral_controller()->CacheEmbeddings(
|
||||
std::move(request),
|
||||
base::BindOnce(&BirchCoralProvider::HandleEmbeddingResult,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void BirchCoralProvider::HandleEmbeddingResult(bool success) {
|
||||
// TODO(conniekxu) Add metrics.
|
||||
Shell::Get()->coral_controller()->CacheEmbeddings(std::move(request));
|
||||
}
|
||||
|
||||
void BirchCoralProvider::ObserveAllWindowsInResponse() {
|
||||
@ -920,4 +967,12 @@ void BirchCoralProvider::Reset() {
|
||||
windows_observation_.RemoveAllObservations();
|
||||
}
|
||||
|
||||
void BirchCoralProvider::OnGenAIAgeAvailabilityReceived(bool allow) {
|
||||
if (!allow) {
|
||||
VLOG(1) << "Coral: age is restricted by GenAI";
|
||||
}
|
||||
is_gen_ai_age_availability_checked_ = true;
|
||||
GetPrefService()->SetBoolean(prefs::kCoralGenAIAgeAllowed, allow);
|
||||
}
|
||||
|
||||
} // namespace ash
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "chromeos/ash/services/coral/public/mojom/coral_service.mojom.h"
|
||||
#include "ui/aura/window_observer.h"
|
||||
|
||||
class PrefRegistrySimple;
|
||||
|
||||
namespace ash {
|
||||
|
||||
class CoralItemRemover;
|
||||
@ -55,6 +57,8 @@ class ASH_EXPORT BirchCoralProvider : public BirchDataProvider,
|
||||
|
||||
static BirchCoralProvider* Get();
|
||||
|
||||
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
|
||||
|
||||
// Gets a group reference with given group ID. This operation will not remove
|
||||
// the group from the `response_`.
|
||||
const coral::mojom::GroupPtr& GetGroupById(const base::Token& group_id) const;
|
||||
@ -78,6 +82,9 @@ class ASH_EXPORT BirchCoralProvider : public BirchDataProvider,
|
||||
void AddObserver(Observer* observer);
|
||||
void RemoveObserver(Observer* observer);
|
||||
|
||||
// Gets if the primary user meets GenAI's age and location requirement.
|
||||
bool GetGenAIAvailability();
|
||||
|
||||
// BirchDataProvider:
|
||||
void RequestBirchDataFetch() override;
|
||||
|
||||
@ -91,6 +98,7 @@ class ASH_EXPORT BirchCoralProvider : public BirchDataProvider,
|
||||
|
||||
// SessionObserver:
|
||||
void OnSessionStateChanged(session_manager::SessionState state) override;
|
||||
void OnActiveUserSessionChanged(const AccountId& account_id) override;
|
||||
|
||||
// aura::WindowObserver:
|
||||
void OnWindowDestroyed(aura::Window* window) override;
|
||||
@ -143,8 +151,6 @@ class ASH_EXPORT BirchCoralProvider : public BirchDataProvider,
|
||||
// Sends a request to the coral backend to cache the embedding for `tab_item`.
|
||||
void CacheTabEmbedding(TabClusterUIItem* tab_item);
|
||||
|
||||
void HandleEmbeddingResult(bool success);
|
||||
|
||||
// Observes all the valid app and browser windows associated with `response_`.
|
||||
void ObserveAllWindowsInResponse();
|
||||
|
||||
@ -161,12 +167,21 @@ class ASH_EXPORT BirchCoralProvider : public BirchDataProvider,
|
||||
// Resets raw pointers and window observations when exiting Overview mode.
|
||||
void Reset();
|
||||
|
||||
// GenAI age availability inquiry callback.
|
||||
void OnGenAIAgeAvailabilityReceived(bool allow);
|
||||
|
||||
// The request sent to the coral backend.
|
||||
CoralRequest request_;
|
||||
|
||||
// Timestamp for when post login coral response expires.
|
||||
base::TimeTicks post_login_response_expiration_timestamp_;
|
||||
|
||||
// Indicates if primary user's age availability checked.
|
||||
bool is_gen_ai_age_availability_checked_ = false;
|
||||
|
||||
// Indicates if primary user's location is allowed by GenAI.
|
||||
std::optional<bool> is_gen_ai_location_allow_;
|
||||
|
||||
// Response generated by the coral backend.
|
||||
std::unique_ptr<CoralResponse> response_;
|
||||
|
||||
|
@ -2624,6 +2624,10 @@ inline constexpr char kClassManagementToolsNavRuleSetting[] =
|
||||
inline constexpr char kClassManagementToolsCaptionEnablementSetting[] =
|
||||
"ash.class_management_tools.caption_enablement_setting";
|
||||
|
||||
// A boolean pref indicating whether age requirement met for GenAI access for
|
||||
// Coral.
|
||||
inline constexpr char kCoralGenAIAgeAllowed[] = "ash.coral.gen_ai_age_allowed";
|
||||
|
||||
// A boolean pref that holds whether the user dismissed the extended updates
|
||||
// notification.
|
||||
inline constexpr char kExtendedUpdatesNotificationDismissed[] =
|
||||
|
@ -15,6 +15,8 @@ namespace ash {
|
||||
// `CoralClient` in chrome/ for browser operations.
|
||||
class ASH_PUBLIC_EXPORT CoralDelegate {
|
||||
public:
|
||||
using GenAIInquiryCallback = base::OnceCallback<void(bool)>;
|
||||
|
||||
virtual ~CoralDelegate() = default;
|
||||
|
||||
// Creates up to one browser with tabs from `group`. Launches the apps given
|
||||
@ -38,11 +40,18 @@ class ASH_PUBLIC_EXPORT CoralDelegate {
|
||||
const std::string& group_description,
|
||||
ScannerDelegate::SendFeedbackCallback send_feedback_callback) = 0;
|
||||
|
||||
// Check whether the current profile is not under age / location restrictions
|
||||
// for Generative AI. It is not guaranteed that calling this multiple times in
|
||||
// the same user session would return the same result, but in general the
|
||||
// result is OK to be persisted for the whole session.
|
||||
virtual bool CanUseGenerativeAiForCurrentProfile() = 0;
|
||||
// Checks whether the current profile is not under age restriction for
|
||||
// Generative AI. It is not guaranteed that calling this multiple times in the
|
||||
// same user session would return the same result, but in general the result
|
||||
// is OK to be persisted for the whole session.The `callback` will be dropped
|
||||
// when there is a pending callback.
|
||||
virtual void CheckGenAIAgeAvailability(GenAIInquiryCallback callback) = 0;
|
||||
|
||||
// Checks whether the current profile is not under location restriction for
|
||||
// Generative AI. It is not guaranteed that calling this multiple times in the
|
||||
// same user session would return the same result, but in general the result
|
||||
// is OK to be persisted for the whole session.
|
||||
virtual bool GetGenAILocationAvailability() = 0;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -24,7 +24,12 @@ void TestCoralDelegate::OpenFeedbackDialog(
|
||||
const std::string& group_description,
|
||||
ScannerDelegate::SendFeedbackCallback send_feedback_callback) {}
|
||||
|
||||
bool TestCoralDelegate::CanUseGenerativeAiForCurrentProfile() {
|
||||
void TestCoralDelegate::CheckGenAIAgeAvailability(
|
||||
GenAIInquiryCallback callback) {
|
||||
std::move(callback).Run(true);
|
||||
}
|
||||
|
||||
bool TestCoralDelegate::GetGenAILocationAvailability() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,8 @@ class TestCoralDelegate : public CoralDelegate {
|
||||
void OpenFeedbackDialog(
|
||||
const std::string& group_description,
|
||||
ScannerDelegate::SendFeedbackCallback send_feedback_callback) override;
|
||||
bool CanUseGenerativeAiForCurrentProfile() override;
|
||||
void CheckGenAIAgeAvailability(GenAIInquiryCallback callback) override;
|
||||
bool GetGenAILocationAvailability() override;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -157,12 +157,10 @@ void CoralController::GenerateContentGroups(
|
||||
std::move(callback), base::TimeTicks::Now()));
|
||||
}
|
||||
|
||||
void CoralController::CacheEmbeddings(const CoralRequest& request,
|
||||
base::OnceCallback<void(bool)> callback) {
|
||||
void CoralController::CacheEmbeddings(const CoralRequest& request) {
|
||||
CoralProcessor* coral_processor = EnsureCoralProcessor();
|
||||
if (!coral_processor) {
|
||||
LOG(ERROR) << "Failed to connect to coral processor.";
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -176,7 +174,7 @@ void CoralController::CacheEmbeddings(const CoralRequest& request,
|
||||
coral_processor->CacheEmbeddings(
|
||||
std::move(cache_embeddings_request),
|
||||
base::BindOnce(&CoralController::HandleCacheEmbeddingsResult,
|
||||
weak_factory_.GetWeakPtr(), std::move(callback)));
|
||||
weak_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
void CoralController::OpenNewDeskWithGroup(CoralResponse::Group group,
|
||||
@ -342,15 +340,12 @@ void CoralController::HandleGroupResult(CoralSource source,
|
||||
}
|
||||
|
||||
void CoralController::HandleCacheEmbeddingsResult(
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
coral::mojom::CacheEmbeddingsResultPtr result) {
|
||||
if (result->is_error()) {
|
||||
LOG(ERROR) << "Coral cache embeddings request failed with CoralError code: "
|
||||
<< static_cast<int>(result->get_error());
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
std::move(callback).Run(true);
|
||||
}
|
||||
|
||||
void CoralController::OnTemplateCreated(
|
||||
|
@ -115,9 +115,7 @@ class ASH_EXPORT CoralController {
|
||||
mojo::PendingRemote<coral::mojom::TitleObserver> title_observer,
|
||||
CoralResponseCallback callback);
|
||||
|
||||
// Callback returns whether the request was successful.
|
||||
void CacheEmbeddings(const CoralRequest& request,
|
||||
base::OnceCallback<void(bool)> callback);
|
||||
void CacheEmbeddings(const CoralRequest& request);
|
||||
|
||||
// Creates a new desk for the content group from `source_desk`.
|
||||
void OpenNewDeskWithGroup(CoralResponse::Group group,
|
||||
@ -142,12 +140,8 @@ class ASH_EXPORT CoralController {
|
||||
const base::TimeTicks& request_time,
|
||||
coral::mojom::GroupResultPtr result);
|
||||
|
||||
// Used as the callback of mojom::CoralProcessor::CacheEmbeddings. `callback`
|
||||
// is the callback passed from `CoralController::CacheEmbeddings`, which
|
||||
// should be triggered with a bool indicating whether the CacheEmbeddings
|
||||
// operation was successful.
|
||||
// Used as the callback of mojom::CoralProcessor::CacheEmbeddings.
|
||||
void HandleCacheEmbeddingsResult(
|
||||
base::OnceCallback<void(bool)> callback,
|
||||
coral::mojom::CacheEmbeddingsResultPtr result);
|
||||
|
||||
// Callback that is run when we call
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "ash/wm/overview/birch/birch_bar_context_menu_model.h"
|
||||
|
||||
#include "ash/birch/birch_coral_provider.h"
|
||||
#include "ash/birch/coral_util.h"
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
@ -49,7 +50,9 @@ BirchBarContextMenuModel::BirchBarContextMenuModel(
|
||||
AddSeparator(ui::MenuSeparatorType::NORMAL_SEPARATOR);
|
||||
|
||||
if (features::IsCoralFeatureEnabled()) {
|
||||
bool coral_enabled = coral_util::IsCoralAllowedByPolicy(GetPrefService());
|
||||
bool coral_enabled =
|
||||
coral_util::IsCoralAllowedByPolicy(GetPrefService()) &&
|
||||
BirchCoralProvider::Get()->GetGenAIAvailability();
|
||||
AddItem(base::to_underlying(CommandId::kCoralSuggestions),
|
||||
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_CORAL_BAR_MENU_ITEM));
|
||||
auto coral_index = GetIndexOfCommandId(
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "ash/birch/coral_util.h"
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
#include "ash/constants/ash_switches.h"
|
||||
#include "ash/session/session_controller_impl.h"
|
||||
#include "ash/shell.h"
|
||||
#include "ash/webui/system_apps/public/system_web_app_type.h"
|
||||
@ -47,6 +48,11 @@ class BirchCoralProviderTest : public extensions::PlatformAppBrowserTest {
|
||||
extensions::PlatformAppBrowserTest::SetUpOnMainThread();
|
||||
}
|
||||
|
||||
void SetUpCommandLine(base::CommandLine* command_line) override {
|
||||
extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
|
||||
command_line->AppendSwitch(switches::kForceBirchFakeCoralBackend);
|
||||
}
|
||||
|
||||
protected:
|
||||
BirchCoralProvider* GetCoralProvider() const {
|
||||
return static_cast<BirchCoralProvider*>(
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "chromeos/ui/wm/desks/desks_helper.h"
|
||||
#include "components/app_constants/constants.h"
|
||||
#include "components/app_restore/restore_data.h"
|
||||
#include "components/signin/public/identity_manager/identity_manager.h"
|
||||
#include "components/user_manager/user_manager.h"
|
||||
#include "components/variations/service/variations_service.h"
|
||||
#include "ui/display/display.h"
|
||||
@ -31,6 +30,7 @@
|
||||
namespace {
|
||||
|
||||
constexpr base::TimeDelta kClearLaunchDataDuration = base::Seconds(20);
|
||||
constexpr base::TimeDelta kGenAIInquiryTimeout = base::Seconds(10);
|
||||
|
||||
// Returns the first `AppRestoreData` in `restore_data` associated with
|
||||
// `app_id`. If one is found, the also `out_window_id` will have the window id
|
||||
@ -267,28 +267,76 @@ void CoralDelegateImpl::OpenFeedbackDialog(
|
||||
dialog->ShowSystemDialogForBrowserContext(GetActiveUserBrowserContext());
|
||||
}
|
||||
|
||||
bool CoralDelegateImpl::CanUseGenerativeAiForCurrentProfile() {
|
||||
void CoralDelegateImpl::CheckGenAIAgeAvailability(
|
||||
GenAIInquiryCallback callback) {
|
||||
// Skip if there is a pending callback.
|
||||
if (gen_ai_age_inquiry_callback_) {
|
||||
return;
|
||||
}
|
||||
// Check age restriction using account capabilities.
|
||||
Profile* profile = GetActiveUserProfile();
|
||||
if (!profile) {
|
||||
return false;
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
auto* identity_manager = IdentityManagerFactory::GetForProfile(profile);
|
||||
if (identity_manager == nullptr) {
|
||||
return false;
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
const auto account_id =
|
||||
identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kSignin);
|
||||
if (account_id.empty()) {
|
||||
return false;
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the the token is not ready, wait until the tokens are loaded.
|
||||
if (!identity_manager->AreRefreshTokensLoaded()) {
|
||||
identity_manager_observation_.Observe(identity_manager);
|
||||
gen_ai_age_inquiry_callback_ = std::move(callback);
|
||||
gen_ai_age_inquiry_timeout_.Start(
|
||||
FROM_HERE, kGenAIInquiryTimeout,
|
||||
base::BindOnce(&CoralDelegateImpl::HandleGenerativeAiInquiryTimeout,
|
||||
base::Unretained(this)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!identity_manager->HasAccountWithRefreshToken(account_id)) {
|
||||
std::move(callback).Run(false);
|
||||
return;
|
||||
}
|
||||
const AccountInfo extended_account_info =
|
||||
identity_manager->FindExtendedAccountInfoByAccountId(account_id);
|
||||
if (extended_account_info.capabilities.can_use_chromeos_generative_ai() !=
|
||||
signin::Tribool::kTrue) {
|
||||
return false;
|
||||
}
|
||||
std::move(callback).Run(
|
||||
extended_account_info.capabilities.can_use_chromeos_generative_ai() ==
|
||||
signin::Tribool::kTrue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check location restrictions.
|
||||
bool CoralDelegateImpl::GetGenAILocationAvailability() {
|
||||
return ash::IsGenerativeAiAllowedForCountry(GetCountryCode());
|
||||
}
|
||||
|
||||
void CoralDelegateImpl::OnIdentityManagerShutdown(
|
||||
signin::IdentityManager* identity_manager) {
|
||||
gen_ai_age_inquiry_timeout_.Stop();
|
||||
gen_ai_age_inquiry_callback_.Reset();
|
||||
identity_manager_observation_.Reset();
|
||||
}
|
||||
|
||||
void CoralDelegateImpl::OnRefreshTokensLoaded() {
|
||||
if (gen_ai_age_inquiry_callback_) {
|
||||
if (gen_ai_age_inquiry_timeout_.IsRunning()) {
|
||||
gen_ai_age_inquiry_timeout_.Stop();
|
||||
}
|
||||
identity_manager_observation_.Reset();
|
||||
// Re-run the check.
|
||||
CheckGenAIAgeAvailability(std::move(gen_ai_age_inquiry_callback_));
|
||||
}
|
||||
}
|
||||
|
||||
void CoralDelegateImpl::HandleGenerativeAiInquiryTimeout() {
|
||||
identity_manager_observation_.Reset();
|
||||
std::move(gen_ai_age_inquiry_callback_).Run(false);
|
||||
}
|
||||
|
@ -6,10 +6,14 @@
|
||||
#define CHROME_BROWSER_UI_ASH_WM_CORAL_DELEGATE_IMPL_H_
|
||||
|
||||
#include "ash/public/cpp/coral_delegate.h"
|
||||
#include "base/scoped_observation.h"
|
||||
#include "base/timer/timer.h"
|
||||
#include "components/signin/public/identity_manager/identity_manager.h"
|
||||
|
||||
class DesksTemplatesAppLaunchHandler;
|
||||
|
||||
class CoralDelegateImpl : public ash::CoralDelegate {
|
||||
class CoralDelegateImpl : public ash::CoralDelegate,
|
||||
public signin::IdentityManager::Observer {
|
||||
public:
|
||||
CoralDelegateImpl();
|
||||
CoralDelegateImpl(const CoralDelegateImpl&) = delete;
|
||||
@ -26,12 +30,28 @@ class CoralDelegateImpl : public ash::CoralDelegate {
|
||||
void OpenFeedbackDialog(const std::string& group_description,
|
||||
ash::ScannerDelegate::SendFeedbackCallback
|
||||
send_feedback_callback) override;
|
||||
bool CanUseGenerativeAiForCurrentProfile() override;
|
||||
void CheckGenAIAgeAvailability(GenAIInquiryCallback callback) override;
|
||||
bool GetGenAILocationAvailability() override;
|
||||
|
||||
// signin::IdentityManager::Observer:
|
||||
void OnIdentityManagerShutdown(
|
||||
signin::IdentityManager* identity_manager) override;
|
||||
void OnRefreshTokensLoaded() override;
|
||||
|
||||
private:
|
||||
void HandleGenerativeAiInquiryTimeout();
|
||||
|
||||
// Handles launching apps and creating browsers for post login groups.
|
||||
std::unique_ptr<DesksTemplatesAppLaunchHandler> app_launch_handler_;
|
||||
|
||||
GenAIInquiryCallback gen_ai_age_inquiry_callback_;
|
||||
|
||||
base::OneShotTimer gen_ai_age_inquiry_timeout_;
|
||||
|
||||
base::ScopedObservation<signin::IdentityManager,
|
||||
signin::IdentityManager::Observer>
|
||||
identity_manager_observation_{this};
|
||||
|
||||
base::WeakPtrFactory<CoralDelegateImpl> weak_ptr_factory_{this};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user