blob: be7778ed7986ab65e4d43e8bee1aeee4c98da514 [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"
Alex Deymo30534502015-07-20 15:06:33 -070017#include "update_engine/dbus_proxies.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080018#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070019#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080020#include "update_engine/payload_state.h"
21#include "update_engine/prefs.h"
Alex Deymo30534502015-07-20 15:06:33 -070022#include "update_engine/shill_proxy.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080023#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070024#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080025
26namespace chromeos_update_engine {
27
28// A real implementation of the SystemStateInterface which is
29// used by the actual product code.
30class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070031 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070032 // Constructs all system objects that do not require separate initialization;
33 // see Initialize() below for the remaining ones.
Alex Deymo30534502015-07-20 15:06:33 -070034 explicit RealSystemState(const scoped_refptr<dbus::Bus>& bus);
Gilad Arnold1f847232014-04-07 12:07:49 -070035
36 // Initializes and sets systems objects that require an initialization
37 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070038 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080039
Alex Vakulenko157fe302014-08-11 15:59:58 -070040 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070041 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080042 device_policy_ = device_policy;
43 }
44
Alex Vakulenko157fe302014-08-11 15:59:58 -070045 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080046 return device_policy_;
47 }
48
Alex Vakulenko157fe302014-08-11 15:59:58 -070049 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070050
Alex Deymof6ee0162015-07-31 12:35:22 -070051 inline ConnectionManagerInterface* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080052 return &connection_manager_;
53 }
54
Alex Vakulenko157fe302014-08-11 15:59:58 -070055 inline HardwareInterface* hardware() override { return &hardware_; }
Alex Deymo42432912013-07-12 20:21:15 -070056
Alex Vakulenko157fe302014-08-11 15:59:58 -070057 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080058 return &metrics_lib_;
59 }
60
Alex Vakulenko157fe302014-08-11 15:59:58 -070061 inline PrefsInterface* prefs() override { return &prefs_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080062
Alex Vakulenko157fe302014-08-11 15:59:58 -070063 inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070064 return &powerwash_safe_prefs_;
65 }
66
Alex Vakulenko157fe302014-08-11 15:59:58 -070067 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080068 return &payload_state_;
69 }
70
Alex Vakulenko157fe302014-08-11 15:59:58 -070071 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070072 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080073 }
74
Alex Vakulenko157fe302014-08-11 15:59:58 -070075 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070076 return &request_params_;
77 }
78
Alex Vakulenko157fe302014-08-11 15:59:58 -070079 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070080
Alex Vakulenko157fe302014-08-11 15:59:58 -070081 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -070082 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -070083 }
84
Alex Deymo30534502015-07-20 15:06:33 -070085 inline org::chromium::PowerManagerProxyInterface* power_manager_proxy()
86 override {
87 return &power_manager_proxy_;
88 }
89
Alex Vakulenko157fe302014-08-11 15:59:58 -070090 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -070091
Alex Deymo94c06162014-03-21 20:34:46 -070092 private:
Alex Deymo30534502015-07-20 15:06:33 -070093 // Real DBus proxies using the DBus connection.
94 org::chromium::debugdProxy debugd_proxy_;
95 org::chromium::PowerManagerProxy power_manager_proxy_;
96 org::chromium::SessionManagerInterfaceProxy session_manager_proxy_;
97 ShillProxy shill_proxy_;
98 LibCrosProxy libcros_proxy_;
99
David Zeuthenf413fe52013-04-22 14:04:39 -0700100 // Interface for the clock.
101 Clock clock_;
102
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800103 // The latest device policy object from the policy provider.
Alex Deymo30534502015-07-20 15:06:33 -0700104 const policy::DevicePolicy* device_policy_{nullptr};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800105
Alex Deymo30534502015-07-20 15:06:33 -0700106 // The connection manager object that makes download decisions depending on
107 // the current type of connection.
108 ConnectionManager connection_manager_{&shill_proxy_, this};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800109
Alex Deymo42432912013-07-12 20:21:15 -0700110 // Interface for the hardware functions.
111 Hardware hardware_;
112
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800113 // The Metrics Library interface for reporting UMA stats.
114 MetricsLibrary metrics_lib_;
115
116 // Interface for persisted store.
117 Prefs prefs_;
118
Chris Sosaaa18e162013-06-20 13:20:30 -0700119 // Interface for persisted store that persists across powerwashes.
120 Prefs powerwash_safe_prefs_;
121
Alex Deymo30534502015-07-20 15:06:33 -0700122 // All state pertaining to payload state such as response, URL, backoff
123 // states.
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800124 PayloadState payload_state_;
125
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800126 // Pointer to the update attempter object.
Alex Deymo30534502015-07-20 15:06:33 -0700127 UpdateAttempter update_attempter_{this, &libcros_proxy_, &debugd_proxy_};
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700128
129 // Common parameters for all Omaha requests.
Alex Deymo30534502015-07-20 15:06:33 -0700130 OmahaRequestParams request_params_{this};
Chris Sosabe45bef2013-04-09 18:25:12 -0700131
Ben Chan02f7c1d2014-10-18 15:18:02 -0700132 std::unique_ptr<P2PManager> p2p_manager_;
David Zeuthen526cb582013-08-06 12:26:18 -0700133
Ben Chan02f7c1d2014-10-18 15:18:02 -0700134 std::unique_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700135
Alex Deymoc83baf62014-04-02 17:43:35 -0700136 policy::PolicyProvider policy_provider_;
137
Chris Sosabe45bef2013-04-09 18:25:12 -0700138 // If true, this is the first instance of the update engine since the system
139 // rebooted. Important for tracking whether you are running instance of the
140 // update engine on first boot or due to a crash/restart.
Alex Deymo30534502015-07-20 15:06:33 -0700141 bool system_rebooted_{false};
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800142};
143
144} // namespace chromeos_update_engine
145
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700146#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_