Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 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_REAL_SYSTEM_STATE_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |
| 7 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 8 | #include "update_engine/system_state.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 9 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 10 | #include "update_engine/clock.h" |
| 11 | #include "update_engine/connection_manager.h" |
| 12 | #include "update_engine/gpio_handler.h" |
| 13 | #include "update_engine/hardware.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 14 | #include "update_engine/p2p_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 15 | #include "update_engine/payload_state.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 16 | #include "update_engine/policy_manager/policy_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 17 | #include "update_engine/prefs.h" |
| 18 | #include "update_engine/real_dbus_wrapper.h" |
| 19 | #include "update_engine/update_attempter.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 20 | |
| 21 | namespace chromeos_update_engine { |
| 22 | |
| 23 | // A real implementation of the SystemStateInterface which is |
| 24 | // used by the actual product code. |
| 25 | class RealSystemState : public SystemState { |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 26 | public: |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 27 | // Constructors and destructors. |
| 28 | RealSystemState(); |
| 29 | virtual ~RealSystemState() {} |
| 30 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 31 | virtual bool IsOOBEComplete(base::Time* out_time_of_oobe); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 32 | |
| 33 | virtual inline void set_device_policy( |
| 34 | const policy::DevicePolicy* device_policy) { |
| 35 | device_policy_ = device_policy; |
| 36 | } |
| 37 | |
| 38 | virtual inline const policy::DevicePolicy* device_policy() const { |
| 39 | return device_policy_; |
| 40 | } |
| 41 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 42 | virtual inline ClockInterface* clock() { |
| 43 | return &clock_; |
| 44 | } |
| 45 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 46 | virtual inline ConnectionManager* connection_manager() { |
| 47 | return &connection_manager_; |
| 48 | } |
| 49 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 50 | virtual inline HardwareInterface* hardware() { |
| 51 | return &hardware_; |
| 52 | } |
| 53 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 54 | virtual inline MetricsLibraryInterface* metrics_lib() { |
| 55 | return &metrics_lib_; |
| 56 | } |
| 57 | |
| 58 | virtual inline PrefsInterface* prefs() { |
| 59 | return &prefs_; |
| 60 | } |
| 61 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 62 | virtual inline PrefsInterface* powerwash_safe_prefs() { |
| 63 | return &powerwash_safe_prefs_; |
| 64 | } |
| 65 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 66 | virtual inline PayloadStateInterface* payload_state() { |
| 67 | return &payload_state_; |
| 68 | } |
| 69 | |
| 70 | virtual inline GpioHandler* gpio_handler() const { |
| 71 | return gpio_handler_.get(); |
| 72 | } |
| 73 | |
| 74 | virtual inline UpdateAttempter* update_attempter() { |
| 75 | return update_attempter_.get(); |
| 76 | } |
| 77 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 78 | // Returns a pointer to the object that stores the parameters that are |
| 79 | // common to all Omaha requests. |
| 80 | virtual inline OmahaRequestParams* request_params() { |
| 81 | return &request_params_; |
| 82 | } |
| 83 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 84 | virtual inline P2PManager* p2p_manager() { |
| 85 | return p2p_manager_.get(); |
| 86 | } |
| 87 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 88 | virtual inline chromeos_policy_manager::PolicyManager* policy_manager() { |
| 89 | return &policy_manager_; |
| 90 | } |
| 91 | |
| 92 | virtual inline bool system_rebooted() { |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 93 | return system_rebooted_; |
| 94 | } |
| 95 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 96 | // Initializes this concrete object. Other methods should be invoked only |
| 97 | // if the object has been initialized successfully. |
| 98 | bool Initialize(bool enable_gpio); |
| 99 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 100 | private: |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 101 | // Interface for the clock. |
| 102 | Clock clock_; |
| 103 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 104 | // The latest device policy object from the policy provider. |
| 105 | const policy::DevicePolicy* device_policy_; |
| 106 | |
| 107 | // The connection manager object that makes download |
| 108 | // decisions depending on the current type of connection. |
| 109 | ConnectionManager connection_manager_; |
| 110 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 111 | // Interface for the hardware functions. |
| 112 | Hardware hardware_; |
| 113 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 114 | // The Metrics Library interface for reporting UMA stats. |
| 115 | MetricsLibrary metrics_lib_; |
| 116 | |
| 117 | // Interface for persisted store. |
| 118 | Prefs prefs_; |
| 119 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 120 | // Interface for persisted store that persists across powerwashes. |
| 121 | Prefs powerwash_safe_prefs_; |
| 122 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 123 | // All state pertaining to payload state such as |
| 124 | // response, URL, backoff states. |
| 125 | PayloadState payload_state_; |
| 126 | |
| 127 | // Pointer to a GPIO handler and other needed modules (note that the order of |
| 128 | // declaration significant for destruction, as the latter depends on the |
| 129 | // former). |
| 130 | scoped_ptr<UdevInterface> udev_iface_; |
| 131 | scoped_ptr<FileDescriptor> file_descriptor_; |
| 132 | scoped_ptr<GpioHandler> gpio_handler_; |
| 133 | |
| 134 | // The dbus object used to initialize the update attempter. |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 135 | RealDBusWrapper dbus_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 136 | |
| 137 | // Pointer to the update attempter object. |
| 138 | scoped_ptr<UpdateAttempter> update_attempter_; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 139 | |
| 140 | // Common parameters for all Omaha requests. |
| 141 | OmahaRequestParams request_params_; |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 142 | |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 143 | scoped_ptr<P2PManager> p2p_manager_; |
| 144 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame^] | 145 | chromeos_policy_manager::PolicyManager policy_manager_; |
| 146 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 147 | // If true, this is the first instance of the update engine since the system |
| 148 | // rebooted. Important for tracking whether you are running instance of the |
| 149 | // update engine on first boot or due to a crash/restart. |
| 150 | bool system_rebooted_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | } // namespace chromeos_update_engine |
| 154 | |
| 155 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |