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 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 47 | // Gets the interface for the payload state object. |
| 48 | virtual PayloadStateInterface* 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 | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 61 | virtual inline void set_device_policy( |
| 62 | const policy::DevicePolicy* device_policy) { |
| 63 | device_policy_ = device_policy; |
| 64 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 65 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 66 | virtual inline const policy::DevicePolicy* device_policy() const { |
| 67 | return device_policy_; |
| 68 | } |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 69 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 70 | virtual inline ConnectionManager* connection_manager() { |
| 71 | return &connection_manager_; |
| 72 | } |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 73 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 74 | virtual inline MetricsLibraryInterface* metrics_lib() { |
| 75 | return &metrics_lib_; |
| 76 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 77 | |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 78 | virtual inline PrefsInterface* prefs() { |
| 79 | return &prefs_; |
| 80 | } |
| 81 | |
| 82 | virtual inline PayloadStateInterface* payload_state() { |
| 83 | return &payload_state_; |
| 84 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 85 | |
| 86 | // Initializs this concrete object. Other methods should be invoked only |
| 87 | // if the object has been initialized successfully. |
| 88 | bool Initialize(); |
| 89 | |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 90 | private: |
| 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 Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 97 | |
| 98 | // The Metrics Library interface for reporting UMA stats. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 99 | MetricsLibrary metrics_lib_; |
| 100 | |
| 101 | // Interface for persisted store. |
| 102 | Prefs prefs_; |
| 103 | |
| 104 | // All state pertaining to payload state such as |
Jay Srinivasan | 0826288 | 2012-12-28 19:29:43 -0800 | [diff] [blame^] | 105 | // response, URL, backoff states. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 106 | PayloadState payload_state_; |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | } // namespace chromeos_update_engine |
| 110 | |
| 111 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H_ |