blob: 6be09242b69e0a6e35c17cadea396ec23b9d1d08 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2021 The Chromium Authors
Igor900cbc12021-10-12 17:58:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_LACROS_DEVICE_SETTINGS_LACROS_H_
6#define CHROME_BROWSER_LACROS_DEVICE_SETTINGS_LACROS_H_
7
8#include "base/memory/weak_ptr.h"
Vignesh Shenvi3fe3bf42022-08-17 18:11:249#include "base/observer_list.h"
10#include "base/observer_list_types.h"
11#include "base/sequence_checker.h"
12#include "base/thread_annotations.h"
Igor900cbc12021-10-12 17:58:2313#include "chromeos/crosapi/mojom/device_settings_service.mojom.h"
14#include "mojo/public/cpp/bindings/receiver.h"
15
16// The keeper of device settings needed for Lacros. Initializes with current
17// value at startup and receives the updates from ash when the settings are
18// changed. Lacros should use the device settings provided by this class when
19// needs to use any device settings.
20class DeviceSettingsLacros : public crosapi::mojom::DeviceSettingsObserver {
21 public:
Vignesh Shenvi3fe3bf42022-08-17 18:11:2422 // Observer that is notified on certain events like device settings updates in
23 // Ash.
24 class Observer : public base::CheckedObserver {
25 public:
26 Observer() = default;
27 Observer(const Observer&) = delete;
28 Observer& operator=(const Observer&) = delete;
29 ~Observer() override = default;
30
31 // Triggered when device settings are updated,
32 virtual void OnDeviceSettingsUpdated() {}
33 };
34
Igor900cbc12021-10-12 17:58:2335 DeviceSettingsLacros();
36 DeviceSettingsLacros(const DeviceSettingsLacros&) = delete;
37 DeviceSettingsLacros& operator=(const DeviceSettingsLacros&) = delete;
38 ~DeviceSettingsLacros() override;
39
Vignesh Shenvi3fe3bf42022-08-17 18:11:2440 // Returns device settings that were retrieved from Ash via crosapi. Needs to
41 // be accessed in a valid sequence for thread safety.
Igor900cbc12021-10-12 17:58:2342 crosapi::mojom::DeviceSettings* GetDeviceSettings();
43
44 // crosapi::mojom::DeviceSettingsObserver:
Vignesh Shenvi3fe3bf42022-08-17 18:11:2445 // Updated device settings as they are recorded in Ash. Needs to run in a
46 // valid sequence for thread safety.
Igor900cbc12021-10-12 17:58:2347 void UpdateDeviceSettings(
48 crosapi::mojom::DeviceSettingsPtr device_settings) override;
49
Vignesh Shenvi3fe3bf42022-08-17 18:11:2450 void AddObserver(Observer* observer);
51 void RemoveObserver(Observer* observer);
52
Igor900cbc12021-10-12 17:58:2353 private:
54 void Init();
55
Vignesh Shenvi3fe3bf42022-08-17 18:11:2456 SEQUENCE_CHECKER(sequence_checker_);
57
58 crosapi::mojom::DeviceSettingsPtr device_settings_
59 GUARDED_BY_CONTEXT(sequence_checker_);
60 base::ObserverList<DeviceSettingsLacros::Observer> observers_;
61
Igor900cbc12021-10-12 17:58:2362 mojo::Receiver<crosapi::mojom::DeviceSettingsObserver> receiver_{this};
63 base::WeakPtrFactory<DeviceSettingsLacros> weak_ptr_factory_{this};
64};
65
66#endif // CHROME_BROWSER_LACROS_DEVICE_SETTINGS_LACROS_H_