blob: 04ad38272ad4de9385a6c295abd1b5cb8bb69cfd [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
47 // Gets the URL State object.
48 virtual PayloadState* 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 Srinivasan6f6ea002012-12-14 11:26:28 -080061 virtual void set_device_policy(const policy::DevicePolicy* device_policy);
62 virtual const policy::DevicePolicy* device_policy() const;
Jay Srinivasan43488792012-06-19 00:25:31 -070063
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080064 virtual ConnectionManager* connection_manager();
Jay Srinivasan43488792012-06-19 00:25:31 -070065
Jay Srinivasanf0572052012-10-23 18:12:56 -070066 virtual MetricsLibraryInterface* metrics_lib();
67
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080068 virtual PrefsInterface* prefs();
69
70 virtual PayloadState* payload_state();
71
72 // Initializs this concrete object. Other methods should be invoked only
73 // if the object has been initialized successfully.
74 bool Initialize();
75
Jay Srinivasan43488792012-06-19 00:25:31 -070076private:
77 // The latest device policy object from the policy provider.
78 const policy::DevicePolicy* device_policy_;
79
80 // The connection manager object that makes download
81 // decisions depending on the current type of connection.
82 ConnectionManager connection_manager_;
Jay Srinivasanf0572052012-10-23 18:12:56 -070083
84 // The Metrics Library interface for reporting UMA stats.
Jay Srinivasan6f6ea002012-12-14 11:26:28 -080085 MetricsLibrary metrics_lib_;
86
87 // Interface for persisted store.
88 Prefs prefs_;
89
90 // All state pertaining to payload state such as
91 // response, URL, back-off states.
92 PayloadState payload_state_;
Jay Srinivasan43488792012-06-19 00:25:31 -070093};
94
95} // namespace chromeos_update_engine
96
97#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H_