blob: 83f3ac1e3a64ecccf0e462be543a7f2b0c9c48cb [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();
Jay Srinivasan53173b92013-05-17 17:13:01 -070028 virtual bool IsOfficialBuild();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080029
30 virtual inline void set_device_policy(
31 const policy::DevicePolicy* device_policy) {
32 device_policy_ = device_policy;
33 }
34
35 virtual inline const policy::DevicePolicy* device_policy() const {
36 return device_policy_;
37 }
38
David Zeuthenf413fe52013-04-22 14:04:39 -070039 virtual inline ClockInterface* clock() {
40 return &clock_;
41 }
42
Jay Srinivasan55f50c22013-01-10 19:24:35 -080043 virtual inline ConnectionManager* connection_manager() {
44 return &connection_manager_;
45 }
46
47 virtual inline MetricsLibraryInterface* metrics_lib() {
48 return &metrics_lib_;
49 }
50
51 virtual inline PrefsInterface* prefs() {
52 return &prefs_;
53 }
54
55 virtual inline PayloadStateInterface* payload_state() {
56 return &payload_state_;
57 }
58
59 virtual inline GpioHandler* gpio_handler() const {
60 return gpio_handler_.get();
61 }
62
63 virtual inline UpdateAttempter* update_attempter() {
64 return update_attempter_.get();
65 }
66
Jay Srinivasanae4697c2013-03-18 17:08:08 -070067 // Returns a pointer to the object that stores the parameters that are
68 // common to all Omaha requests.
69 virtual inline OmahaRequestParams* request_params() {
70 return &request_params_;
71 }
72
Chris Sosabe45bef2013-04-09 18:25:12 -070073 virtual inline bool system_rebooted(){
74 return system_rebooted_;
75 }
76
Jay Srinivasan55f50c22013-01-10 19:24:35 -080077 // Initializes this concrete object. Other methods should be invoked only
78 // if the object has been initialized successfully.
79 bool Initialize(bool enable_gpio);
80
81private:
David Zeuthenf413fe52013-04-22 14:04:39 -070082 // Interface for the clock.
83 Clock clock_;
84
Jay Srinivasan55f50c22013-01-10 19:24:35 -080085 // The latest device policy object from the policy provider.
86 const policy::DevicePolicy* device_policy_;
87
88 // The connection manager object that makes download
89 // decisions depending on the current type of connection.
90 ConnectionManager connection_manager_;
91
92 // The Metrics Library interface for reporting UMA stats.
93 MetricsLibrary metrics_lib_;
94
95 // Interface for persisted store.
96 Prefs prefs_;
97
98 // All state pertaining to payload state such as
99 // response, URL, backoff states.
100 PayloadState payload_state_;
101
102 // Pointer to a GPIO handler and other needed modules (note that the order of
103 // declaration significant for destruction, as the latter depends on the
104 // former).
105 scoped_ptr<UdevInterface> udev_iface_;
106 scoped_ptr<FileDescriptor> file_descriptor_;
107 scoped_ptr<GpioHandler> gpio_handler_;
108
109 // The dbus object used to initialize the update attempter.
110 ConcreteDbusGlib dbus_;
111
112 // Pointer to the update attempter object.
113 scoped_ptr<UpdateAttempter> update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700114
115 // Common parameters for all Omaha requests.
116 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700117
118 // If true, this is the first instance of the update engine since the system
119 // rebooted. Important for tracking whether you are running instance of the
120 // update engine on first boot or due to a crash/restart.
121 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800122};
123
124} // namespace chromeos_update_engine
125
126#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_REAL_SYSTEM_STATE_H_