blob: 790393880e24fb03ee4a771f69ecba3d80142bcd (
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
|
// 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 <string>
#include <utility>
#include <vector>
#include "base/basictypes.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/policy_map.h"
#include "chrome/browser/policy/policy_service.h"
namespace policy {
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;
private:
struct Entry;
struct ProviderData;
typedef std::pair<PolicyDomain, std::string> PolicyNamespace;
typedef std::map<PolicyNamespace, Entry*> EntryMap;
typedef std::vector<ProviderData*> ProviderList;
// ConfigurationPolicyProvider::Observer overrides:
virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE;
virtual void OnProviderGoingAway(
ConfigurationPolicyProvider* provider) OVERRIDE;
Entry* GetOrCreate(const PolicyNamespace& ns);
ProviderList::iterator GetProviderData(ConfigurationPolicyProvider* provider);
// Erases the entry for |ns|, if it has no observers and no policies.
void MaybeCleanup(const PolicyNamespace& ns);
// Combines the policies from all the providers, and notifies the observers
// of namespaces whose policies have been modified.
void MergeAndTriggerUpdates();
// Contains all the providers together with a cached copy of their policies
// and their registrars.
ProviderList providers_;
// Maps each policy namespace to its current policies.
EntryMap entries_;
DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
|