Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 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 | // |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 16 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |
| 18 | #define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 19 | |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 20 | #include "update_engine/system_state.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 21 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 22 | #include <memory> |
| 23 | |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 24 | #include <metrics/metrics_library.h> |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 25 | #include <policy/device_policy.h> |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 26 | |
Alex Deymo | b8803bb | 2015-08-19 23:14:49 -0700 | [diff] [blame^] | 27 | #include "debugd/dbus-proxies.h" |
| 28 | #include "login_manager/dbus-proxies.h" |
| 29 | #include "power_manager/dbus-proxies.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 30 | #include "update_engine/clock.h" |
| 31 | #include "update_engine/connection_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 32 | #include "update_engine/hardware.h" |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 33 | #include "update_engine/p2p_manager.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 34 | #include "update_engine/payload_state.h" |
| 35 | #include "update_engine/prefs.h" |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 36 | #include "update_engine/shill_proxy.h" |
Gilad Arnold | 1b9d6ae | 2014-03-03 13:46:07 -0800 | [diff] [blame] | 37 | #include "update_engine/update_attempter.h" |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 38 | #include "update_engine/update_manager/update_manager.h" |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 39 | |
| 40 | namespace chromeos_update_engine { |
| 41 | |
| 42 | // A real implementation of the SystemStateInterface which is |
| 43 | // used by the actual product code. |
| 44 | class RealSystemState : public SystemState { |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 45 | public: |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 46 | // Constructs all system objects that do not require separate initialization; |
| 47 | // see Initialize() below for the remaining ones. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 48 | explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus); |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 49 | |
| 50 | // Initializes and sets systems objects that require an initialization |
| 51 | // separately from construction. Returns |true| on success. |
Nam T. Nguyen | 7d623eb | 2014-05-13 16:06:28 -0700 | [diff] [blame] | 52 | bool Initialize(); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 53 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 54 | inline void set_device_policy( |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 55 | const policy::DevicePolicy* device_policy) override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 56 | device_policy_ = device_policy; |
| 57 | } |
| 58 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 59 | inline const policy::DevicePolicy* device_policy() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 60 | return device_policy_; |
| 61 | } |
| 62 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 63 | inline ClockInterface* clock() override { return &clock_; } |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 64 | |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 65 | inline ConnectionManagerInterface* connection_manager() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 66 | return &connection_manager_; |
| 67 | } |
| 68 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 69 | inline HardwareInterface* hardware() override { return &hardware_; } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 70 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 71 | inline MetricsLibraryInterface* metrics_lib() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 72 | return &metrics_lib_; |
| 73 | } |
| 74 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 75 | inline PrefsInterface* prefs() override { return &prefs_; } |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 76 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 77 | inline PrefsInterface* powerwash_safe_prefs() override { |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 78 | return &powerwash_safe_prefs_; |
| 79 | } |
| 80 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 81 | inline PayloadStateInterface* payload_state() override { |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 82 | return &payload_state_; |
| 83 | } |
| 84 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 85 | inline UpdateAttempter* update_attempter() override { |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 86 | return &update_attempter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 89 | inline OmahaRequestParams* request_params() override { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | return &request_params_; |
| 91 | } |
| 92 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 93 | inline P2PManager* p2p_manager() override { return p2p_manager_.get(); } |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 94 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 95 | inline chromeos_update_manager::UpdateManager* update_manager() override { |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 96 | return update_manager_.get(); |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 99 | inline org::chromium::PowerManagerProxyInterface* power_manager_proxy() |
| 100 | override { |
| 101 | return &power_manager_proxy_; |
| 102 | } |
| 103 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 104 | inline bool system_rebooted() override { return system_rebooted_; } |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 105 | |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 106 | private: |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 107 | // Real DBus proxies using the DBus connection. |
| 108 | org::chromium::debugdProxy debugd_proxy_; |
| 109 | org::chromium::PowerManagerProxy power_manager_proxy_; |
| 110 | org::chromium::SessionManagerInterfaceProxy session_manager_proxy_; |
| 111 | ShillProxy shill_proxy_; |
| 112 | LibCrosProxy libcros_proxy_; |
| 113 | |
David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 114 | // Interface for the clock. |
| 115 | Clock clock_; |
| 116 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 117 | // The latest device policy object from the policy provider. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 118 | const policy::DevicePolicy* device_policy_{nullptr}; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 119 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 120 | // The connection manager object that makes download decisions depending on |
| 121 | // the current type of connection. |
| 122 | ConnectionManager connection_manager_{&shill_proxy_, this}; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 123 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 124 | // Interface for the hardware functions. |
| 125 | Hardware hardware_; |
| 126 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 127 | // The Metrics Library interface for reporting UMA stats. |
| 128 | MetricsLibrary metrics_lib_; |
| 129 | |
| 130 | // Interface for persisted store. |
| 131 | Prefs prefs_; |
| 132 | |
Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 133 | // Interface for persisted store that persists across powerwashes. |
| 134 | Prefs powerwash_safe_prefs_; |
| 135 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 136 | // All state pertaining to payload state such as response, URL, backoff |
| 137 | // states. |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 138 | PayloadState payload_state_; |
| 139 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 140 | // Pointer to the update attempter object. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 141 | UpdateAttempter update_attempter_{this, &libcros_proxy_, &debugd_proxy_}; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 142 | |
| 143 | // Common parameters for all Omaha requests. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 144 | OmahaRequestParams request_params_{this}; |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 145 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 146 | std::unique_ptr<P2PManager> p2p_manager_; |
David Zeuthen | 526cb58 | 2013-08-06 12:26:18 -0700 | [diff] [blame] | 147 | |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 148 | std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_; |
Alex Deymo | 94c0616 | 2014-03-21 20:34:46 -0700 | [diff] [blame] | 149 | |
Alex Deymo | c83baf6 | 2014-04-02 17:43:35 -0700 | [diff] [blame] | 150 | policy::PolicyProvider policy_provider_; |
| 151 | |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 152 | // If true, this is the first instance of the update engine since the system |
| 153 | // rebooted. Important for tracking whether you are running instance of the |
| 154 | // update engine on first boot or due to a crash/restart. |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 155 | bool system_rebooted_{false}; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace chromeos_update_engine |
| 159 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 160 | #endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |