Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 1 | // 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 Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 8 | #include "metrics/metrics_library.h" |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 9 | #include <policy/device_policy.h> |
| 10 | #include <policy/libpolicy.h> |
| 11 | |
| 12 | #include <update_engine/connection_manager.h> |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 13 | #include <update_engine/payload_state.h> |
| 14 | #include <update_engine/prefs.h> |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 15 | |
| 16 | namespace chromeos_update_engine { |
| 17 | |
| 18 | // An interface to global system context, including platform resources, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 19 | // the current state of the system, high-level objects whose lifetime is same |
| 20 | // as main, system interfaces, etc. |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 21 | // 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. |
| 25 | class 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 Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 35 | virtual void set_device_policy(const policy::DevicePolicy* device_policy) = 0; |
| 36 | virtual const policy::DevicePolicy* device_policy() const = 0; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 37 | |
| 38 | // Gets the connection manager object. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 39 | virtual ConnectionManager* connection_manager() = 0; |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 40 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 41 | // Gets the Metrics Library interface for reporting UMA stats. |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 42 | virtual MetricsLibraryInterface* metrics_lib() = 0; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 43 | |
| 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 Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // A real implementation of the SystemStateInterface which is |
| 52 | // used by the actual product code. |
| 53 | class RealSystemState : public SystemState { |
| 54 | public: |
| 55 | // Constructors and destructors. |
| 56 | RealSystemState(); |
| 57 | virtual ~RealSystemState() {} |
| 58 | |
| 59 | virtual bool IsOOBEComplete(); |
| 60 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 61 | virtual void set_device_policy(const policy::DevicePolicy* device_policy); |
| 62 | virtual const policy::DevicePolicy* device_policy() const; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 63 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 64 | virtual ConnectionManager* connection_manager(); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 65 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 66 | virtual MetricsLibraryInterface* metrics_lib(); |
| 67 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 68 | 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 Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 76 | private: |
| 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 Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 83 | |
| 84 | // The Metrics Library interface for reporting UMA stats. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame^] | 85 | 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 Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace chromeos_update_engine |
| 96 | |
| 97 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H_ |