OLD | NEW |
---|---|
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 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/memory/weak_ptr.h" | |
14 #include "base/observer_list.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_bundle.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 |
21 class PolicyMap; | 22 class PolicyMap; |
22 | 23 |
23 class PolicyServiceImpl : public PolicyService, | 24 class PolicyServiceImpl : public PolicyService, |
(...skipping 16 matching lines...) Expand all Loading... | |
40 virtual const PolicyMap& GetPolicies( | 41 virtual const PolicyMap& GetPolicies( |
41 PolicyDomain domain, | 42 PolicyDomain domain, |
42 const std::string& component_id) const OVERRIDE; | 43 const std::string& component_id) const OVERRIDE; |
43 virtual bool IsInitializationComplete() const OVERRIDE; | 44 virtual bool IsInitializationComplete() const OVERRIDE; |
44 virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE; | 45 virtual void RefreshPolicies(const base::Closure& callback) OVERRIDE; |
45 | 46 |
46 private: | 47 private: |
47 typedef ObserverList<PolicyService::Observer, true> Observers; | 48 typedef ObserverList<PolicyService::Observer, true> Observers; |
48 typedef std::map<PolicyDomain, Observers*> ObserverMap; | 49 typedef std::map<PolicyDomain, Observers*> ObserverMap; |
49 | 50 |
51 // Information about policy changes sent to observers. | |
52 class PolicyChangeInfo { | |
53 public: | |
54 PolicyChangeInfo(const PolicyBundle::PolicyNamespace& policy_namespace, | |
55 const PolicyMap& previous, const PolicyMap& current); | |
56 ~PolicyChangeInfo(); | |
57 | |
58 PolicyBundle::PolicyNamespace policy_namespace_; | |
59 PolicyMap previous_; | |
60 PolicyMap current_; | |
61 }; | |
62 | |
63 | |
Joao da Silva
2013/01/07 09:23:52
nit: single newline
Andrew T Wilson (Slow)
2013/01/07 14:11:32
Done.
| |
50 // ConfigurationPolicyProvider::Observer overrides: | 64 // ConfigurationPolicyProvider::Observer overrides: |
51 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE; | 65 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE; |
52 | 66 |
53 // Notifies observers of |ns| that its policies have changed, passing along | 67 // Posts a task to notify observers of |ns| that its policies have changed, |
54 // the |previous| and the |current| policies. | 68 // passing along the |previous| and the |current| policies. |
55 void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns, | 69 void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns, |
56 const PolicyMap& previous, | 70 const PolicyMap& previous, |
57 const PolicyMap& current); | 71 const PolicyMap& current); |
58 | 72 |
73 // Helper function invoked by NotifyNamespaceUpdated() to notify observers | |
74 // via a queued task, to deal with reentrancy issues caused by observers | |
75 // generating policy changes. | |
76 void NotifyNamespaceUpdatedTask(scoped_ptr<PolicyChangeInfo> info); | |
77 | |
59 // Combines the policies from all the providers, and notifies the observers | 78 // Combines the policies from all the providers, and notifies the observers |
60 // of namespaces whose policies have been modified. | 79 // of namespaces whose policies have been modified. |
61 void MergeAndTriggerUpdates(); | 80 void MergeAndTriggerUpdates(); |
62 | 81 |
63 // Checks if all providers are initialized, and notifies the observers | 82 // Checks if all providers are initialized, and notifies the observers |
64 // if the service just became initialized. | 83 // if the service just became initialized. |
65 void CheckInitializationComplete(); | 84 void CheckInitializationComplete(); |
66 | 85 |
67 // Invokes all the refresh callbacks if there are no more refreshes pending. | 86 // Invokes all the refresh callbacks if there are no more refreshes pending. |
68 void CheckRefreshComplete(); | 87 void CheckRefreshComplete(); |
(...skipping 11 matching lines...) Expand all Loading... | |
80 bool initialization_complete_; | 99 bool initialization_complete_; |
81 | 100 |
82 // Set of providers that have a pending update that was triggered by a | 101 // Set of providers that have a pending update that was triggered by a |
83 // call to RefreshPolicies(). | 102 // call to RefreshPolicies(). |
84 std::set<ConfigurationPolicyProvider*> refresh_pending_; | 103 std::set<ConfigurationPolicyProvider*> refresh_pending_; |
85 | 104 |
86 // List of callbacks to invoke once all providers refresh after a | 105 // List of callbacks to invoke once all providers refresh after a |
87 // RefreshPolicies() call. | 106 // RefreshPolicies() call. |
88 std::vector<base::Closure> refresh_callbacks_; | 107 std::vector<base::Closure> refresh_callbacks_; |
89 | 108 |
109 // Used to create tasks to delay new policy updates while we may be already | |
110 // processing previous policy updates. | |
111 base::WeakPtrFactory<PolicyServiceImpl> weak_ptr_factory_; | |
112 | |
90 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl); | 113 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl); |
91 }; | 114 }; |
92 | 115 |
93 } // namespace policy | 116 } // namespace policy |
94 | 117 |
95 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ | 118 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ |
OLD | NEW |