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