blob: 2148b514bcbf63936f598b61a4f3c512646c99e9 [file] [log] [blame]
Jay Srinivasan43488792012-06-19 00:25:31 -07001// Copyright (c) 2012 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_SYSTEM_STATE_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_
7
Alex Vakulenko75039d72014-03-25 12:36:28 -07008#include <base/time/time.h>
Jay Srinivasanf0572052012-10-23 18:12:56 -07009#include "metrics/metrics_library.h"
Jay Srinivasan43488792012-06-19 00:25:31 -070010#include <policy/device_policy.h>
11#include <policy/libpolicy.h>
12
Gilad Arnoldf3815bb2013-01-14 11:58:24 -080013#include "update_engine/gpio_handler.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070014#include "update_engine/omaha_request_params.h"
Gilad Arnoldf3815bb2013-01-14 11:58:24 -080015
Alex Deymo94c06162014-03-21 20:34:46 -070016namespace chromeos_policy_manager {
17
18class PolicyManager;
19
20} // namespace chromeos_policy_manager
21
Jay Srinivasan43488792012-06-19 00:25:31 -070022namespace chromeos_update_engine {
23
Jay Srinivasan55f50c22013-01-10 19:24:35 -080024// SystemState is the root class within the update engine. So we should avoid
25// any circular references in header file inclusion. Hence forward-declaring
26// the required classes.
David Zeuthenf413fe52013-04-22 14:04:39 -070027class ClockInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080028class ConnectionManager;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080029class GpioHandler;
Alex Deymo94c06162014-03-21 20:34:46 -070030class HardwareInterface;
David Zeuthen526cb582013-08-06 12:26:18 -070031class P2PManager;
Alex Deymo94c06162014-03-21 20:34:46 -070032class PayloadStateInterface;
33class PrefsInterface;
34class UpdateAttempter;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080035
Jay Srinivasan43488792012-06-19 00:25:31 -070036// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080037// the current state of the system, high-level objects whose lifetime is same
38// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070039// Carved out separately so it can be mocked for unit tests.
40// Currently it has only one method, but we should start migrating other
41// methods to use this as and when needed to unit test them.
Alex Deymo94c06162014-03-21 20:34:46 -070042// TODO(jaysri): Consider renaming this to something like GlobalContext.
Jay Srinivasan43488792012-06-19 00:25:31 -070043class SystemState {
44 public:
45 // Destructs this object.
46 virtual ~SystemState() {}
47
David Zeuthen639aa362014-02-03 16:23:44 -080048 // Returns true if the OOBE process has been completed and EULA
49 // accepted, False otherwise. If True is returned, the time-stamp
50 // of when OOBE happened is returned in |out_time_of_oobe|.
51 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070052
53 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080054 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
55 virtual const policy::DevicePolicy* device_policy() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070056
David Zeuthenf413fe52013-04-22 14:04:39 -070057 // Gets the interface object for the clock.
58 virtual ClockInterface* clock() = 0;
59
Jay Srinivasan43488792012-06-19 00:25:31 -070060 // Gets the connection manager object.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080061 virtual ConnectionManager* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070062
Alex Deymo42432912013-07-12 20:21:15 -070063 // Gets the hardware interface object.
64 virtual HardwareInterface* hardware() = 0;
65
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080066 // Gets the Metrics Library interface for reporting UMA stats.
Jay Srinivasanf0572052012-10-23 18:12:56 -070067 virtual MetricsLibraryInterface* metrics_lib() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080068
69 // Gets the interface object for persisted store.
70 virtual PrefsInterface* prefs() = 0;
71
Chris Sosaaa18e162013-06-20 13:20:30 -070072 // Gets the interface object for the persisted store that persists across
73 // powerwashes. Please note that this should be used very seldomly and must
74 // be forwards and backwards compatible as powerwash is used to go back and
75 // forth in system versions.
76 virtual PrefsInterface* powerwash_safe_prefs() = 0;
77
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080078 // Gets the interface for the payload state object.
79 virtual PayloadStateInterface* payload_state() = 0;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080080
81 // Returns a pointer to the GPIO handler.
82 virtual GpioHandler* gpio_handler() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070083
Jay Srinivasan55f50c22013-01-10 19:24:35 -080084 // Returns a pointer to the update attempter object.
85 virtual UpdateAttempter* update_attempter() = 0;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070086
87 // Returns a pointer to the object that stores the parameters that are
88 // common to all Omaha requests.
89 virtual OmahaRequestParams* request_params() = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -070090
David Zeuthen526cb582013-08-06 12:26:18 -070091 // Returns a pointer to the P2PManager singleton.
92 virtual P2PManager* p2p_manager() = 0;
93
Alex Deymo94c06162014-03-21 20:34:46 -070094 // Returns a pointer to the PolicyManager singleton.
95 virtual chromeos_policy_manager::PolicyManager* policy_manager() = 0;
96
Chris Sosabe45bef2013-04-09 18:25:12 -070097 // If true, this is the first instance of the update engine since the system
98 // restarted. Important for tracking whether you are running instance of the
99 // update engine on first boot or due to a crash/restart.
100 virtual bool system_rebooted() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -0700101};
102
103} // namespace chromeos_update_engine
104
Jay Srinivasan55f50c22013-01-10 19:24:35 -0800105#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_