| 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 |  | 
|  | 8 | #include <update_engine/system_state.h> | 
|  | 9 |  | 
| David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 10 | #include <update_engine/clock.h> | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 11 | #include <update_engine/connection_manager.h> | 
|  | 12 | #include <update_engine/gpio_handler.h> | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 13 | #include <update_engine/hardware.h> | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 14 | #include <update_engine/payload_state.h> | 
|  | 15 | #include <update_engine/prefs.h> | 
|  | 16 | #include <update_engine/update_attempter.h> | 
|  | 17 |  | 
|  | 18 | namespace chromeos_update_engine { | 
|  | 19 |  | 
|  | 20 | // A real implementation of the SystemStateInterface which is | 
|  | 21 | // used by the actual product code. | 
|  | 22 | class RealSystemState : public SystemState { | 
|  | 23 | public: | 
|  | 24 | // Constructors and destructors. | 
|  | 25 | RealSystemState(); | 
|  | 26 | virtual ~RealSystemState() {} | 
|  | 27 |  | 
|  | 28 | virtual bool IsOOBEComplete(); | 
| Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 29 | virtual bool IsOfficialBuild(); | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 30 |  | 
|  | 31 | virtual inline void set_device_policy( | 
|  | 32 | const policy::DevicePolicy* device_policy) { | 
|  | 33 | device_policy_ = device_policy; | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | virtual inline const policy::DevicePolicy* device_policy() const { | 
|  | 37 | return device_policy_; | 
|  | 38 | } | 
|  | 39 |  | 
| David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 40 | virtual inline ClockInterface* clock() { | 
|  | 41 | return &clock_; | 
|  | 42 | } | 
|  | 43 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 44 | virtual inline ConnectionManager* connection_manager() { | 
|  | 45 | return &connection_manager_; | 
|  | 46 | } | 
|  | 47 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 48 | virtual inline HardwareInterface* hardware() { | 
|  | 49 | return &hardware_; | 
|  | 50 | } | 
|  | 51 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 52 | virtual inline MetricsLibraryInterface* metrics_lib() { | 
|  | 53 | return &metrics_lib_; | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | virtual inline PrefsInterface* prefs() { | 
|  | 57 | return &prefs_; | 
|  | 58 | } | 
|  | 59 |  | 
| Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 60 | virtual inline PrefsInterface* powerwash_safe_prefs() { | 
|  | 61 | return &powerwash_safe_prefs_; | 
|  | 62 | } | 
|  | 63 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 64 | virtual inline PayloadStateInterface* payload_state() { | 
|  | 65 | return &payload_state_; | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | virtual inline GpioHandler* gpio_handler() const { | 
|  | 69 | return gpio_handler_.get(); | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | virtual inline UpdateAttempter* update_attempter() { | 
|  | 73 | return update_attempter_.get(); | 
|  | 74 | } | 
|  | 75 |  | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 76 | // Returns a pointer to the object that stores the parameters that are | 
|  | 77 | // common to all Omaha requests. | 
|  | 78 | virtual inline OmahaRequestParams* request_params() { | 
|  | 79 | return &request_params_; | 
|  | 80 | } | 
|  | 81 |  | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 82 | virtual inline bool system_rebooted(){ | 
|  | 83 | return system_rebooted_; | 
|  | 84 | } | 
|  | 85 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 86 | // Initializes this concrete object. Other methods should be invoked only | 
|  | 87 | // if the object has been initialized successfully. | 
|  | 88 | bool Initialize(bool enable_gpio); | 
|  | 89 |  | 
|  | 90 | private: | 
| David Zeuthen | f413fe5 | 2013-04-22 14:04:39 -0700 | [diff] [blame] | 91 | // Interface for the clock. | 
|  | 92 | Clock clock_; | 
|  | 93 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 94 | // The latest device policy object from the policy provider. | 
|  | 95 | const policy::DevicePolicy* device_policy_; | 
|  | 96 |  | 
|  | 97 | // The connection manager object that makes download | 
|  | 98 | // decisions depending on the current type of connection. | 
|  | 99 | ConnectionManager connection_manager_; | 
|  | 100 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 101 | // Interface for the hardware functions. | 
|  | 102 | Hardware hardware_; | 
|  | 103 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 104 | // The Metrics Library interface for reporting UMA stats. | 
|  | 105 | MetricsLibrary metrics_lib_; | 
|  | 106 |  | 
|  | 107 | // Interface for persisted store. | 
|  | 108 | Prefs prefs_; | 
|  | 109 |  | 
| Chris Sosa | aa18e16 | 2013-06-20 13:20:30 -0700 | [diff] [blame] | 110 | // Interface for persisted store that persists across powerwashes. | 
|  | 111 | Prefs powerwash_safe_prefs_; | 
|  | 112 |  | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 113 | // All state pertaining to payload state such as | 
|  | 114 | // response, URL, backoff states. | 
|  | 115 | PayloadState payload_state_; | 
|  | 116 |  | 
|  | 117 | // Pointer to a GPIO handler and other needed modules (note that the order of | 
|  | 118 | // declaration significant for destruction, as the latter depends on the | 
|  | 119 | // former). | 
|  | 120 | scoped_ptr<UdevInterface> udev_iface_; | 
|  | 121 | scoped_ptr<FileDescriptor> file_descriptor_; | 
|  | 122 | scoped_ptr<GpioHandler> gpio_handler_; | 
|  | 123 |  | 
|  | 124 | // The dbus object used to initialize the update attempter. | 
|  | 125 | ConcreteDbusGlib dbus_; | 
|  | 126 |  | 
|  | 127 | // Pointer to the update attempter object. | 
|  | 128 | scoped_ptr<UpdateAttempter> update_attempter_; | 
| Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | // Common parameters for all Omaha requests. | 
|  | 131 | OmahaRequestParams request_params_; | 
| Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame] | 132 |  | 
|  | 133 | // If true, this is the first instance of the update engine since the system | 
|  | 134 | // rebooted. Important for tracking whether you are running instance of the | 
|  | 135 | // update engine on first boot or due to a crash/restart. | 
|  | 136 | bool system_rebooted_; | 
| Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 137 | }; | 
|  | 138 |  | 
|  | 139 | }  // namespace chromeos_update_engine | 
|  | 140 |  | 
|  | 141 | #endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_ |