blob: 47c71aee4690bdd7bf9d3ff53f5b634fc7d5a7ee [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
Alex Deymoc83baf62014-04-02 17:43:35 -070010#include <metrics/metrics_library.h>
Alex Deymo63784a52014-05-28 10:46:14 -070011#include <policy/device_policy.h>
Gilad Arnold1f847232014-04-07 12:07:49 -070012
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080013#include "update_engine/clock.h"
14#include "update_engine/connection_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080015#include "update_engine/hardware.h"
Alex Deymo94c06162014-03-21 20:34:46 -070016#include "update_engine/p2p_manager.h"
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -080017#include "update_engine/payload_state.h"
18#include "update_engine/prefs.h"
19#include "update_engine/real_dbus_wrapper.h"
20#include "update_engine/update_attempter.h"
Alex Deymo63784a52014-05-28 10:46:14 -070021#include "update_engine/update_manager/update_manager.h"
Jay Srinivasan55f50c22013-01-10 19:24:35 -080022
23namespace chromeos_update_engine {
24
25// A real implementation of the SystemStateInterface which is
26// used by the actual product code.
27class RealSystemState : public SystemState {
Alex Deymo94c06162014-03-21 20:34:46 -070028 public:
Gilad Arnold1f847232014-04-07 12:07:49 -070029 // Constructs all system objects that do not require separate initialization;
30 // see Initialize() below for the remaining ones.
Jay Srinivasan55f50c22013-01-10 19:24:35 -080031 RealSystemState();
Gilad Arnold1f847232014-04-07 12:07:49 -070032
33 // Initializes and sets systems objects that require an initialization
34 // separately from construction. Returns |true| on success.
Nam T. Nguyen7d623eb2014-05-13 16:06:28 -070035 bool Initialize();
Jay Srinivasan55f50c22013-01-10 19:24:35 -080036
Alex Vakulenko157fe302014-08-11 15:59:58 -070037 inline void set_device_policy(
Gilad Arnold1f847232014-04-07 12:07:49 -070038 const policy::DevicePolicy* device_policy) override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080039 device_policy_ = device_policy;
40 }
41
Alex Vakulenko157fe302014-08-11 15:59:58 -070042 inline const policy::DevicePolicy* device_policy() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080043 return device_policy_;
44 }
45
Alex Vakulenko157fe302014-08-11 15:59:58 -070046 inline ClockInterface* clock() override { return &clock_; }
David Zeuthenf413fe52013-04-22 14:04:39 -070047
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 inline ConnectionManager* connection_manager() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080049 return &connection_manager_;
50 }
51
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 inline HardwareInterface* hardware() override { return &hardware_; }
Alex Deymo42432912013-07-12 20:21:15 -070053
Alex Vakulenko157fe302014-08-11 15:59:58 -070054 inline MetricsLibraryInterface* metrics_lib() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080055 return &metrics_lib_;
56 }
57
Alex Vakulenko157fe302014-08-11 15:59:58 -070058 inline PrefsInterface* prefs() override { return &prefs_; }
Jay Srinivasan55f50c22013-01-10 19:24:35 -080059
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 inline PrefsInterface* powerwash_safe_prefs() override {
Chris Sosaaa18e162013-06-20 13:20:30 -070061 return &powerwash_safe_prefs_;
62 }
63
Alex Vakulenko157fe302014-08-11 15:59:58 -070064 inline PayloadStateInterface* payload_state() override {
Jay Srinivasan55f50c22013-01-10 19:24:35 -080065 return &payload_state_;
66 }
67
Alex Vakulenko157fe302014-08-11 15:59:58 -070068 inline UpdateAttempter* update_attempter() override {
Gilad Arnold1f847232014-04-07 12:07:49 -070069 return &update_attempter_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080070 }
71
Alex Vakulenko157fe302014-08-11 15:59:58 -070072 inline OmahaRequestParams* request_params() override {
Jay Srinivasanae4697c2013-03-18 17:08:08 -070073 return &request_params_;
74 }
75
Alex Vakulenko157fe302014-08-11 15:59:58 -070076 inline P2PManager* p2p_manager() override { return p2p_manager_.get(); }
David Zeuthen526cb582013-08-06 12:26:18 -070077
Alex Vakulenko157fe302014-08-11 15:59:58 -070078 inline chromeos_update_manager::UpdateManager* update_manager() override {
Alex Deymo63784a52014-05-28 10:46:14 -070079 return update_manager_.get();
Alex Deymo94c06162014-03-21 20:34:46 -070080 }
81
Alex Vakulenko157fe302014-08-11 15:59:58 -070082 inline bool system_rebooted() override { return system_rebooted_; }
Chris Sosabe45bef2013-04-09 18:25:12 -070083
Alex Deymo94c06162014-03-21 20:34:46 -070084 private:
David Zeuthenf413fe52013-04-22 14:04:39 -070085 // Interface for the clock.
86 Clock clock_;
87
Jay Srinivasan55f50c22013-01-10 19:24:35 -080088 // The latest device policy object from the policy provider.
89 const policy::DevicePolicy* device_policy_;
90
91 // The connection manager object that makes download
92 // decisions depending on the current type of connection.
93 ConnectionManager connection_manager_;
94
Alex Deymo42432912013-07-12 20:21:15 -070095 // Interface for the hardware functions.
96 Hardware hardware_;
97
Jay Srinivasan55f50c22013-01-10 19:24:35 -080098 // The Metrics Library interface for reporting UMA stats.
99 MetricsLibrary metrics_lib_;
100
101 // Interface for persisted store.
102 Prefs prefs_;
103
Chris Sosaaa18e162013-06-20 13:20:30 -0700104 // Interface for persisted store that persists across powerwashes.
105 Prefs powerwash_safe_prefs_;
106
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800107 // All state pertaining to payload state such as
108 // response, URL, backoff states.
109 PayloadState payload_state_;
110
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800111 // The dbus object used to initialize the update attempter.
Gilad Arnold1b9d6ae2014-03-03 13:46:07 -0800112 RealDBusWrapper dbus_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800113
114 // Pointer to the update attempter object.
Gilad Arnold1f847232014-04-07 12:07:49 -0700115 UpdateAttempter update_attempter_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700116
117 // Common parameters for all Omaha requests.
118 OmahaRequestParams request_params_;
Chris Sosabe45bef2013-04-09 18:25:12 -0700119
David Zeuthen526cb582013-08-06 12:26:18 -0700120 scoped_ptr<P2PManager> p2p_manager_;
121
Alex Deymo63784a52014-05-28 10:46:14 -0700122 scoped_ptr<chromeos_update_manager::UpdateManager> update_manager_;
Alex Deymo94c06162014-03-21 20:34:46 -0700123
Alex Deymoc83baf62014-04-02 17:43:35 -0700124 policy::PolicyProvider policy_provider_;
125
Chris Sosabe45bef2013-04-09 18:25:12 -0700126 // If true, this is the first instance of the update engine since the system
127 // rebooted. Important for tracking whether you are running instance of the
128 // update engine on first boot or due to a crash/restart.
129 bool system_rebooted_;
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800130};
131
132} // namespace chromeos_update_engine
133
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700134#endif // UPDATE_ENGINE_REAL_SYSTEM_STATE_H_