blob: 4dee1eb05fa28a434176a3ba02a54a9975a9e876 [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
12#include <update_engine/connection_manager.h>
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080013#include <update_engine/payload_state.h>
14#include <update_engine/prefs.h>
Jay Srinivasan43488792012-06-19 00:25:31 -070015
16namespace chromeos_update_engine {
17
18// An interface to global system context, including platform resources,
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080019// the current state of the system, high-level objects whose lifetime is same
20// as main, system interfaces, etc.
Jay Srinivasan43488792012-06-19 00:25:31 -070021// Carved out separately so it can be mocked for unit tests.
22// Currently it has only one method, but we should start migrating other
23// methods to use this as and when needed to unit test them.
24// TODO (jaysri): Consider renaming this to something like GlobalContext.
25class SystemState {
26 public:
27 // Destructs this object.
28 virtual ~SystemState() {}
29
30 // Returns true if the OOBE process has been completed and EULA accepted.
31 // False otherwise.
32 virtual bool IsOOBEComplete() = 0;
33
34 // Sets or gets the latest device policy.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080035 virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0;
36 virtual const policy::DevicePolicy* device_policy() const = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070037
38 // Gets the connection manager object.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080039 virtual ConnectionManager* connection_manager() = 0;
Jay Srinivasanf0572052012-10-23 18:12:56 -070040
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080041 // Gets the Metrics Library interface for reporting UMA stats.
Jay Srinivasanf0572052012-10-23 18:12:56 -070042 virtual MetricsLibraryInterface* metrics_lib() = 0;
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080043
44 // Gets the interface object for persisted store.
45 virtual PrefsInterface* prefs() = 0;
46
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080047 // Gets the interface for the payload state object.
48 virtual PayloadStateInterface* payload_state() = 0;
Jay Srinivasan43488792012-06-19 00:25:31 -070049};
50
51// A real implementation of the SystemStateInterface which is
52// used by the actual product code.
53class RealSystemState : public SystemState {
54public:
55 // Constructors and destructors.
56 RealSystemState();
57 virtual ~RealSystemState() {}
58
59 virtual bool IsOOBEComplete();
60
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080061 virtual inline void set_device_policy(
62 const policy::DevicePolicy* device_policy) {
63 device_policy_ = device_policy;
64 }
Jay Srinivasan43488792012-06-19 00:25:31 -070065
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080066 virtual inline const policy::DevicePolicy* device_policy() const {
67 return device_policy_;
68 }
Jay Srinivasan43488792012-06-19 00:25:31 -070069
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080070 virtual inline ConnectionManager* connection_manager() {
71 return &connection_manager_;
72 }
Jay Srinivasanf0572052012-10-23 18:12:56 -070073
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080074 virtual inline MetricsLibraryInterface* metrics_lib() {
75 return &metrics_lib_;
76 }
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080077
Jay Srinivasan2b5a0f02012-12-19 17:25:56 -080078 virtual inline PrefsInterface* prefs() {
79 return &prefs_;
80 }
81
82 virtual inline PayloadStateInterface* payload_state() {
83 return &payload_state_;
84 }
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080085
86 // Initializs this concrete object. Other methods should be invoked only
87 // if the object has been initialized successfully.
88 bool Initialize();
89
Jay Srinivasan43488792012-06-19 00:25:31 -070090private:
91 // The latest device policy object from the policy provider.
92 const policy::DevicePolicy* device_policy_;
93
94 // The connection manager object that makes download
95 // decisions depending on the current type of connection.
96 ConnectionManager connection_manager_;
Jay Srinivasanf0572052012-10-23 18:12:56 -070097
98 // The Metrics Library interface for reporting UMA stats.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080099 MetricsLibrary metrics_lib_;
100
101 // Interface for persisted store.
102 Prefs prefs_;
103
104 // All state pertaining to payload state such as
105 // response, URL, back-off states.
106 PayloadState payload_state_;
Jay Srinivasan43488792012-06-19 00:25:31 -0700107};
108
109} // namespace chromeos_update_engine
110
111#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H_