crosapi_pref_observer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROMEOS_LACROS_CROSAPI_PREF_OBSERVER_H_
  5. #define CHROMEOS_LACROS_CROSAPI_PREF_OBSERVER_H_
  6. #include "base/callback_forward.h"
  7. #include "base/component_export.h"
  8. #include "base/gtest_prod_util.h"
  9. #include "base/values.h"
  10. #include "chromeos/crosapi/mojom/prefs.mojom.h"
  11. #include "mojo/public/cpp/bindings/receiver.h"
  12. // Helper to simplify the crosapi::mojom::PrefObserver API.
  13. // Observes ash-chrome for changes in specified pref.
  14. class COMPONENT_EXPORT(CHROMEOS_LACROS) CrosapiPrefObserver
  15. : public crosapi::mojom::PrefObserver {
  16. public:
  17. using PrefChangedCallback = base::RepeatingCallback<void(base::Value value)>;
  18. CrosapiPrefObserver(crosapi::mojom::PrefPath path,
  19. PrefChangedCallback callback);
  20. CrosapiPrefObserver(const CrosapiPrefObserver&) = delete;
  21. CrosapiPrefObserver& operator=(const CrosapiPrefObserver&) = delete;
  22. ~CrosapiPrefObserver() override;
  23. private:
  24. FRIEND_TEST_ALL_PREFIXES(CrosapiPrefObserverLacrosBrowserTest, Basics);
  25. // crosapi::mojom::PrefObserver:
  26. void OnPrefChanged(base::Value value) override;
  27. PrefChangedCallback callback_;
  28. // Receives mojo messages from ash.
  29. mojo::Receiver<crosapi::mojom::PrefObserver> receiver_{this};
  30. };
  31. #endif // CHROMEOS_LACROS_CROSAPI_PREF_OBSERVER_H_