OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/observer_list.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/policy/configuration_policy_provider.h" | 16 #include "chrome/browser/policy/configuration_policy_provider.h" |
17 #include "chrome/browser/policy/configuration_policy_store_interface.h" | 17 #include "chrome/browser/policy/configuration_policy_store_interface.h" |
| 18 #include "chrome/common/notification_observer.h" |
| 19 #include "chrome/common/notification_registrar.h" |
18 #include "chrome/common/pref_store.h" | 20 #include "chrome/common/pref_store.h" |
19 | 21 |
20 class Profile; | 22 class Profile; |
21 | 23 |
22 namespace policy { | 24 namespace policy { |
23 | 25 |
24 // An implementation of the |PrefStore| that holds a Dictionary | 26 class ConfigurationPolicyPrefKeeper; |
25 // created through applied policy. | 27 |
| 28 // An implementation of PrefStore that bridges policy settings as read from a |
| 29 // ConfigurationPolicyProvider to preferences. |
26 class ConfigurationPolicyPrefStore : public PrefStore, | 30 class ConfigurationPolicyPrefStore : public PrefStore, |
27 public ConfigurationPolicyStoreInterface { | 31 public NotificationObserver { |
28 public: | 32 public: |
29 typedef std::set<const char*> ProxyPreferenceSet; | |
30 | |
31 // The ConfigurationPolicyPrefStore does not take ownership of the | 33 // The ConfigurationPolicyPrefStore does not take ownership of the |
32 // passed-in |provider|. | 34 // passed-in |provider|. |
33 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); | 35 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); |
34 virtual ~ConfigurationPolicyPrefStore(); | 36 virtual ~ConfigurationPolicyPrefStore(); |
35 | 37 |
36 // PrefStore methods: | 38 // PrefStore methods: |
| 39 virtual void AddObserver(Observer* observer); |
| 40 virtual void RemoveObserver(Observer* observer); |
| 41 virtual bool IsInitializationComplete() const; |
37 virtual ReadResult GetValue(const std::string& key, Value** result) const; | 42 virtual ReadResult GetValue(const std::string& key, Value** result) const; |
38 | 43 |
39 virtual DictionaryValue* prefs() const; | |
40 | |
41 // ConfigurationPolicyStore methods: | |
42 virtual void Apply(ConfigurationPolicyType setting, Value* value); | |
43 | |
44 // Creates a ConfigurationPolicyPrefStore that reads managed platform policy. | 44 // Creates a ConfigurationPolicyPrefStore that reads managed platform policy. |
45 static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore(); | 45 static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore(); |
46 | 46 |
47 // Creates a ConfigurationPolicyPrefStore that supplies policy from | 47 // Creates a ConfigurationPolicyPrefStore that supplies policy from |
48 // the device management server. | 48 // the device management server. |
49 static ConfigurationPolicyPrefStore* CreateDeviceManagementPolicyPrefStore( | 49 static ConfigurationPolicyPrefStore* CreateDeviceManagementPolicyPrefStore( |
50 Profile* profile); | 50 Profile* profile); |
51 | 51 |
52 // Creates a ConfigurationPolicyPrefStore that reads recommended policy. | 52 // Creates a ConfigurationPolicyPrefStore that reads recommended policy. |
53 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); | 53 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); |
54 | 54 |
55 // Returns the default policy definition list for Chrome. | 55 // Returns the default policy definition list for Chrome. |
56 static const ConfigurationPolicyProvider::PolicyDefinitionList* | 56 static const ConfigurationPolicyProvider::PolicyDefinitionList* |
57 GetChromePolicyDefinitionList(); | 57 GetChromePolicyDefinitionList(); |
58 | 58 |
59 private: | 59 private: |
60 // Policies that map to a single preference are handled | 60 // TODO(mnissler): Remove after provider has proper observer interface. |
61 // by an automated converter. Each one of these policies | 61 // NotificationObserver overrides: |
62 // has an entry in |simple_policy_map_| with the following type. | 62 void Observe(NotificationType type, |
63 struct PolicyToPreferenceMapEntry { | 63 const NotificationSource& source, |
64 Value::ValueType value_type; | 64 const NotificationDetails& details); |
65 ConfigurationPolicyType policy_type; | |
66 const char* preference_path; // A DictionaryValue path, not a file path. | |
67 }; | |
68 | 65 |
69 static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; | 66 // Refreshes policy information, rereading policy from the provider and |
70 static const PolicyToPreferenceMapEntry kProxyPolicyMap[]; | 67 // sending out change notifications as appropriate. |
71 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[]; | 68 void Refresh(); |
| 69 |
72 static const ConfigurationPolicyProvider::PolicyDefinitionList | 70 static const ConfigurationPolicyProvider::PolicyDefinitionList |
73 kPolicyDefinitionList; | 71 kPolicyDefinitionList; |
74 | 72 |
| 73 // The policy provider from which policy settings are read. |
75 ConfigurationPolicyProvider* provider_; | 74 ConfigurationPolicyProvider* provider_; |
76 scoped_ptr<DictionaryValue> prefs_; | |
77 | 75 |
78 // Temporary cache that stores values until FinalizeProxyPolicySettings() | 76 // Initialization status as reported by the policy provider the last time we |
79 // is called. | 77 // queried it. |
80 std::map<ConfigurationPolicyType, Value*> proxy_policies_; | 78 bool initialization_complete_; |
81 | 79 |
82 bool HasProxyPolicy(ConfigurationPolicyType policy) const; | 80 // Current policy preferences. |
| 81 scoped_ptr<ConfigurationPolicyPrefKeeper> policy_keeper_; |
83 | 82 |
84 // Returns the map entry that corresponds to |policy| in the map. | 83 // TODO(mnissler): Remove after provider has proper observer interface. |
85 const PolicyToPreferenceMapEntry* FindPolicyInMap( | 84 NotificationRegistrar registrar_; |
86 ConfigurationPolicyType policy, | |
87 const PolicyToPreferenceMapEntry* map, | |
88 int size) const; | |
89 | 85 |
90 // Remove the preferences found in the map from |prefs_|. Returns true if | 86 ObserverList<Observer, true> observers_; |
91 // any such preferences were found and removed. | |
92 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map, | |
93 int table_size); | |
94 | |
95 bool ApplyPolicyFromMap(ConfigurationPolicyType policy, | |
96 Value* value, | |
97 const PolicyToPreferenceMapEntry* map, | |
98 int size); | |
99 | |
100 // Processes proxy-specific policies. Returns true if the specified policy | |
101 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership | |
102 // of |value| in the case that the policy is proxy-specific. | |
103 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value); | |
104 | |
105 // Handles sync-related policies. Returns true if the policy was handled. | |
106 // Assumes ownership of |value| in that case. | |
107 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value); | |
108 | |
109 // Handles policies that affect AutoFill. Returns true if the policy was | |
110 // handled and assumes ownership of |value| in that case. | |
111 bool ApplyAutoFillPolicy(ConfigurationPolicyType policy, Value* value); | |
112 | |
113 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
114 // a blank string. | |
115 void EnsureStringPrefExists(const std::string& path); | |
116 | |
117 // If the required entries for default search are specified and valid, | |
118 // finalizes the policy-specified configuration by initializing the | |
119 // unspecified map entries. Otherwise wipes all default search related | |
120 // map entries from |prefs_|. | |
121 void FinalizeDefaultSearchPolicySettings(); | |
122 | |
123 // If the required entries for the proxy settings are specified and valid, | |
124 // finalizes the policy-specified configuration by initializing the | |
125 // respective values in |prefs_|. | |
126 void FinalizeProxyPolicySettings(); | |
127 | |
128 // Returns true if the policy values stored in proxy_* represent a valid | |
129 // proxy configuration. | |
130 bool CheckProxySettings(); | |
131 | |
132 // Assumes CheckProxySettings returns true and applies the values stored | |
133 // in proxy_*. | |
134 void ApplyProxySettings(); | |
135 | 87 |
136 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); | 88 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); |
137 }; | 89 }; |
138 | 90 |
139 } // namespace policy | 91 } // namespace policy |
140 | 92 |
141 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ | 93 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ |
OLD | NEW |