1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_MAGIC_BOOST_MAGIC_BOOST_STATE_ASH_H_
#define CHROME_BROWSER_ASH_MAGIC_BOOST_MAGIC_BOOST_STATE_ASH_H_
#include <memory>
#include "ash/public/cpp/session/session_observer.h"
#include "ash/shell_observer.h"
#include "base/functional/callback_forward.h"
#include "base/scoped_observation.h"
#include "base/types/expected.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/components/magic_boost/public/cpp/magic_boost_state.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/signin/public/identity_manager/identity_manager.h"
namespace ash {
namespace input_method {
class EditorPanelManager;
} // namespace input_method
class SessionController;
class Shell;
// A class that holds MagicBoost related prefs and states.
class MagicBoostStateAsh : public chromeos::MagicBoostState,
public ash::SessionObserver,
public ash::ShellObserver {
public:
using InjectActiveProfileForTestingCallback =
base::RepeatingCallback<Profile*()>;
MagicBoostStateAsh();
explicit MagicBoostStateAsh(InjectActiveProfileForTestingCallback
inject_active_profile_for_testing_callback);
MagicBoostStateAsh(const MagicBoostStateAsh&) = delete;
MagicBoostStateAsh& operator=(const MagicBoostStateAsh&) = delete;
~MagicBoostStateAsh() override;
// MagicBoostState:
bool CanShowNoticeBannerForHMR() override;
int32_t AsyncIncrementHMRConsentWindowDismissCount() override;
void AsyncWriteConsentStatus(
chromeos::HMRConsentStatus consent_status) override;
void AsyncWriteHMREnabled(bool enabled) override;
void ShouldIncludeOrcaInOptIn(
base::OnceCallback<void(bool)> callback) override;
bool ShouldIncludeOrcaInOptInSync() override;
void DisableOrcaFeature() override;
void DisableLobsterSettings() override;
// Virtual for testing.
virtual void EnableOrcaFeature();
input_method::EditorPanelManager* GetEditorPanelManager();
void set_editor_panel_manager_for_test(
input_method::EditorPanelManager* editor_manager) {
editor_manager_for_test_ = editor_manager;
}
protected:
base::expected<bool, chromeos::MagicBoostState::Error>
IsMagicBoostAvailableExpected() const override;
private:
friend class MagicBoostStateAshTest;
Profile* GetActiveUserProfile();
// ash::SessionObserver:
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
// ash::ShellObserver:
void OnShellDestroying() override;
// Sets up callbacks for updates to relevant prefs for magic_boost.
void RegisterPrefChanges(PrefService* pref_service);
// Called when the related preferences are updated from the pref service.
void OnMagicBoostEnabledUpdated();
void OnHMREnabledUpdated();
void OnHMRConsentStatusUpdated();
void OnHMRConsentWindowDismissCountUpdated();
void OnRefreshTokensReady();
// Observes user profile prefs for magic_boost.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
// Use `std::unique_ptr` instead of `std::optional` as this variable holds an
// extended class of `signin::IdentityManager::Observer` class.
std::unique_ptr<signin::IdentityManager::Observer>
refresh_tokens_loaded_barrier_;
base::ScopedObservation<ash::SessionController, ash::SessionObserver>
session_observation_{this};
raw_ptr<input_method::EditorPanelManager> editor_manager_for_test_ = nullptr;
base::ScopedObservation<ash::Shell, ash::ShellObserver> shell_observation_{
this};
const InjectActiveProfileForTestingCallback
inject_active_profile_for_testing_callback_;
};
} // namespace ash
#endif // CHROME_BROWSER_ASH_MAGIC_BOOST_MAGIC_BOOST_STATE_ASH_H_
|