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_CONFIGURATION_POLICY_PREF_STORE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ |
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ | 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "base/prefs/pref_store.h" | 13 #include "base/prefs/pref_store.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
16 #include "chrome/browser/policy/policy_service.h" | 16 #include "chrome/browser/policy/policy_service.h" |
17 | 17 |
18 class PrefValueMap; | 18 class PrefValueMap; |
19 | 19 |
20 namespace policy { | 20 namespace policy { |
21 | 21 |
22 class ConfigurationPolicyHandlerList; | |
23 | |
22 // An implementation of PrefStore that bridges policy settings as read from the | 24 // An implementation of PrefStore that bridges policy settings as read from the |
23 // PolicyService to preferences. Converts POLICY_DOMAIN_CHROME policies a given | 25 // PolicyService to preferences. Converts POLICY_DOMAIN_CHROME policies a given |
24 // PolicyLevel to their corresponding preferences. | 26 // PolicyLevel to their corresponding preferences. |
25 class ConfigurationPolicyPrefStore | 27 class ConfigurationPolicyPrefStore |
26 : public PrefStore, | 28 : public PrefStore, |
27 public PolicyService::Observer { | 29 public PolicyService::Observer { |
28 public: | 30 public: |
29 // Does not take ownership of |service|. Only policies of the given |level| | 31 // Does not take ownership of |service| nor |handler_list|, which must outlive |
30 // will be mapped. | 32 // the store.. Only policies of the given |level| will be mapped. |
Mattias Nissler (ping if slow)
2013/08/12 13:38:28
nit: One period is enough.
Joao da Silva
2013/08/12 15:41:55
Done.
| |
31 ConfigurationPolicyPrefStore(PolicyService* service, PolicyLevel level); | 33 ConfigurationPolicyPrefStore( |
34 PolicyService* service, | |
35 const ConfigurationPolicyHandlerList* handler_list, | |
36 PolicyLevel level); | |
bartfab (slow)
2013/08/12 13:27:53
Nit: #include "chrome/browser/policy/policy_types.
Joao da Silva
2013/08/12 15:41:55
Done.
| |
32 | 37 |
33 // PrefStore methods: | 38 // PrefStore methods: |
34 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; | 39 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE; |
35 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; | 40 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE; |
36 virtual size_t NumberOfObservers() const OVERRIDE; | 41 virtual size_t NumberOfObservers() const OVERRIDE; |
37 virtual bool IsInitializationComplete() const OVERRIDE; | 42 virtual bool IsInitializationComplete() const OVERRIDE; |
38 virtual bool GetValue(const std::string& key, | 43 virtual bool GetValue(const std::string& key, |
39 const Value** result) const OVERRIDE; | 44 const Value** result) const OVERRIDE; |
40 | 45 |
41 // PolicyService::Observer methods: | 46 // PolicyService::Observer methods: |
42 virtual void OnPolicyUpdated(const PolicyNamespace& ns, | 47 virtual void OnPolicyUpdated(const PolicyNamespace& ns, |
43 const PolicyMap& previous, | 48 const PolicyMap& previous, |
44 const PolicyMap& current) OVERRIDE; | 49 const PolicyMap& current) OVERRIDE; |
45 virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; | 50 virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; |
46 | 51 |
47 // Creates a ConfigurationPolicyPrefStore that only provides policies that | |
48 // have POLICY_LEVEL_MANDATORY level. | |
49 static ConfigurationPolicyPrefStore* CreateMandatoryPolicyPrefStore( | |
50 PolicyService* policy_service); | |
51 | |
52 // Creates a ConfigurationPolicyPrefStore that only provides policies that | |
53 // have POLICY_LEVEL_RECOMMENDED level. | |
54 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore( | |
55 PolicyService* policy_service); | |
56 | |
57 private: | 52 private: |
58 virtual ~ConfigurationPolicyPrefStore(); | 53 virtual ~ConfigurationPolicyPrefStore(); |
59 | 54 |
60 // Refreshes policy information, rereading policy from the policy service and | 55 // Refreshes policy information, rereading policy from the policy service and |
61 // sending out change notifications as appropriate. | 56 // sending out change notifications as appropriate. |
62 void Refresh(); | 57 void Refresh(); |
63 | 58 |
64 // Returns a new PrefValueMap containing the preference values that correspond | 59 // Returns a new PrefValueMap containing the preference values that correspond |
65 // to the policies currently provided by the policy service. | 60 // to the policies currently provided by the policy service. |
66 PrefValueMap* CreatePreferencesFromPolicies(); | 61 PrefValueMap* CreatePreferencesFromPolicies(); |
67 | 62 |
68 // The PolicyService from which policy settings are read. | 63 // The PolicyService from which policy settings are read. |
69 PolicyService* policy_service_; | 64 PolicyService* policy_service_; |
70 | 65 |
66 // The policy handlers used to convert policies into their corresponding | |
67 // preferences. | |
68 const ConfigurationPolicyHandlerList* handler_list_; | |
69 | |
71 // The policy level that this PrefStore uses. | 70 // The policy level that this PrefStore uses. |
72 PolicyLevel level_; | 71 PolicyLevel level_; |
73 | 72 |
74 // Current policy preferences. | 73 // Current policy preferences. |
75 scoped_ptr<PrefValueMap> prefs_; | 74 scoped_ptr<PrefValueMap> prefs_; |
76 | 75 |
77 ObserverList<PrefStore::Observer, true> observers_; | 76 ObserverList<PrefStore::Observer, true> observers_; |
78 | 77 |
79 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); | 78 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); |
80 }; | 79 }; |
81 | 80 |
82 } // namespace policy | 81 } // namespace policy |
83 | 82 |
84 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ | 83 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ |
OLD | NEW |