blob: 4e97b9543accc5384aa1e2b97cbb0f5e53f026dd [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
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
6#define UPDATE_ENGINE_REAL_SYSTEM_STATE_H_
Jay Srinivasan55f50c22013-01-10 19:24:35 -08007
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -08008#include "update_engine/system_state.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -08009
Ben Chan02f7c1d2014-10-18 15:18:02 -070010#include <memory>
11
Alex Deymoc83baf62014-04-02 17:43:35 -070012#include <metrics/metrics_library.h>
Alex Deymo63784a52014-05-28 10:46:14 -070013#include <policy/device_policy.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070014
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080015#include "update_engine/clock.h"
16#include "update_engine/connection_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080017#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070018#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080019#include "update_engine/payload_state.h"
20#include "update_engine/prefs.h"
21#include "update_engine/real_dbus_wrapper.h"
22#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070023#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080024
25namespace chromeos_update_engine {
26
27// A real implementation of the SystemStateInterface which is
28// used by the actual product code.
29class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070030 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070031 // Constructs all system objects that do not require separate initialization;
32 // see Initialize() below for the remaining ones.
Jay Srinivasan55f50c22013-01-10 19:24:35 -080033 RealSystemState();
Gilad Arnold1f847232014-04-07 12:07:49 -070034
35 // Initializes and sets systems objects that require an initialization
36 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070037 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080038
Alex Vakulenko157fe302014-08-11 15:59:58 -070039 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070040 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080041 device_policy_ = device_policy;
42 }
43
Alex Vakulenko157fe302014-08-11 15:59:58 -070044 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080045 return device_policy_;
46 }
47
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070049
Alex Deymof6ee0162015-07-31 12:35:22 -070050 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080051 return &connection_manager_;
52 }
53
Alex Vakulenko157fe302014-08-11 15:59:58 -070054 inline HardwareInterface* hardware() override { return &hardware_; }
Alex Deymo42432912013-07-12 20:21:15 -070055
Alex Vakulenko157fe302014-08-11 15:59:58 -070056 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080057 return &metrics_lib_;
58 }
59
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 inline PrefsInterface* prefs() override { return &prefs_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080061
Alex Vakulenko157fe302014-08-11 15:59:58 -070062 inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070063 return &powerwash_safe_prefs_;
64 }
65
Alex Vakulenko157fe302014-08-11 15:59:58 -070066 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080067 return &payload_state_;
68 }
69
Alex Vakulenko157fe302014-08-11 15:59:58 -070070 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070071 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080072 }
73
Alex Vakulenko157fe302014-08-11 15:59:58 -070074 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070075 return &request_params_;
76 }
77
Alex Vakulenko157fe302014-08-11 15:59:58 -070078 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070079
Alex Vakulenko157fe302014-08-11 15:59:58 -070080 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -070081 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -070082 }
83
Alex Vakulenko157fe302014-08-11 15:59:58 -070084 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -070085
Alex Deymo94c06162014-03-21 20:34:46 -070086 private:
David Zeuthenf413fe52013-04-22 14:04:39 -070087 // Interface for the clock.
88 Clock clock_;
89
Jay Srinivasan55f50c22013-01-10 19:24:35 -080090 // The latest device policy object from the policy provider.
91 const policy::DevicePolicy* device_policy_;
92
93 // The connection manager object that makes download
94 // decisions depending on the current type of connection.
95 ConnectionManager connection_manager_;
96
Alex Deymo42432912013-07-12 20:21:15 -070097 // Interface for the hardware functions.
98 Hardware hardware_;
99
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800100 // The Metrics Library interface for reporting UMA stats.
101 MetricsLibrary metrics_lib_;
102
103 // Interface for persisted store.
104 Prefs prefs_;
105
Chris Sosaaa18e162013-06-20 13:20:30 -0700106 // Interface for persisted store that persists across powerwashes.
107 Prefs powerwash_safe_prefs_;
108
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800109 // All state pertaining to payload state such as
110 // response, URL, backoff states.
111 PayloadState payload_state_;
112
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800113 // The dbus object used to initialize the update attempter.
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800114 RealDBusWrapper dbus_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800115
116 // Pointer to the update attempter object.
Gilad Arnold1f847232014-04-07 12:07:49 -0700117 UpdateAttempter update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700118
119 // Common parameters for all Omaha requests.
120 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700121
Ben Chan02f7c1d2014-10-18 15:18:02 -0700122 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700123
Ben Chan02f7c1d2014-10-18 15:18:02 -0700124 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700125
Alex Deymoc83baf62014-04-02 17:43:35 -0700126 policy::PolicyProvider policy_provider_;
127
Chris Sosabe45bef2013-04-09 18:25:12 -0700128 // If true, this is the first instance of the update engine since the system
129 // rebooted. Important for tracking whether you are running instance of the
130 // update engine on first boot or due to a crash/restart.
131 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800132};
133
134} // namespace chromeos_update_engine
135
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700136#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_