system_state.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Copyright (C) 2012 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef UPDATE_ENGINE_SYSTEM_STATE_H_
  17. #define UPDATE_ENGINE_SYSTEM_STATE_H_
  18. namespace chromeos_update_manager {
  19. class UpdateManager;
  20. } // namespace chromeos_update_manager
  21. namespace policy {
  22. class DevicePolicy;
  23. } // namespace policy
  24. namespace chromeos_update_engine {
  25. // SystemState is the root class within the update engine. So we should avoid
  26. // any circular references in header file inclusion. Hence forward-declaring
  27. // the required classes.
  28. class BootControlInterface;
  29. class ClockInterface;
  30. class ConnectionManagerInterface;
  31. class DlcServiceInterface;
  32. class HardwareInterface;
  33. class MetricsReporterInterface;
  34. class OmahaRequestParams;
  35. class P2PManager;
  36. class PayloadStateInterface;
  37. class PowerManagerInterface;
  38. class PrefsInterface;
  39. class UpdateAttempter;
  40. // An interface to global system context, including platform resources,
  41. // the current state of the system, high-level objects whose lifetime is same
  42. // as main, system interfaces, etc.
  43. // Carved out separately so it can be mocked for unit tests.
  44. // Currently it has only one method, but we should start migrating other
  45. // methods to use this as and when needed to unit test them.
  46. // TODO(jaysri): Consider renaming this to something like GlobalContext.
  47. class SystemState {
  48. public:
  49. // Destructs this object.
  50. virtual ~SystemState() {}
  51. // Sets or gets the latest device policy.
  52. virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
  53. virtual const policy::DevicePolicy* device_policy() = 0;
  54. // Gets the interface object for the bootloader control interface.
  55. virtual BootControlInterface* boot_control() = 0;
  56. // Gets the interface object for the clock.
  57. virtual ClockInterface* clock() = 0;
  58. // Gets the connection manager object.
  59. virtual ConnectionManagerInterface* connection_manager() = 0;
  60. // Gets the hardware interface object.
  61. virtual HardwareInterface* hardware() = 0;
  62. // Gets the Metrics Library interface for reporting UMA stats.
  63. virtual MetricsReporterInterface* metrics_reporter() = 0;
  64. // Gets the interface object for persisted store.
  65. virtual PrefsInterface* prefs() = 0;
  66. // Gets the interface object for the persisted store that persists across
  67. // powerwashes. Please note that this should be used very seldomly and must
  68. // be forwards and backwards compatible as powerwash is used to go back and
  69. // forth in system versions.
  70. virtual PrefsInterface* powerwash_safe_prefs() = 0;
  71. // Gets the interface for the payload state object.
  72. virtual PayloadStateInterface* payload_state() = 0;
  73. // Returns a pointer to the update attempter object.
  74. virtual UpdateAttempter* update_attempter() = 0;
  75. // Returns a pointer to the object that stores the parameters that are
  76. // common to all Omaha requests.
  77. virtual OmahaRequestParams* request_params() = 0;
  78. // Returns a pointer to the P2PManager singleton.
  79. virtual P2PManager* p2p_manager() = 0;
  80. // Returns a pointer to the UpdateManager singleton.
  81. virtual chromeos_update_manager::UpdateManager* update_manager() = 0;
  82. // Gets the power manager object. Mocked during test.
  83. virtual PowerManagerInterface* power_manager() = 0;
  84. // If true, this is the first instance of the update engine since the system
  85. // restarted. Important for tracking whether you are running instance of the
  86. // update engine on first boot or due to a crash/restart.
  87. virtual bool system_rebooted() = 0;
  88. // Returns a pointer to the DlcServiceInterface singleton.
  89. virtual DlcServiceInterface* dlcservice() = 0;
  90. };
  91. } // namespace chromeos_update_engine
  92. #endif // UPDATE_ENGINE_SYSTEM_STATE_H_