blob: f4bd19c60de2e0ce55a95b7b532b650b04c4673c [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
Jay Srinivasanf0572052012-10-23 18:12:56 -07008#include "metrics/metrics_library.h"
Jay Srinivasan43488792012-06-19 00:25:31 -07009#include <policy/device_policy.h>
10#include <policy/libpolicy.h>
11
Gilad Arnoldf3815bb2013-01-14 11:58:24 -080012#include "update_engine/gpio_handler.h"
Jay Srinivasanae4697c2013-03-18 17:08:08 -070013#include "update_engine/omaha_request_params.h"
Gilad Arnoldf3815bb2013-01-14 11:58:24 -080014
Jay Srinivasan43488792012-06-19 00:25:31 -070015namespace chromeos_update_engine {
16
Jay Srinivasan55f50c22013-01-10 19:24:35 -080017// SystemState is the root class within the update engine. So we should avoid
18// any circular references in header file inclusion. Hence forward-declaring
19// the required classes.
David Zeuthenf413fe52013-04-22 14:04:39 -070020class ClockInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080021class ConnectionManager;
Alex Deymo42432912013-07-12 20:21:15 -070022class HardwareInterface;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080023class PrefsInterface;
24class PayloadStateInterface;
25class GpioHandler;
26class UpdateAttempter;
David Zeuthen526cb582013-08-06 12:26:18 -070027class P2PManager;
Jay Srinivasan55f50c22013-01-10 19:24:35 -080028
Jay Srinivasan43488792012-06-19 00:25:31 -070029// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080030// the current state of the system, high-level objects whose lifetime is same
31// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070032// Carved out separately so it can be mocked for unit tests.
33// Currently it has only one method, but we should start migrating other
34// methods to use this as and when needed to unit test them.
35// TODO (jaysri): Consider renaming this to something like GlobalContext.
36class SystemState {
37 public:
38 // Destructs this object.
39 virtual ~SystemState() {}
40
41 // Returns true if the OOBE process has been completed and EULA accepted.
42 // False otherwise.
43 virtual bool IsOOBEComplete() = 0;
44
Jay Srinivasan53173b92013-05-17 17:13:01 -070045 // Returns true if we're running an official (i.e, non-dev, non-test) build.
46 // False otherwise.
47 virtual bool IsOfficialBuild() = 0;
48
Jay Srinivasan43488792012-06-19 00:25:31 -070049 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080050 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
51 virtual const policy::DevicePolicy* device_policy() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070052
David Zeuthenf413fe52013-04-22 14:04:39 -070053 // Gets the interface object for the clock.
54 virtual ClockInterface* clock() = 0;
55
Jay Srinivasan43488792012-06-19 00:25:31 -070056 // Gets the connection manager object.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080057 virtual ConnectionManager* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070058
Alex Deymo42432912013-07-12 20:21:15 -070059 // Gets the hardware interface object.
60 virtual HardwareInterface* hardware() = 0;
61
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080062 // Gets the Metrics Library interface for reporting UMA stats.
Jay Srinivasanf0572052012-10-23 18:12:56 -070063 virtual MetricsLibraryInterface* metrics_lib() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080064
65 // Gets the interface object for persisted store.
66 virtual PrefsInterface* prefs() = 0;
67
Chris Sosaaa18e162013-06-20 13:20:30 -070068 // Gets the interface object for the persisted store that persists across
69 // powerwashes. Please note that this should be used very seldomly and must
70 // be forwards and backwards compatible as powerwash is used to go back and
71 // forth in system versions.
72 virtual PrefsInterface* powerwash_safe_prefs() = 0;
73
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080074 // Gets the interface for the payload state object.
75 virtual PayloadStateInterface* payload_state() = 0;
Gilad Arnoldbf7919b2013-01-08 13:07:37 -080076
77 // Returns a pointer to the GPIO handler.
78 virtual GpioHandler* gpio_handler() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070079
Jay Srinivasan55f50c22013-01-10 19:24:35 -080080 // Returns a pointer to the update attempter object.
81 virtual UpdateAttempter* update_attempter() = 0;
Jay Srinivasanae4697c2013-03-18 17:08:08 -070082
83 // Returns a pointer to the object that stores the parameters that are
84 // common to all Omaha requests.
85 virtual OmahaRequestParams* request_params() = 0;
Chris Sosabe45bef2013-04-09 18:25:12 -070086
David Zeuthen526cb582013-08-06 12:26:18 -070087 // Returns a pointer to the P2PManager singleton.
88 virtual P2PManager* p2p_manager() = 0;
89
Chris Sosabe45bef2013-04-09 18:25:12 -070090 // If true, this is the first instance of the update engine since the system
91 // restarted. Important for tracking whether you are running instance of the
92 // update engine on first boot or due to a crash/restart.
93 virtual bool system_rebooted() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070094};
95
96} // namespace chromeos_update_engine
97
Jay Srinivasan55f50c22013-01-10 19:24:35 -080098#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_SYSTEM_STATE_H_