blob: 8668542930b5c14aaf3257dbcdca0e203c1cc3f2 [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
Jay Srinivasan43488792012-06-19 00:25:31 -070016namespace chromeos_update_engine {
17
Jay Srinivasan55f50c22013-01-10 19:24:35 -080018// SystemState is the root class within the update engine. So we should avoid
19// any circular references in header file inclusion. Hence forward-declaring
20// the required classes.
David Zeuthenf413fe52013-04-22 14:04:39 -070021class ClockInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080022class ConnectionManager;
Alex Deymo42432912013-07-12 20:21:15 -070023class HardwareInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080024class PrefsInterface;
25class PayloadStateInterface;
26class GpioHandler;
27class UpdateAttempter;
David Zeuthen526cb582013-08-06 12:26:18 -070028class P2PManager;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080029
Jay Srinivasan43488792012-06-19 00:25:31 -070030// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080031// the current state of the system, high-level objects whose lifetime is same
32// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070033// Carved out separately so it can be mocked for unit tests.
34// Currently it has only one method, but we should start migrating other
35// methods to use this as and when needed to unit test them.
36// TODO (jaysri): Consider renaming this to something like GlobalContext.
37class SystemState {
38 public:
39 // Destructs this object.
40 virtual ~SystemState() {}
41
David Zeuthen639aa362014-02-03 16:23:44 -080042 // Returns true if the OOBE process has been completed and EULA
43 // accepted, False otherwise. If True is returned, the time-stamp
44 // of when OOBE happened is returned in |out_time_of_oobe|.
45 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070046
47 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080048 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
49 virtual const policy::DevicePolicy* device_policy() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070050
David Zeuthenf413fe52013-04-22 14:04:39 -070051 // Gets the interface object for the clock.
52 virtual ClockInterface* clock() = 0;
53
Jay Srinivasan43488792012-06-19 00:25:31 -070054 // Gets the connection manager object.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080055 virtual ConnectionManager* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070056
Alex Deymo42432912013-07-12 20:21:15 -070057 // Gets the hardware interface object.
58 virtual HardwareInterface* hardware() = 0;
59
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080060 // Gets the Metrics Library interface for reporting UMA stats.
Jay Srinivasanf0572052012-10-23 18:12:56 -070061 virtual MetricsLibraryInterface* metrics_lib() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080062
63 // Gets the interface object for persisted store.
64 virtual PrefsInterface* prefs() = 0;
65
Chris Sosaaa18e162013-06-20 13:20:30 -070066 // Gets the interface object for the persisted store that persists across
67 // powerwashes. Please note that this should be used very seldomly and must
68 // be forwards and backwards compatible as powerwash is used to go back and
69 // forth in system versions.
70 virtual PrefsInterface* powerwash_safe_prefs() = 0;
71
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080072 // Gets the interface for the payload state object.
73 virtual PayloadStateInterface* payload_state() = 0;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080074
75 // Returns a pointer to the GPIO handler.
76 virtual GpioHandler* gpio_handler() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070077
Jay Srinivasan55f50c22013-01-10 19:24:35 -080078 // Returns a pointer to the update attempter object.
79 virtual UpdateAttempter* update_attempter() = 0;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070080
81 // Returns a pointer to the object that stores the parameters that are
82 // common to all Omaha requests.
83 virtual OmahaRequestParams* request_params() = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -070084
David Zeuthen526cb582013-08-06 12:26:18 -070085 // Returns a pointer to the P2PManager singleton.
86 virtual P2PManager* p2p_manager() = 0;
87
Chris Sosabe45bef2013-04-09 18:25:12 -070088 // If true, this is the first instance of the update engine since the system
89 // restarted. Important for tracking whether you are running instance of the
90 // update engine on first boot or due to a crash/restart.
91 virtual bool system_rebooted() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070092};
93
94} // namespace chromeos_update_engine
95
Jay Srinivasan55f50c22013-01-10 19:24:35 -080096#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_