• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #ifndef LIBBRILLO_POLICY_LIBPOLICY_H_
6 #define LIBBRILLO_POLICY_LIBPOLICY_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include <base/macros.h>
12 
13 #include "install_attributes/libinstallattributes.h"
14 
15 #pragma GCC visibility push(default)
16 
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:
27   // The default constructor does not load policy.
28   PolicyProvider();
29   virtual ~PolicyProvider();
30 
31   // Constructor for tests only!
32   explicit PolicyProvider(std::unique_ptr<DevicePolicy> device_policy);
33 
34   // This function will ensure the freshness of the contents that the getters
35   // are delivering. Normally contents are cached to prevent unnecessary load.
36   virtual bool Reload();
37 
38   virtual bool device_policy_is_loaded() const;
39 
40   // Returns a value from the device policy cache.
41   virtual const DevicePolicy& GetDevicePolicy() const;
42 
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 
53  private:
54   std::unique_ptr<DevicePolicy> device_policy_;
55   bool device_policy_is_loaded_ = false;
56   std::unique_ptr<InstallAttributesReader> install_attributes_reader_;
57 
58   DISALLOW_COPY_AND_ASSIGN(PolicyProvider);
59 };
60 }  // namespace policy
61 
62 #pragma GCC visibility pop
63 
64 #endif  // LIBBRILLO_POLICY_LIBPOLICY_H_
65