phone_model.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ASH_COMPONENTS_PHONEHUB_PHONE_MODEL_H_
  5. #define ASH_COMPONENTS_PHONEHUB_PHONE_MODEL_H_
  6. #include "ash/components/phonehub/browser_tabs_model.h"
  7. #include "ash/components/phonehub/phone_status_model.h"
  8. #include "base/observer_list.h"
  9. #include "base/observer_list_types.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace ash {
  12. namespace phonehub {
  13. // Model representing the phone used for Phone Hub. Provides getters which
  14. // return the state of the phone when connected, or null if disconnected. Also
  15. // exposes an observer interface so that clients can be notified of changes to
  16. // the model.
  17. class PhoneModel {
  18. public:
  19. class Observer : public base::CheckedObserver {
  20. public:
  21. ~Observer() override = default;
  22. // Called when some part of the model has changed.
  23. virtual void OnModelChanged() = 0;
  24. };
  25. PhoneModel(const PhoneModel&) = delete;
  26. PhoneModel& operator=(const PhoneModel&) = delete;
  27. virtual ~PhoneModel();
  28. const absl::optional<std::u16string>& phone_name() const {
  29. return phone_name_;
  30. }
  31. const absl::optional<PhoneStatusModel>& phone_status_model() const {
  32. return phone_status_model_;
  33. }
  34. const absl::optional<BrowserTabsModel>& browser_tabs_model() const {
  35. return browser_tabs_model_;
  36. }
  37. void AddObserver(Observer* observer);
  38. void RemoveObserver(Observer* observer);
  39. protected:
  40. PhoneModel();
  41. void NotifyModelChanged();
  42. absl::optional<std::u16string> phone_name_;
  43. absl::optional<PhoneStatusModel> phone_status_model_;
  44. absl::optional<BrowserTabsModel> browser_tabs_model_;
  45. private:
  46. base::ObserverList<Observer> observer_list_;
  47. };
  48. } // namespace phonehub
  49. } // namespace ash
  50. #endif // ASH_COMPONENTS_PHONEHUB_PHONE_MODEL_H_