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