Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS 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 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_ |
| 7 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 8 | #include "metrics/metrics_library.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 9 | #include <policy/device_policy.h> |
| 10 | #include <policy/libpolicy.h> |
| 11 | |
| 12 | #include <update_engine/connection_manager.h> |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame^] | 13 | #include <update_engine/gpio_handler.h> |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 14 | #include <update_engine/payload_state.h> |
| 15 | #include <update_engine/prefs.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
| 19 | // An interface to global system context, including platform resources, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 20 | // the current state of the system, high-level objects whose lifetime is same |
| 21 | // as main, system interfaces, etc. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 22 | // Carved out separately so it can be mocked for unit tests. |
| 23 | // Currently it has only one method, but we should start migrating other |
| 24 | // methods to use this as and when needed to unit test them. |
| 25 | // TODO (jaysri): Consider renaming this to something like GlobalContext. |
| 26 | class SystemState { |
| 27 | public: |
| 28 | // Destructs this object. |
| 29 | virtual ~SystemState() {} |
| 30 | |
| 31 | // Returns true if the OOBE process has been completed and EULA accepted. |
| 32 | // False otherwise. |
| 33 | virtual bool IsOOBEComplete() = 0; |
| 34 | |
| 35 | // Sets or gets the latest device policy. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 36 | virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0; |
| 37 | virtual const policy::DevicePolicy* device_policy() const = 0; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 38 | |
| 39 | // Gets the connection manager object. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 40 | virtual ConnectionManager* connection_manager() = 0; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 41 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 42 | // Gets the Metrics Library interface for reporting UMA stats. |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 43 | virtual MetricsLibraryInterface* metrics_lib() = 0; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 44 | |
| 45 | // Gets the interface object for persisted store. |
| 46 | virtual PrefsInterface* prefs() = 0; |
| 47 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 48 | // Gets the interface for the payload state object. |
| 49 | virtual PayloadStateInterface* payload_state() = 0; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame^] | 50 | |
| 51 | // Returns a pointer to the GPIO handler. |
| 52 | virtual GpioHandler* gpio_handler() const = 0; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | // A real implementation of the SystemStateInterface which is |
| 56 | // used by the actual product code. |
| 57 | class RealSystemState : public SystemState { |
| 58 | public: |
| 59 | // Constructors and destructors. |
| 60 | RealSystemState(); |
| 61 | virtual ~RealSystemState() {} |
| 62 | |
| 63 | virtual bool IsOOBEComplete(); |
| 64 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 65 | virtual inline void set_device_policy( |
| 66 | const policy::DevicePolicy* device_policy) { |
| 67 | device_policy_ = device_policy; |
| 68 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 69 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 70 | virtual inline const policy::DevicePolicy* device_policy() const { |
| 71 | return device_policy_; |
| 72 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 73 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 74 | virtual inline ConnectionManager* connection_manager() { |
| 75 | return &connection_manager_; |
| 76 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 77 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 78 | virtual inline MetricsLibraryInterface* metrics_lib() { |
| 79 | return &metrics_lib_; |
| 80 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 81 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 82 | virtual inline PrefsInterface* prefs() { |
| 83 | return &prefs_; |
| 84 | } |
| 85 | |
| 86 | virtual inline PayloadStateInterface* payload_state() { |
| 87 | return &payload_state_; |
| 88 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 89 | |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame^] | 90 | // Returns a pointer to the GPIO handler. |
| 91 | virtual inline GpioHandler* gpio_handler() const { |
| 92 | return gpio_handler_.get(); |
| 93 | } |
| 94 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 95 | // Initializs this concrete object. Other methods should be invoked only |
| 96 | // if the object has been initialized successfully. |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame^] | 97 | bool Initialize(bool enable_gpio); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 98 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 99 | private: |
| 100 | // The latest device policy object from the policy provider. |
| 101 | const policy::DevicePolicy* device_policy_; |
| 102 | |
| 103 | // The connection manager object that makes download |
| 104 | // decisions depending on the current type of connection. |
| 105 | ConnectionManager connection_manager_; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 106 | |
| 107 | // The Metrics Library interface for reporting UMA stats. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 108 | MetricsLibrary metrics_lib_; |
| 109 | |
| 110 | // Interface for persisted store. |
| 111 | Prefs prefs_; |
| 112 | |
| 113 | // All state pertaining to payload state such as |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame] | 114 | // response, URL, backoff states. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 115 | PayloadState payload_state_; |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame^] | 116 | |
| 117 | // Pointer to a GPIO handler and other needed modules (note that the order of |
| 118 | // declaration significant for destruction, as the latter depends on the |
| 119 | // former). |
| 120 | scoped_ptr<UdevInterface> udev_iface_; |
| 121 | scoped_ptr<FileDescriptor> file_descriptor_; |
| 122 | scoped_ptr<GpioHandler> gpio_handler_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace chromeos_update_engine |
| 126 | |
| 127 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H_ |