Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/policy/policy_service_impl.h

Issue 10386097: Refactored ConfigurationPolicyProvider to provide PolicyBundles instead of PolicyMaps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/policy_service.h ('k') | chrome/browser/policy/policy_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ 5 #ifndef CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ 6 #define CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set>
10 #include <string> 11 #include <string>
11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/observer_list.h"
15 #include "chrome/browser/policy/configuration_policy_provider.h" 16 #include "chrome/browser/policy/configuration_policy_provider.h"
16 #include "chrome/browser/policy/policy_map.h" 17 #include "chrome/browser/policy/policy_bundle.h"
17 #include "chrome/browser/policy/policy_service.h" 18 #include "chrome/browser/policy/policy_service.h"
18 19
19 namespace policy { 20 namespace policy {
20 21
22 class PolicyMap;
23
21 class PolicyServiceImpl : public PolicyService, 24 class PolicyServiceImpl : public PolicyService,
22 public ConfigurationPolicyProvider::Observer { 25 public ConfigurationPolicyProvider::Observer {
23 public: 26 public:
24 typedef std::vector<ConfigurationPolicyProvider*> Providers; 27 typedef std::vector<ConfigurationPolicyProvider*> Providers;
25 28
26 // The PolicyServiceImpl will merge policies from |providers|. |providers| 29 // The PolicyServiceImpl will merge policies from |providers|. |providers|
27 // must be sorted in decreasing order of priority; the first provider will 30 // must be sorted in decreasing order of priority; the first provider will
28 // have the highest priority. The PolicyServiceImpl does not take ownership of 31 // have the highest priority. The PolicyServiceImpl does not take ownership of
29 // the providers, but handles OnProviderGoingAway() if they are destroyed. 32 // the providers, but handles OnProviderGoingAway() if they are destroyed.
30 explicit PolicyServiceImpl(const Providers& providers); 33 explicit PolicyServiceImpl(const Providers& providers);
31 virtual ~PolicyServiceImpl(); 34 virtual ~PolicyServiceImpl();
32 35
33 // PolicyService overrides: 36 // PolicyService overrides:
34 virtual void AddObserver(PolicyDomain domain, 37 virtual void AddObserver(PolicyDomain domain,
35 const std::string& component_id, 38 const std::string& component_id,
36 PolicyService::Observer* observer) OVERRIDE; 39 PolicyService::Observer* observer) OVERRIDE;
37 virtual void RemoveObserver(PolicyDomain domain, 40 virtual void RemoveObserver(PolicyDomain domain,
38 const std::string& component_id, 41 const std::string& component_id,
39 PolicyService::Observer* observer) OVERRIDE; 42 PolicyService::Observer* observer) OVERRIDE;
40 virtual const PolicyMap* GetPolicies( 43 virtual const PolicyMap& GetPolicies(
41 PolicyDomain domain, 44 PolicyDomain domain,
42 const std::string& component_id) const OVERRIDE; 45 const std::string& component_id) const OVERRIDE;
43 virtual bool IsInitializationComplete() const OVERRIDE; 46 virtual bool IsInitializationComplete() const OVERRIDE;
44 virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE; 47 virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE;
45 48
46 private: 49 private:
47 struct Entry; 50 typedef ObserverList<PolicyService::Observer, true> Observers;
48 struct ProviderData; 51 typedef std::map<PolicyBundle::PolicyNamespace, Observers*> ObserverMap;
49 52 typedef std::vector<ConfigurationPolicyObserverRegistrar*> RegistrarList;
50 typedef std::pair<PolicyDomain, std::string> PolicyNamespace;
51 typedef std::map<PolicyNamespace, Entry*> EntryMap;
52 typedef std::vector<ProviderData*> ProviderList;
53 53
54 // ConfigurationPolicyProvider::Observer overrides: 54 // ConfigurationPolicyProvider::Observer overrides:
55 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE; 55 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE;
56 virtual void OnProviderGoingAway( 56 virtual void OnProviderGoingAway(
57 ConfigurationPolicyProvider* provider) OVERRIDE; 57 ConfigurationPolicyProvider* provider) OVERRIDE;
58 58
59 Entry* GetOrCreate(const PolicyNamespace& ns); 59 // Returns an iterator to the entry in |registrars_| that corresponds to
60 ProviderList::iterator GetProviderData(ConfigurationPolicyProvider* provider); 60 // |provider|, or |registrars_.end()|.
61 RegistrarList::iterator GetRegistrar(ConfigurationPolicyProvider* provider);
61 62
62 // Erases the entry for |ns|, if it has no observers and no policies. 63 // Notifies observers of |ns| that its policies have changed, passing along
63 void MaybeCleanup(const PolicyNamespace& ns); 64 // the |previous| and the |current| policies.
65 void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns,
66 const PolicyMap& previous,
67 const PolicyMap& current);
64 68
65 // Combines the policies from all the providers, and notifies the observers 69 // Combines the policies from all the providers, and notifies the observers
66 // of namespaces whose policies have been modified. 70 // of namespaces whose policies have been modified.
67 // |is_refresh| should be true if MergeAndTriggerUpdates() was invoked because 71 void MergeAndTriggerUpdates();
68 // a provider has just refreshed its policies.
69 void MergeAndTriggerUpdates(bool is_refresh);
70 72
71 // Contains all the providers together with a cached copy of their policies 73 // Checks if all providers are initialized, and notifies the observers
72 // and their registrars. 74 // if the service just became initialized.
73 ProviderList providers_; 75 void CheckInitializationComplete();
76
77 // Invokes all the refresh callbacks if there are no more refreshes pending.
78 void CheckRefreshComplete();
79
80 // Contains a registrar for each of the providers passed in the constructor,
81 // in order of decreasing priority.
82 RegistrarList registrars_;
74 83
75 // Maps each policy namespace to its current policies. 84 // Maps each policy namespace to its current policies.
76 EntryMap entries_; 85 PolicyBundle policy_bundle_;
86
87 // Maps each policy namespace to its observer list.
88 ObserverMap observers_;
77 89
78 // True if all the providers are initialized. 90 // True if all the providers are initialized.
79 bool initialization_complete_; 91 bool initialization_complete_;
80 92
93 // Set of providers that have a pending update that was triggered by a
94 // call to RefreshPolicies().
95 std::set<ConfigurationPolicyProvider*> refresh_pending_;
96
81 // List of callbacks to invoke once all providers refresh after a 97 // List of callbacks to invoke once all providers refresh after a
82 // RefreshPolicies() call. 98 // RefreshPolicies() call.
83 std::vector<base::Closure> refresh_callbacks_; 99 std::vector<base::Closure> refresh_callbacks_;
84 100
85 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl); 101 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl);
86 }; 102 };
87 103
88 } // namespace policy 104 } // namespace policy
89 105
90 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ 106 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_service.h ('k') | chrome/browser/policy/policy_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698