Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
Alex Vakulenko | fed60b0 | 2015-10-27 09:53:05 -0700 | [diff] [blame] | 5 | #ifndef LIBBRILLO_POLICY_LIBPOLICY_H_ |
| 6 | #define LIBBRILLO_POLICY_LIBPOLICY_H_ |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 7 | |
Luis Hector Chavez | 16c285d | 2016-05-20 23:07:35 -0700 | [diff] [blame] | 8 | #include <memory> |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Alex Vakulenko | f2418e5 | 2014-09-04 08:26:42 -0700 | [diff] [blame] | 11 | #include <base/macros.h> |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 12 | |
Marton Hunyady | 7859c4f | 2018-04-16 20:04:21 +0200 | [diff] [blame] | 13 | #include "install_attributes/libinstallattributes.h" |
| 14 | |
Mike Frysinger | c313f82 | 2012-02-17 16:18:38 -0500 | [diff] [blame] | 15 | #pragma GCC visibility push(default) |
| 16 | |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 17 | namespace policy { |
| 18 | |
| 19 | class DevicePolicy; |
| 20 | |
| 21 | // This class holds device settings that are to be enforced across all users. |
| 22 | // |
| 23 | // If there is a policy on disk at creation time, we will load it at verify |
| 24 | // its signature. |
| 25 | class PolicyProvider { |
| 26 | public: |
Lutz Justen | c794a05 | 2018-01-29 14:46:42 +0100 | [diff] [blame] | 27 | // The default constructor does not load policy. |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 28 | PolicyProvider(); |
| 29 | virtual ~PolicyProvider(); |
| 30 | |
Alex Vakulenko | f2418e5 | 2014-09-04 08:26:42 -0700 | [diff] [blame] | 31 | // Constructor for tests only! |
Igor | d213a40 | 2017-09-20 15:56:08 +0200 | [diff] [blame] | 32 | explicit PolicyProvider(std::unique_ptr<DevicePolicy> device_policy); |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 33 | |
Alex Vakulenko | f2418e5 | 2014-09-04 08:26:42 -0700 | [diff] [blame] | 34 | // This function will ensure the freshness of the contents that the getters |
| 35 | // are delivering. Normally contents are cached to prevent unnecessary load. |
Alex Deymo | 5da8faf | 2014-04-11 19:34:06 -0700 | [diff] [blame] | 36 | virtual bool Reload(); |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 37 | |
Alex Deymo | 5da8faf | 2014-04-11 19:34:06 -0700 | [diff] [blame] | 38 | virtual bool device_policy_is_loaded() const; |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 39 | |
| 40 | // Returns a value from the device policy cache. |
| 41 | virtual const DevicePolicy& GetDevicePolicy() const; |
| 42 | |
Marton Hunyady | 7859c4f | 2018-04-16 20:04:21 +0200 | [diff] [blame] | 43 | // Returns true if the device is not an enterprise enrolled device, so it |
| 44 | // won't have device policy before the next powerwash. Returns false if device |
| 45 | // is still in OOBE (so device mode is not determined yet). |
| 46 | virtual bool IsConsumerDevice() const; |
| 47 | |
| 48 | void SetDevicePolicyForTesting( |
| 49 | std::unique_ptr<DevicePolicy> device_policy); |
| 50 | void SetInstallAttributesReaderForTesting( |
| 51 | std::unique_ptr<InstallAttributesReader> install_attributes_reader); |
| 52 | |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 53 | private: |
Luis Hector Chavez | 16c285d | 2016-05-20 23:07:35 -0700 | [diff] [blame] | 54 | std::unique_ptr<DevicePolicy> device_policy_; |
Thiemo Nagel | ce533da | 2016-10-24 14:53:14 +0200 | [diff] [blame] | 55 | bool device_policy_is_loaded_ = false; |
Marton Hunyady | 7859c4f | 2018-04-16 20:04:21 +0200 | [diff] [blame] | 56 | std::unique_ptr<InstallAttributesReader> install_attributes_reader_; |
Julian Pastarmov | 2638fbc | 2011-07-20 14:30:46 +0200 | [diff] [blame] | 57 | |
| 58 | DISALLOW_COPY_AND_ASSIGN(PolicyProvider); |
| 59 | }; |
| 60 | } // namespace policy |
| 61 | |
Mike Frysinger | c313f82 | 2012-02-17 16:18:38 -0500 | [diff] [blame] | 62 | #pragma GCC visibility pop |
| 63 | |
Alex Vakulenko | fed60b0 | 2015-10-27 09:53:05 -0700 | [diff] [blame] | 64 | #endif // LIBBRILLO_POLICY_LIBPOLICY_H_ |