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