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