blob: 9bd50fe3cd397a8b1232bad7a8c86568b3ce5113 [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
8#include <update_engine/system_state.h>
9
David Zeuthenf413fe52013-04-22 14:04:39 -070010#include <update_engine/clock.h>
Jay Srinivasan55f50c22013-01-10 19:24:35 -080011#include <update_engine/connection_manager.h>
12#include <update_engine/gpio_handler.h>
Alex Deymo42432912013-07-12 20:21:15 -070013#include <update_engine/hardware.h>
Jay Srinivasan55f50c22013-01-10 19:24:35 -080014#include <update_engine/payload_state.h>
15#include <update_engine/prefs.h>
16#include <update_engine/update_attempter.h>
David Zeuthen526cb582013-08-06 12:26:18 -070017#include <update_engine/p2p_manager.h>
Jay Srinivasan55f50c22013-01-10 19:24:35 -080018
19namespace chromeos_update_engine {
20
21// A real implementation of the SystemStateInterface which is
22// used by the actual product code.
23class RealSystemState : public SystemState {
24public:
25 // Constructors and destructors.
26 RealSystemState();
27 virtual ~RealSystemState() {}
28
29 virtual bool IsOOBEComplete();
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 Zeuthenf413fe52013-04-22 14:04:39 -070040 virtual inline ClockInterface* clock() {
41 return &clock_;
42 }
43
Jay Srinivasan55f50c22013-01-10 19:24:35 -080044 virtual inline ConnectionManager* connection_manager() {
45 return &connection_manager_;
46 }
47
Alex Deymo42432912013-07-12 20:21:15 -070048 virtual inline HardwareInterface* hardware() {
49 return &hardware_;
50 }
51
Jay Srinivasan55f50c22013-01-10 19:24:35 -080052 virtual inline MetricsLibraryInterface* metrics_lib() {
53 return &metrics_lib_;
54 }
55
56 virtual inline PrefsInterface* prefs() {
57 return &prefs_;
58 }
59
Chris Sosaaa18e162013-06-20 13:20:30 -070060 virtual inline PrefsInterface* powerwash_safe_prefs() {
61 return &powerwash_safe_prefs_;
62 }
63
Jay Srinivasan55f50c22013-01-10 19:24:35 -080064 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 Srinivasanae4697c2013-03-18 17:08:08 -070076 // 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
David Zeuthen526cb582013-08-06 12:26:18 -070082 virtual inline P2PManager* p2p_manager() {
83 return p2p_manager_.get();
84 }
85
Chris Sosabe45bef2013-04-09 18:25:12 -070086 virtual inline bool system_rebooted(){
87 return system_rebooted_;
88 }
89
Jay Srinivasan55f50c22013-01-10 19:24:35 -080090 // Initializes this concrete object. Other methods should be invoked only
91 // if the object has been initialized successfully.
92 bool Initialize(bool enable_gpio);
93
94private:
David Zeuthenf413fe52013-04-22 14:04:39 -070095 // Interface for the clock.
96 Clock clock_;
97
Jay Srinivasan55f50c22013-01-10 19:24:35 -080098 // The latest device policy object from the policy provider.
99 const policy::DevicePolicy* device_policy_;
100
101 // The connection manager object that makes download
102 // decisions depending on the current type of connection.
103 ConnectionManager connection_manager_;
104
Alex Deymo42432912013-07-12 20:21:15 -0700105 // Interface for the hardware functions.
106 Hardware hardware_;
107
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800108 // The Metrics Library interface for reporting UMA stats.
109 MetricsLibrary metrics_lib_;
110
111 // Interface for persisted store.
112 Prefs prefs_;
113
Chris Sosaaa18e162013-06-20 13:20:30 -0700114 // Interface for persisted store that persists across powerwashes.
115 Prefs powerwash_safe_prefs_;
116
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800117 // All state pertaining to payload state such as
118 // response, URL, backoff states.
119 PayloadState payload_state_;
120
121 // Pointer to a GPIO handler and other needed modules (note that the order of
122 // declaration significant for destruction, as the latter depends on the
123 // former).
124 scoped_ptr<UdevInterface> udev_iface_;
125 scoped_ptr<FileDescriptor> file_descriptor_;
126 scoped_ptr<GpioHandler> gpio_handler_;
127
128 // The dbus object used to initialize the update attempter.
129 ConcreteDbusGlib dbus_;
130
131 // Pointer to the update attempter object.
132 scoped_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700133
134 // Common parameters for all Omaha requests.
135 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700136
David Zeuthen526cb582013-08-06 12:26:18 -0700137 scoped_ptr<P2PManager> p2p_manager_;
138
Chris Sosabe45bef2013-04-09 18:25:12 -0700139 // If true, this is the first instance of the update engine since the system
140 // rebooted. Important for tracking whether you are running instance of the
141 // update engine on first boot or due to a crash/restart.
142 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800143};
144
145} // namespace chromeos_update_engine
146
147#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_