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