• 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 #include "policy/libpolicy.h"
6 
7 #include <base/logging.h>
8 
9 #include "policy/device_policy.h"
10 #ifndef __ANDROID__
11 #include "policy/device_policy_impl.h"
12 #endif
13 
14 namespace policy {
15 
PolicyProvider()16 PolicyProvider::PolicyProvider()
17     : device_policy_(nullptr),
18       device_policy_is_loaded_(false) {
19 #ifndef __ANDROID__
20   device_policy_.reset(new DevicePolicyImpl());
21 #endif
22 }
23 
PolicyProvider(DevicePolicy * device_policy)24 PolicyProvider::PolicyProvider(DevicePolicy* device_policy)
25     : device_policy_(device_policy),
26       device_policy_is_loaded_(true) {
27 }
28 
~PolicyProvider()29 PolicyProvider::~PolicyProvider() {
30 }
31 
Reload()32 bool PolicyProvider::Reload() {
33   if (!device_policy_)
34     return false;
35   device_policy_is_loaded_ = device_policy_->LoadPolicy();
36   if (!device_policy_is_loaded_) {
37     LOG(WARNING) << "Could not load the device policy file.";
38   }
39   return device_policy_is_loaded_;
40 }
41 
device_policy_is_loaded() const42 bool PolicyProvider::device_policy_is_loaded() const {
43   return device_policy_is_loaded_;
44 }
45 
GetDevicePolicy() const46 const DevicePolicy& PolicyProvider::GetDevicePolicy() const {
47   if (!device_policy_is_loaded_)
48     DCHECK("Trying to get policy data but policy was not loaded!");
49 
50   return *device_policy_;
51 }
52 
53 }  // namespace policy
54