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

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

Issue 11667006: Create a list of policy changes before notifying observers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another ToT merge Created 7 years, 11 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
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 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
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
50 // ConfigurationPolicyProvider::Observer overrides: 63 // ConfigurationPolicyProvider::Observer overrides:
51 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE; 64 virtual void OnUpdatePolicy(ConfigurationPolicyProvider* provider) OVERRIDE;
52 65
53 // Notifies observers of |ns| that its policies have changed, passing along 66 // Posts a task to notify observers of |ns| that its policies have changed,
54 // the |previous| and the |current| policies. 67 // passing along the |previous| and the |current| policies.
55 void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns, 68 void NotifyNamespaceUpdated(const PolicyBundle::PolicyNamespace& ns,
56 const PolicyMap& previous, 69 const PolicyMap& previous,
57 const PolicyMap& current); 70 const PolicyMap& current);
58 71
72 // Helper function invoked by NotifyNamespaceUpdated() to notify observers
73 // via a queued task, to deal with reentrancy issues caused by observers
74 // generating policy changes.
75 void NotifyNamespaceUpdatedTask(scoped_ptr<PolicyChangeInfo> info);
76
59 // Combines the policies from all the providers, and notifies the observers 77 // Combines the policies from all the providers, and notifies the observers
60 // of namespaces whose policies have been modified. 78 // of namespaces whose policies have been modified.
61 void MergeAndTriggerUpdates(); 79 void MergeAndTriggerUpdates();
62 80
63 // Checks if all providers are initialized, and notifies the observers 81 // Checks if all providers are initialized, and notifies the observers
64 // if the service just became initialized. 82 // if the service just became initialized.
65 void CheckInitializationComplete(); 83 void CheckInitializationComplete();
66 84
67 // Invokes all the refresh callbacks if there are no more refreshes pending. 85 // Invokes all the refresh callbacks if there are no more refreshes pending.
68 void CheckRefreshComplete(); 86 void CheckRefreshComplete();
(...skipping 11 matching lines...) Expand all
80 bool initialization_complete_; 98 bool initialization_complete_;
81 99
82 // Set of providers that have a pending update that was triggered by a 100 // Set of providers that have a pending update that was triggered by a
83 // call to RefreshPolicies(). 101 // call to RefreshPolicies().
84 std::set<ConfigurationPolicyProvider*> refresh_pending_; 102 std::set<ConfigurationPolicyProvider*> refresh_pending_;
85 103
86 // List of callbacks to invoke once all providers refresh after a 104 // List of callbacks to invoke once all providers refresh after a
87 // RefreshPolicies() call. 105 // RefreshPolicies() call.
88 std::vector<base::Closure> refresh_callbacks_; 106 std::vector<base::Closure> refresh_callbacks_;
89 107
108 // Used to create tasks to delay new policy updates while we may be already
109 // processing previous policy updates.
110 base::WeakPtrFactory<PolicyServiceImpl> weak_ptr_factory_;
111
90 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl); 112 DISALLOW_COPY_AND_ASSIGN(PolicyServiceImpl);
91 }; 113 };
92 114
93 } // namespace policy 115 } // namespace policy
94 116
95 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_ 117 #endif // CHROME_BROWSER_POLICY_POLICY_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_prefs_browsertest.cc ('k') | chrome/browser/policy/policy_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698