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
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
#define CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
#pragma once
#include <map>
#include <set>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/observer_list.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/policy_bundle.h"
#include "chrome/browser/policy/policy_service.h"
namespace policy {
class PolicyMap;
class PolicyServiceImpl : public PolicyService,
public ConfigurationPolicyProvider::Observer {
public:
typedef std::vector<ConfigurationPolicyProvider*> Providers;
// The PolicyServiceImpl will merge policies from |providers|. |providers|
// must be sorted in decreasing order of priority; the first provider will
// have the highest priority. The PolicyServiceImpl does not take ownership of
// the providers, but handles OnProviderGoingAway() if they are destroyed.
explicit PolicyServiceImpl(const Providers& providers);
virtual ~PolicyServiceImpl();
// PolicyService overrides:
virtual void AddObserver(PolicyDomain domain,
const std::string& component_id,
PolicyService::Observer* observer) OVERRIDE;
virtual void RemoveObserver(PolicyDomain domain,
const std::string& component_id,
PolicyService::Observer* observer) OVERRIDE;
virtual const PolicyMap& GetPolicies(
PolicyDomain domain,
const std::string& component_id) const OVERRIDE;
virtual bool IsInitializationComplete() const OVERRIDE;
virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE;
private:
typedef ObserverList<PolicyService::Observer, true> Observers;
typedef std::map<PolicyBundle::PolicyNamespace, Observers*> ObserverMap;
typedef std::vector<ConfigurationPolicyObserverRegistrar*> RegistrarList;
// ConfigurationPolicyProvider::Observer overrides:
virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE;
virtual void OnProviderGoingAway(
ConfigurationPolicyProvider* provider) OVERRIDE;
// Returns an iterator to the entry in |registrars_| that corresponds to
// |provider|, or |registrars_.end()|.
RegistrarList::iterator GetRegistrar(ConfigurationPolicyProvider* provider);
// Notifies observers of |ns| that its policies have changed, passing along
// the |previous| and the |current| policies.
void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns,
const PolicyMap& previous,
const PolicyMap& current);
// Combines the policies from all the providers, and notifies the observers
// of namespaces whose policies have been modified.
void MergeAndTriggerUpdates();
// Checks if all providers are initialized, and notifies the observers
// if the service just became initialized.
void CheckInitializationComplete();
// Invokes all the refresh callbacks if there are no more refreshes pending.
void CheckRefreshComplete();
// Contains a registrar for each of the providers passed in the constructor,
// in order of decreasing priority.
RegistrarList registrars_;
// Maps each policy namespace to its current policies.
PolicyBundle policy_bundle_;
// Maps each policy namespace to its observer list.
ObserverMap observers_;
// True if all the providers are initialized.
bool initialization_complete_;
// Set of providers that have a pending update that was triggered by a
// call to RefreshPolicies().
std::set<ConfigurationPolicyProvider*> refresh_pending_;
// List of callbacks to invoke once all providers refresh after a
// RefreshPolicies() call.
std::vector<base::Closure> refresh_callbacks_;
DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
|