update_model.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2018 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_SYSTEM_MODEL_UPDATE_MODEL_H_
  5. #define ASH_SYSTEM_MODEL_UPDATE_MODEL_H_
  6. #include "ash/public/cpp/update_types.h"
  7. #include "base/observer_list.h"
  8. namespace ash {
  9. class UpdateObserver {
  10. public:
  11. virtual ~UpdateObserver() {}
  12. virtual void OnUpdateAvailable() = 0;
  13. };
  14. // Model to store system update availability.
  15. class UpdateModel {
  16. public:
  17. UpdateModel();
  18. UpdateModel(const UpdateModel&) = delete;
  19. UpdateModel& operator=(const UpdateModel&) = delete;
  20. ~UpdateModel();
  21. void AddObserver(UpdateObserver* observer);
  22. void RemoveObserver(UpdateObserver* observer);
  23. // Stores the state that a software update is available. The state persists
  24. // until reboot. Based on |severity|, |factory_reset_required| and |rollback|,
  25. // the observer views can indicate the severity of the update to users by
  26. // changing the icon, color, and tooltip.
  27. void SetUpdateAvailable(UpdateSeverity severity,
  28. bool factory_reset_required,
  29. bool rollback,
  30. UpdateType update_type);
  31. // Stores the state of the notification according to the RelaunchNotification
  32. // policy. State persists until reboot or another call to this function.
  33. void SetRelaunchNotificationState(
  34. const RelaunchNotificationState& relaunch_notification_state);
  35. // If |available| is true, a software update is available but user's agreement
  36. // is required as current connection is cellular. If |available| is false, the
  37. // user's one time permission on update over cellular connection has been
  38. // granted.
  39. void SetUpdateOverCellularAvailable(bool available);
  40. // If `deferred` is true, an update is downloaded but deferred.
  41. void SetUpdateDeferred(DeferredUpdateState state);
  42. UpdateSeverity GetSeverity() const;
  43. // Sets |update_required_| back to false.
  44. void ResetUpdateAvailable();
  45. bool update_required() const { return update_required_; }
  46. bool factory_reset_required() const { return factory_reset_required_; }
  47. bool rollback() const { return rollback_; }
  48. UpdateType update_type() const { return update_type_; }
  49. const RelaunchNotificationState& relaunch_notification_state() const {
  50. return relaunch_notification_state_;
  51. }
  52. bool update_over_cellular_available() const {
  53. return update_over_cellular_available_;
  54. }
  55. DeferredUpdateState update_deferred() const { return update_deferred_; }
  56. private:
  57. void NotifyUpdateAvailable();
  58. bool update_required_ = false;
  59. UpdateSeverity severity_ = UpdateSeverity::kNone;
  60. bool factory_reset_required_ = false;
  61. bool rollback_ = false;
  62. UpdateType update_type_ = UpdateType::kSystem;
  63. RelaunchNotificationState relaunch_notification_state_;
  64. bool update_over_cellular_available_ = false;
  65. DeferredUpdateState update_deferred_ = DeferredUpdateState::kNone;
  66. base::ObserverList<UpdateObserver>::Unchecked observers_;
  67. };
  68. } // namespace ash
  69. #endif // ASH_SYSTEM_MODEL_UPDATE_MODEL_H_