David Bokan | 709ff8a | 2024-12-30 18:55:01 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/glic/glic_profile_configuration.h" |
| 6 | |
| 7 | #include "base/values.h" |
| 8 | #include "chrome/browser/browser_process.h" |
| 9 | #include "chrome/browser/glic/glic_pref_names.h" |
David Bokan | 7412e91 | 2025-01-10 19:07:32 | [diff] [blame^] | 10 | #include "chrome/browser/glic/launcher/glic_background_mode_manager.h" |
David Bokan | 709ff8a | 2024-12-30 18:55:01 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile.h" |
| 12 | #include "components/prefs/pref_registry_simple.h" |
| 13 | #include "components/prefs/pref_service.h" |
| 14 | #include "ui/base/accelerators/accelerator.h" |
| 15 | #include "ui/events/event_constants.h" |
| 16 | #include "ui/events/keycodes/keyboard_codes.h" |
| 17 | |
| 18 | namespace glic { |
| 19 | |
David Bokan | c5e12cc | 2025-01-10 16:53:05 | [diff] [blame] | 20 | GlicProfileConfiguration::GlicProfileConfiguration(Profile* profile) |
| 21 | : profile_(*profile) { |
| 22 | pref_registrar_.Init(profile_->GetPrefs()); |
| 23 | pref_registrar_.Add( |
| 24 | prefs::kGlicEnabledByPolicy, |
| 25 | base::BindRepeating(&GlicProfileConfiguration::OnEnabledByPolicyChanged, |
| 26 | base::Unretained(this))); |
| 27 | } |
| 28 | |
David Bokan | 709ff8a | 2024-12-30 18:55:01 | [diff] [blame] | 29 | GlicProfileConfiguration::~GlicProfileConfiguration() = default; |
| 30 | |
| 31 | // static |
| 32 | void GlicProfileConfiguration::RegisterProfilePrefs( |
| 33 | PrefRegistrySimple* registry) { |
David Bokan | c5e12cc | 2025-01-10 16:53:05 | [diff] [blame] | 34 | registry->RegisterBooleanPref(prefs::kGlicEnabledByPolicy, true); |
David Bokan | 709ff8a | 2024-12-30 18:55:01 | [diff] [blame] | 35 | registry->RegisterBooleanPref(prefs::kGlicMicrophoneEnabled, false); |
| 36 | registry->RegisterBooleanPref(prefs::kGlicGeolocationEnabled, false); |
| 37 | registry->RegisterBooleanPref(prefs::kGlicTabContextEnabled, false); |
| 38 | } |
| 39 | |
David Bokan | c5e12cc | 2025-01-10 16:53:05 | [diff] [blame] | 40 | bool GlicProfileConfiguration::IsEnabledByPolicy() const { |
| 41 | return profile_->GetPrefs()->GetBoolean(prefs::kGlicEnabledByPolicy); |
| 42 | } |
| 43 | |
| 44 | void GlicProfileConfiguration::OnEnabledByPolicyChanged() { |
| 45 | // TODO(crbug.com/382722218): Update UI in each window to remove/add Glic |
| 46 | // button. |
David Bokan | 7412e91 | 2025-01-10 19:07:32 | [diff] [blame^] | 47 | GlicBackgroundModeManager::GetInstance()->OnPolicyChanged(); |
David Bokan | c5e12cc | 2025-01-10 16:53:05 | [diff] [blame] | 48 | } |
| 49 | |
David Bokan | 709ff8a | 2024-12-30 18:55:01 | [diff] [blame] | 50 | } // namespace glic |