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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h"
13 #include "base/prefs/pref_store.h"
14 #include "base/values.h"
15 #include "chrome/browser/policy/policy_map.h"
16 #include "chrome/browser/policy/policy_service.h"
17 #include "chrome/browser/policy/policy_types.h"
23 class ConfigurationPolicyHandlerList;
25 // An implementation of PrefStore that bridges policy settings as read from the
26 // PolicyService to preferences. Converts POLICY_DOMAIN_CHROME policies a given
27 // PolicyLevel to their corresponding preferences.
28 class ConfigurationPolicyPrefStore
30 public PolicyService::Observer {
32 // Does not take ownership of |service| nor |handler_list|, which must outlive
33 // the store. Only policies of the given |level| will be mapped.
34 ConfigurationPolicyPrefStore(
35 PolicyService* service,
36 const ConfigurationPolicyHandlerList* handler_list,
40 virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE;
41 virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE;
42 virtual bool HasObservers() const OVERRIDE;
43 virtual bool IsInitializationComplete() const OVERRIDE;
44 virtual bool GetValue(const std::string& key,
45 const Value** result) const OVERRIDE;
47 // PolicyService::Observer methods:
48 virtual void OnPolicyUpdated(const PolicyNamespace& ns,
49 const PolicyMap& previous,
50 const PolicyMap& current) OVERRIDE;
51 virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE;
54 virtual ~ConfigurationPolicyPrefStore();
56 // Refreshes policy information, rereading policy from the policy service and
57 // sending out change notifications as appropriate.
60 // Returns a new PrefValueMap containing the preference values that correspond
61 // to the policies currently provided by the policy service.
62 PrefValueMap* CreatePreferencesFromPolicies();
64 // The PolicyService from which policy settings are read.
65 PolicyService* policy_service_;
67 // The policy handlers used to convert policies into their corresponding
69 const ConfigurationPolicyHandlerList* handler_list_;
71 // The policy level that this PrefStore uses.
74 // Current policy preferences.
75 scoped_ptr<PrefValueMap> prefs_;
77 ObserverList<PrefStore::Observer, true> observers_;
79 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore);
84 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_