blob: 7c411f8d9016559cce6fc12053ada31603f01741 [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 Arnold1b9d6ae2014-03-03 13:46:07 -080010#include "update_engine/clock.h"
11#include "update_engine/connection_manager.h"
12#include "update_engine/gpio_handler.h"
13#include "update_engine/hardware.h"
14#include "update_engine/payload_state.h"
15#include "update_engine/prefs.h"
16#include "update_engine/real_dbus_wrapper.h"
17#include "update_engine/update_attempter.h"
18#include "update_engine/p2p_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080019
20namespace chromeos_update_engine {
21
22// A real implementation of the SystemStateInterface which is
23// used by the actual product code.
24class RealSystemState : public SystemState {
25public:
26 // Constructors and destructors.
27 RealSystemState();
28 virtual ~RealSystemState() {}
29
David Zeuthen639aa362014-02-03 16:23:44 -080030 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe);
Jay Srinivasan55f50c22013-01-10 19:24:35 -080031
32 virtual inline void set_device_policy(
33 const policy::DevicePolicy* device_policy) {
34 device_policy_ = device_policy;
35 }
36
37 virtual inline const policy::DevicePolicy* device_policy() const {
38 return device_policy_;
39 }
40
David Zeuthenf413fe52013-04-22 14:04:39 -070041 virtual inline ClockInterface* clock() {
42 return &clock_;
43 }
44
Jay Srinivasan55f50c22013-01-10 19:24:35 -080045 virtual inline ConnectionManager* connection_manager() {
46 return &connection_manager_;
47 }
48
Alex Deymo42432912013-07-12 20:21:15 -070049 virtual inline HardwareInterface* hardware() {
50 return &hardware_;
51 }
52
Jay Srinivasan55f50c22013-01-10 19:24:35 -080053 virtual inline MetricsLibraryInterface* metrics_lib() {
54 return &metrics_lib_;
55 }
56
57 virtual inline PrefsInterface* prefs() {
58 return &prefs_;
59 }
60
Chris Sosaaa18e162013-06-20 13:20:30 -070061 virtual inline PrefsInterface* powerwash_safe_prefs() {
62 return &powerwash_safe_prefs_;
63 }
64
Jay Srinivasan55f50c22013-01-10 19:24:35 -080065 virtual inline PayloadStateInterface* payload_state() {
66 return &payload_state_;
67 }
68
69 virtual inline GpioHandler* gpio_handler() const {
70 return gpio_handler_.get();
71 }
72
73 virtual inline UpdateAttempter* update_attempter() {
74 return update_attempter_.get();
75 }
76
Jay Srinivasanae4697c2013-03-18 17:08:08 -070077 // Returns a pointer to the object that stores the parameters that are
78 // common to all Omaha requests.
79 virtual inline OmahaRequestParams* request_params() {
80 return &request_params_;
81 }
82
David Zeuthen526cb582013-08-06 12:26:18 -070083 virtual inline P2PManager* p2p_manager() {
84 return p2p_manager_.get();
85 }
86
Chris Sosabe45bef2013-04-09 18:25:12 -070087 virtual inline bool system_rebooted(){
88 return system_rebooted_;
89 }
90
Jay Srinivasan55f50c22013-01-10 19:24:35 -080091 // Initializes this concrete object. Other methods should be invoked only
92 // if the object has been initialized successfully.
93 bool Initialize(bool enable_gpio);
94
95private:
David Zeuthenf413fe52013-04-22 14:04:39 -070096 // Interface for the clock.
97 Clock clock_;
98
Jay Srinivasan55f50c22013-01-10 19:24:35 -080099 // 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 Deymo42432912013-07-12 20:21:15 -0700106 // Interface for the hardware functions.
107 Hardware hardware_;
108
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800109 // The Metrics Library interface for reporting UMA stats.
110 MetricsLibrary metrics_lib_;
111
112 // Interface for persisted store.
113 Prefs prefs_;
114
Chris Sosaaa18e162013-06-20 13:20:30 -0700115 // Interface for persisted store that persists across powerwashes.
116 Prefs powerwash_safe_prefs_;
117
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800118 // All state pertaining to payload state such as
119 // response, URL, backoff states.
120 PayloadState payload_state_;
121
122 // Pointer to a GPIO handler and other needed modules (note that the order of
123 // declaration significant for destruction, as the latter depends on the
124 // former).
125 scoped_ptr<UdevInterface> udev_iface_;
126 scoped_ptr<FileDescriptor> file_descriptor_;
127 scoped_ptr<GpioHandler> gpio_handler_;
128
129 // The dbus object used to initialize the update attempter.
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800130 RealDBusWrapper dbus_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800131
132 // Pointer to the update attempter object.
133 scoped_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700134
135 // Common parameters for all Omaha requests.
136 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700137
David Zeuthen526cb582013-08-06 12:26:18 -0700138 scoped_ptr<P2PManager> p2p_manager_;
139
Chris Sosabe45bef2013-04-09 18:25:12 -0700140 // If true, this is the first instance of the update engine since the system
141 // rebooted. Important for tracking whether you are running instance of the
142 // update engine on first boot or due to a crash/restart.
143 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800144};
145
146} // namespace chromeos_update_engine
147
148#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_