blob: b9c0a26c6eebc2aa88fbd1eec0bcfc5590f2ac70 [file] [log] [blame]
Jay Srinivasan55f50c22013-01-10 19:24:35 -08001// 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 Arnold1b9d6ae2014-03-03 13:46:07 -08008#include "update_engine/system_state.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -08009
Gilad Arnold1f847232014-04-07 12:07:49 -070010#include <policy/device_policy.h>
11
12#include "metrics/metrics_library.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080013#include "update_engine/clock.h"
14#include "update_engine/connection_manager.h"
15#include "update_engine/gpio_handler.h"
16#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070017#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080018#include "update_engine/payload_state.h"
Alex Deymo94c06162014-03-21 20:34:46 -070019#include "update_engine/policy_manager/policy_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080020#include "update_engine/prefs.h"
21#include "update_engine/real_dbus_wrapper.h"
22#include "update_engine/update_attempter.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080023
24namespace chromeos_update_engine {
25
26// A real implementation of the SystemStateInterface which is
27// used by the actual product code.
28class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070029 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070030 // Constructs all system objects that do not require separate initialization;
31 // see Initialize() below for the remaining ones.
Jay Srinivasan55f50c22013-01-10 19:24:35 -080032 RealSystemState();
Gilad Arnold1f847232014-04-07 12:07:49 -070033
34 // Initializes and sets systems objects that require an initialization
35 // separately from construction. Returns |true| on success.
36 bool Initialize(bool enable_gpio);
Jay Srinivasan55f50c22013-01-10 19:24:35 -080037
Jay Srinivasan55f50c22013-01-10 19:24:35 -080038 virtual inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070039 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080040 device_policy_ = device_policy;
41 }
42
Gilad Arnold1f847232014-04-07 12:07:49 -070043 virtual inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080044 return device_policy_;
45 }
46
Gilad Arnold1f847232014-04-07 12:07:49 -070047 virtual inline ClockInterface* clock() override {
David Zeuthenf413fe52013-04-22 14:04:39 -070048 return &clock_;
49 }
50
Gilad Arnold1f847232014-04-07 12:07:49 -070051 virtual inline ConnectionManager* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080052 return &connection_manager_;
53 }
54
Gilad Arnold1f847232014-04-07 12:07:49 -070055 virtual inline HardwareInterface* hardware() override {
Alex Deymo42432912013-07-12 20:21:15 -070056 return &hardware_;
57 }
58
Gilad Arnold1f847232014-04-07 12:07:49 -070059 virtual inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080060 return &metrics_lib_;
61 }
62
Gilad Arnold1f847232014-04-07 12:07:49 -070063 virtual inline PrefsInterface* prefs() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080064 return &prefs_;
65 }
66
Gilad Arnold1f847232014-04-07 12:07:49 -070067 virtual inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070068 return &powerwash_safe_prefs_;
69 }
70
Gilad Arnold1f847232014-04-07 12:07:49 -070071 virtual inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080072 return &payload_state_;
73 }
74
Gilad Arnold1f847232014-04-07 12:07:49 -070075 virtual inline GpioHandler* gpio_handler() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080076 return gpio_handler_.get();
77 }
78
Gilad Arnold1f847232014-04-07 12:07:49 -070079 virtual inline UpdateAttempter* update_attempter() override {
80 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080081 }
82
Gilad Arnold1f847232014-04-07 12:07:49 -070083 virtual inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070084 return &request_params_;
85 }
86
Gilad Arnold1f847232014-04-07 12:07:49 -070087 virtual inline P2PManager* p2p_manager() override {
David Zeuthen526cb582013-08-06 12:26:18 -070088 return p2p_manager_.get();
89 }
90
Gilad Arnold1f847232014-04-07 12:07:49 -070091 virtual inline chromeos_policy_manager::PolicyManager* policy_manager()
92 override {
Alex Deymo94c06162014-03-21 20:34:46 -070093 return &policy_manager_;
94 }
95
Gilad Arnold1f847232014-04-07 12:07:49 -070096 virtual inline bool system_rebooted() override {
Chris Sosabe45bef2013-04-09 18:25:12 -070097 return system_rebooted_;
98 }
99
Alex Deymo94c06162014-03-21 20:34:46 -0700100 private:
David Zeuthenf413fe52013-04-22 14:04:39 -0700101 // Interface for the clock.
102 Clock clock_;
103
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800104 // The latest device policy object from the policy provider.
105 const policy::DevicePolicy* device_policy_;
106
107 // The connection manager object that makes download
108 // decisions depending on the current type of connection.
109 ConnectionManager connection_manager_;
110
Alex Deymo42432912013-07-12 20:21:15 -0700111 // Interface for the hardware functions.
112 Hardware hardware_;
113
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800114 // The Metrics Library interface for reporting UMA stats.
115 MetricsLibrary metrics_lib_;
116
117 // Interface for persisted store.
118 Prefs prefs_;
119
Chris Sosaaa18e162013-06-20 13:20:30 -0700120 // Interface for persisted store that persists across powerwashes.
121 Prefs powerwash_safe_prefs_;
122
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800123 // All state pertaining to payload state such as
124 // response, URL, backoff states.
125 PayloadState payload_state_;
126
127 // Pointer to a GPIO handler and other needed modules (note that the order of
128 // declaration significant for destruction, as the latter depends on the
129 // former).
130 scoped_ptr<UdevInterface> udev_iface_;
131 scoped_ptr<FileDescriptor> file_descriptor_;
132 scoped_ptr<GpioHandler> gpio_handler_;
133
134 // The dbus object used to initialize the update attempter.
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800135 RealDBusWrapper dbus_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800136
137 // Pointer to the update attempter object.
Gilad Arnold1f847232014-04-07 12:07:49 -0700138 UpdateAttempter update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700139
140 // Common parameters for all Omaha requests.
141 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700142
David Zeuthen526cb582013-08-06 12:26:18 -0700143 scoped_ptr<P2PManager> p2p_manager_;
144
Alex Deymo94c06162014-03-21 20:34:46 -0700145 chromeos_policy_manager::PolicyManager policy_manager_;
146
Chris Sosabe45bef2013-04-09 18:25:12 -0700147 // If true, this is the first instance of the update engine since the system
148 // rebooted. Important for tracking whether you are running instance of the
149 // update engine on first boot or due to a crash/restart.
150 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800151};
152
153} // namespace chromeos_update_engine
154
155#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_