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 | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 10 | #include <policy/device_policy.h> |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 11 | #include <metrics/metrics_library.h> |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 12 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 13 | #include "update_engine/clock.h" |
| 14 | #include "update_engine/connection_manager.h" |
| 15 | #include "update_engine/gpio_handler.h" |
| 16 | #include "update_engine/hardware.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 17 | #include "update_engine/p2p_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 18 | #include "update_engine/payload_state.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 19 | #include "update_engine/policy_manager/policy_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 20 | #include "update_engine/prefs.h" |
| 21 | #include "update_engine/real_dbus_wrapper.h" |
| 22 | #include "update_engine/update_attempter.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
| 26 | // A real implementation of the SystemStateInterface which is |
| 27 | // used by the actual product code. |
| 28 | class RealSystemState : public SystemState { |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 29 | public: |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 30 | // Constructs all system objects that do not require separate initialization; |
| 31 | // see Initialize() below for the remaining ones. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 32 | RealSystemState(); |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 33 | |
| 34 | // Initializes and sets systems objects that require an initialization |
| 35 | // separately from construction. Returns |true| on success. |
| 36 | bool Initialize(bool enable_gpio); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 37 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 38 | virtual inline void set_device_policy( |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 39 | const policy::DevicePolicy* device_policy) override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 40 | device_policy_ = device_policy; |
| 41 | } |
| 42 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 43 | virtual inline const policy::DevicePolicy* device_policy() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 44 | return device_policy_; |
| 45 | } |
| 46 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 47 | virtual inline ClockInterface* clock() override { |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 48 | return &clock_; |
| 49 | } |
| 50 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 51 | virtual inline ConnectionManager* connection_manager() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 52 | return &connection_manager_; |
| 53 | } |
| 54 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 55 | virtual inline HardwareInterface* hardware() override { |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 56 | return &hardware_; |
| 57 | } |
| 58 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 59 | virtual inline MetricsLibraryInterface* metrics_lib() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 60 | return &metrics_lib_; |
| 61 | } |
| 62 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 63 | virtual inline PrefsInterface* prefs() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 64 | return &prefs_; |
| 65 | } |
| 66 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 67 | virtual inline PrefsInterface* powerwash_safe_prefs() override { |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 68 | return &powerwash_safe_prefs_; |
| 69 | } |
| 70 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 71 | virtual inline PayloadStateInterface* payload_state() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 72 | return &payload_state_; |
| 73 | } |
| 74 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 75 | virtual inline GpioHandler* gpio_handler() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 76 | return gpio_handler_.get(); |
| 77 | } |
| 78 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 79 | virtual inline UpdateAttempter* update_attempter() override { |
| 80 | return &update_attempter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 83 | virtual inline OmahaRequestParams* request_params() override { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 84 | return &request_params_; |
| 85 | } |
| 86 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 87 | virtual inline P2PManager* p2p_manager() override { |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 88 | return p2p_manager_.get(); |
| 89 | } |
| 90 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 91 | virtual inline chromeos_policy_manager::PolicyManager* policy_manager() |
| 92 | override { |
Alex Deymo | 680d022 | 2014-04-24 21:00:08 -0700 | [diff] [blame] | 93 | return policy_manager_.get(); |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 96 | virtual inline bool system_rebooted() override { |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 97 | return system_rebooted_; |
| 98 | } |
| 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. |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 138 | 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 | 680d022 | 2014-04-24 21:00:08 -0700 | [diff] [blame] | 145 | scoped_ptr<chromeos_policy_manager::PolicyManager> policy_manager_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 146 | |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 147 | policy::PolicyProvider policy_provider_; |
| 148 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 149 | // If true, this is the first instance of the update engine since the system |
| 150 | // rebooted. Important for tracking whether you are running instance of the |
| 151 | // update engine on first boot or due to a crash/restart. |
| 152 | bool system_rebooted_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | } // namespace chromeos_update_engine |
| 156 | |
| 157 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |