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