blob: 5e87f584e2876614c149f4d2cf5bb2234fb03b64 [file] [log] [blame]
Julian Pastarmov2638fbc2011-07-20 14:30:46 +02001// 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 Vakulenkofed60b02015-10-27 09:53:05 -07005#ifndef LIBBRILLO_POLICY_LIBPOLICY_H_
6#define LIBBRILLO_POLICY_LIBPOLICY_H_
Julian Pastarmov2638fbc2011-07-20 14:30:46 +02007
Luis Hector Chavez16c285d2016-05-20 23:07:35 -07008#include <memory>
Julian Pastarmov2638fbc2011-07-20 14:30:46 +02009#include <string>
10
Alex Vakulenkof2418e52014-09-04 08:26:42 -070011#include <base/macros.h>
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020012
Marton Hunyady7859c4f2018-04-16 20:04:21 +020013#include "install_attributes/libinstallattributes.h"
14
Mike Frysingerc313f822012-02-17 16:18:38 -050015#pragma GCC visibility push(default)
16
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020017namespace policy {
18
19class 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.
25class PolicyProvider {
26 public:
Lutz Justenc794a052018-01-29 14:46:42 +010027 // The default constructor does not load policy.
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020028 PolicyProvider();
29 virtual ~PolicyProvider();
30
Alex Vakulenkof2418e52014-09-04 08:26:42 -070031 // Constructor for tests only!
Igord213a402017-09-20 15:56:08 +020032 explicit PolicyProvider(std::unique_ptr<DevicePolicy> device_policy);
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020033
Alex Vakulenkof2418e52014-09-04 08:26:42 -070034 // This function will ensure the freshness of the contents that the getters
35 // are delivering. Normally contents are cached to prevent unnecessary load.
Alex Deymo5da8faf2014-04-11 19:34:06 -070036 virtual bool Reload();
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020037
Alex Deymo5da8faf2014-04-11 19:34:06 -070038 virtual bool device_policy_is_loaded() const;
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020039
40 // Returns a value from the device policy cache.
41 virtual const DevicePolicy& GetDevicePolicy() const;
42
Marton Hunyady7859c4f2018-04-16 20:04:21 +020043 // 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 Pastarmov2638fbc2011-07-20 14:30:46 +020053 private:
Luis Hector Chavez16c285d2016-05-20 23:07:35 -070054 std::unique_ptr<DevicePolicy> device_policy_;
Thiemo Nagelce533da2016-10-24 14:53:14 +020055 bool device_policy_is_loaded_ = false;
Marton Hunyady7859c4f2018-04-16 20:04:21 +020056 std::unique_ptr<InstallAttributesReader> install_attributes_reader_;
Julian Pastarmov2638fbc2011-07-20 14:30:46 +020057
58 DISALLOW_COPY_AND_ASSIGN(PolicyProvider);
59};
60} // namespace policy
61
Mike Frysingerc313f822012-02-17 16:18:38 -050062#pragma GCC visibility pop
63
Alex Vakulenkofed60b02015-10-27 09:53:05 -070064#endif // LIBBRILLO_POLICY_LIBPOLICY_H_