blob: 903916affe82f49530b90550100a2d7e26ba8dcc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/policy_map.h"
namespace policy {
ConfigurationPolicyProvider::Observer::~Observer() {}
void ConfigurationPolicyProvider::Observer::OnProviderGoingAway() {}
// Class ConfigurationPolicyProvider.
ConfigurationPolicyProvider::ConfigurationPolicyProvider(
const PolicyDefinitionList* policy_list)
: policy_definition_list_(policy_list) {
}
ConfigurationPolicyProvider::~ConfigurationPolicyProvider() {
FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
observer_list_,
OnProviderGoingAway());
}
bool ConfigurationPolicyProvider::Provide(PolicyMap* result) {
#if !defined(OFFICIAL_BUILD)
if (override_policies_.get()) {
result->CopyFrom(*override_policies_);
return true;
}
#endif
return ProvideInternal(result);
}
bool ConfigurationPolicyProvider::IsInitializationComplete() const {
return true;
}
#if !defined(OFFICIAL_BUILD)
void ConfigurationPolicyProvider::OverridePolicies(PolicyMap* policies) {
override_policies_.reset(policies);
NotifyPolicyUpdated();
}
#endif
void ConfigurationPolicyProvider::NotifyPolicyUpdated() {
FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer,
observer_list_,
OnUpdatePolicy());
}
void ConfigurationPolicyProvider::AddObserver(Observer* observer) {
observer_list_.AddObserver(observer);
}
void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) {
observer_list_.RemoveObserver(observer);
}
// Class ConfigurationPolicyObserverRegistrar.
ConfigurationPolicyObserverRegistrar::ConfigurationPolicyObserverRegistrar()
: provider_(NULL),
observer_(NULL) {}
ConfigurationPolicyObserverRegistrar::~ConfigurationPolicyObserverRegistrar() {
if (provider_)
provider_->RemoveObserver(this);
}
void ConfigurationPolicyObserverRegistrar::Init(
ConfigurationPolicyProvider* provider,
ConfigurationPolicyProvider::Observer* observer) {
provider_ = provider;
observer_ = observer;
provider_->AddObserver(this);
}
void ConfigurationPolicyObserverRegistrar::OnUpdatePolicy() {
observer_->OnUpdatePolicy();
}
void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway() {
observer_->OnProviderGoingAway();
provider_->RemoveObserver(this);
provider_ = NULL;
}
} // namespace policy
|