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
|
// Copyright 2023 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_INPUT_METHOD_EDITOR_CONSENT_STORE_H_
#define CHROME_BROWSER_ASH_INPUT_METHOD_EDITOR_CONSENT_STORE_H_
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ash/input_method/editor_consent_enums.h"
#include "chrome/browser/ash/input_method/editor_metrics_recorder.h"
#include "chromeos/ash/components/editor_menu/public/cpp/editor_consent_status.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
namespace ash::input_method {
// Manages consent status read/write from and to the user prefs.
// Each user has a separate consent status bound with their pref
// store.
class EditorConsentStore {
public:
explicit EditorConsentStore(PrefService* pref_service,
EditorMetricsRecorder* metrics_recorder);
EditorConsentStore(const EditorConsentStore&) = delete;
EditorConsentStore& operator=(const EditorConsentStore&) = delete;
~EditorConsentStore();
chromeos::editor_menu::EditorConsentStatus GetConsentStatus() const;
// Updates the consent status based on user consent action.
void ProcessConsentAction(ConsentAction consent_action);
void ProcessPromoCardAction(PromoCardAction promo_card_action);
void SetPrefService(PrefService* pref_service);
private:
void SetConsentStatus(
chromeos::editor_menu::EditorConsentStatus consent_status);
// Updates the consent status based on the change in the user prefs.
void OnUserPrefChanged();
void OverrideUserPref(bool new_pref_value);
void InitializePrefChangeRegistrar(PrefService* pref_service);
// Not owned by this class.
raw_ptr<PrefService> pref_service_;
raw_ptr<EditorMetricsRecorder> metrics_recorder_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
base::WeakPtrFactory<EditorConsentStore> weak_ptr_factory_{this};
};
} // namespace ash::input_method
#endif // CHROME_BROWSER_ASH_INPUT_METHOD_EDITOR_CONSENT_STORE_H_
|