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

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_provider.h

Issue 10832035: Switch from SignedSettings to DeviceSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 3 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_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
7 7
8 #include <deque>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/gtest_prod_util.h"
16 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/cros_settings_provider.h"
15 #include "chrome/browser/chromeos/settings/ownership_service.h" 18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
16 #include "chrome/browser/chromeos/settings/signed_settings_migration_helper.h" 19 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
17 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
18 #include "chrome/browser/prefs/pref_value_map.h" 20 #include "chrome/browser/prefs/pref_value_map.h"
19 #include "content/public/browser/notification_registrar.h" 21 #include "chrome/browser/prefs/pref_value_map.h"
20 22
21 namespace base { 23 namespace base {
22 class Value; 24 class Value;
23 } 25 }
24 26
25 namespace enterprise_management { 27 namespace enterprise_management {
26 class ChromeDeviceSettingsProto; 28 class ChromeDeviceSettingsProto;
27 } // namespace enterprise_management 29 } // namespace enterprise_management
28 30
29 namespace chromeos { 31 namespace chromeos {
30 32
31 // CrosSettingsProvider implementation that works with SignedSettings. 33 // CrosSettingsProvider implementation that works with device settings.
32 class DeviceSettingsProvider : public CrosSettingsProvider, 34 class DeviceSettingsProvider : public CrosSettingsProvider,
33 public content::NotificationObserver { 35 public DeviceSettingsService::Observer {
34 public: 36 public:
35 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb, 37 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb,
36 SignedSettingsHelper* signed_settings_helper); 38 DeviceSettingsService* device_settings_service);
37 virtual ~DeviceSettingsProvider(); 39 virtual ~DeviceSettingsProvider();
38 40
39 // CrosSettingsProvider implementation. 41 // CrosSettingsProvider implementation.
40 virtual const base::Value* Get(const std::string& path) const OVERRIDE; 42 virtual const base::Value* Get(const std::string& path) const OVERRIDE;
41 virtual TrustedStatus PrepareTrustedValues( 43 virtual TrustedStatus PrepareTrustedValues(
42 const base::Closure& callback) OVERRIDE; 44 const base::Closure& callback) OVERRIDE;
43 virtual bool HandlesSetting(const std::string& path) const OVERRIDE; 45 virtual bool HandlesSetting(const std::string& path) const OVERRIDE;
44 virtual void Reload() OVERRIDE;
45 46
46 private: 47 private:
47 // CrosSettingsProvider implementation: 48 // CrosSettingsProvider implementation:
48 virtual void DoSet(const std::string& path, 49 virtual void DoSet(const std::string& path,
49 const base::Value& value) OVERRIDE; 50 const base::Value& value) OVERRIDE;
50 51
51 // content::NotificationObserver implementation: 52 // DeviceSettingsService::Observer implementation:
52 virtual void Observe(int type, 53 virtual void OwnershipStatusChanged() OVERRIDE;
53 const content::NotificationSource& source, 54 virtual void DeviceSettingsUpdated() OVERRIDE;
54 const content::NotificationDetails& details) OVERRIDE;
55
56 const enterprise_management::PolicyData policy() const;
57 55
58 // Populates in-memory cache from the local_state cache that is used to store 56 // Populates in-memory cache from the local_state cache that is used to store
59 // signed settings before the device is owned and to speed up policy 57 // device settings before the device is owned and to speed up policy
60 // availability before the policy blob is fetched on boot. 58 // availability before the policy blob is fetched on boot.
61 void RetrieveCachedData(); 59 void RetrieveCachedData();
62 60
63 // Stores a value from the |pending_changes_| queue in the signed settings. 61 // Stores a value from the |pending_changes_| queue in the device settings.
64 // If the device is not owned yet the data ends up only in the local_state 62 // If the device is not owned yet the data ends up only in the local_state
65 // cache and is serialized once ownership is acquired. 63 // cache and is serialized once ownership is acquired.
66 void SetInPolicy(); 64 void SetInPolicy();
67 65
68 // Finalizes stores to the policy file if the cache is dirty.
69 void FinishSetInPolicy(
70 SignedSettings::ReturnCode code,
71 const enterprise_management::PolicyFetchResponse& policy);
72
73 // Decode the various groups of policies. 66 // Decode the various groups of policies.
74 void DecodeLoginPolicies( 67 void DecodeLoginPolicies(
75 const enterprise_management::ChromeDeviceSettingsProto& policy, 68 const enterprise_management::ChromeDeviceSettingsProto& policy,
76 PrefValueMap* new_values_cache) const; 69 PrefValueMap* new_values_cache) const;
77 void DecodeKioskPolicies( 70 void DecodeKioskPolicies(
78 const enterprise_management::ChromeDeviceSettingsProto& policy, 71 const enterprise_management::ChromeDeviceSettingsProto& policy,
79 PrefValueMap* new_values_cache) const; 72 PrefValueMap* new_values_cache) const;
80 void DecodeNetworkPolicies( 73 void DecodeNetworkPolicies(
81 const enterprise_management::ChromeDeviceSettingsProto& policy, 74 const enterprise_management::ChromeDeviceSettingsProto& policy,
82 PrefValueMap* new_values_cache) const; 75 PrefValueMap* new_values_cache) const;
83 void DecodeReportingPolicies( 76 void DecodeReportingPolicies(
84 const enterprise_management::ChromeDeviceSettingsProto& policy, 77 const enterprise_management::ChromeDeviceSettingsProto& policy,
85 PrefValueMap* new_values_cache) const; 78 PrefValueMap* new_values_cache) const;
86 void DecodeGenericPolicies( 79 void DecodeGenericPolicies(
87 const enterprise_management::ChromeDeviceSettingsProto& policy, 80 const enterprise_management::ChromeDeviceSettingsProto& policy,
88 PrefValueMap* new_values_cache) const; 81 PrefValueMap* new_values_cache) const;
89 82
90 // Parses the policy cache and fills the cache of base::Value objects. 83 // Parses the policy data and fills in |values_cache_|.
91 void UpdateValuesCache(); 84 void UpdateValuesCache(
85 const enterprise_management::PolicyData& policy_data,
86 const enterprise_management::ChromeDeviceSettingsProto& settings);
92 87
93 // Applies the metrics policy and if not set migrates the legacy file. 88 // Applies the metrics policy and if not set migrates the legacy file.
94 void ApplyMetricsSetting(bool use_file, bool new_value) const; 89 void ApplyMetricsSetting(bool use_file, bool new_value);
95 90
96 // Applies the data roaming policy. 91 // Applies the data roaming policy.
97 void ApplyRoamingSetting(bool new_value) const; 92 void ApplyRoamingSetting(bool new_value);
98 93
99 // Applies any changes of the policies that are not handled by the respective 94 // Applies any changes of the policies that are not handled by the respective
100 // subsystems. 95 // subsystems.
101 void ApplySideEffects() const; 96 void ApplySideEffects(
97 const enterprise_management::ChromeDeviceSettingsProto& settings);
102 98
103 // In case of missing policy blob we should verify if this is upgrade of 99 // In case of missing policy blob we should verify if this is upgrade of
104 // machine owned from pre version 12 OS and the user never touched the device 100 // machine owned from pre version 12 OS and the user never touched the device
105 // settings. In this case revert to defaults and let people in until the owner 101 // settings. In this case revert to defaults and let people in until the owner
106 // comes and changes that. 102 // comes and changes that.
107 bool MitigateMissingPolicy(); 103 bool MitigateMissingPolicy();
108 104
109 // Called right before boolean property is changed.
110 void OnBooleanPropertyChange(const std::string& path, bool new_value);
111
112 // Checks if the current cache value can be trusted for being representative 105 // Checks if the current cache value can be trusted for being representative
113 // for the disk cache. 106 // for the disk cache.
114 TrustedStatus RequestTrustedEntity(); 107 TrustedStatus RequestTrustedEntity();
115 108
116 // Called right after signed value was checked. 109 // Invokes UpdateFromService() to synchronize with |device_settings_service_|,
117 void OnPropertyRetrieve(const std::string& path, 110 // then triggers the next store operation if applicable.
118 const base::Value* value, 111 void UpdateAndProceedStoring();
119 bool use_default_value);
120 112
121 // Callback of StorePolicyOp for ordinary policy stores. 113 // Re-reads state from |device_settings_service_|, adjusts
122 void OnStorePolicyCompleted(SignedSettings::ReturnCode code); 114 // |trusted_status_| and calls UpdateValuesCache() if applicable. Returns true
115 // if new settings have been loaded.
116 bool UpdateFromService();
123 117
124 // Callback of RetrievePolicyOp for ordinary policy [re]loads. 118 // Sends |device_settings_| to |device_settings_service_| for signing and
125 void OnRetrievePolicyCompleted( 119 // storage in session_manager.
126 SignedSettings::ReturnCode code, 120 void StoreDeviceSettings();
127 const enterprise_management::PolicyFetchResponse& policy);
128 121
129 // These setters are for test use only. 122 // Checks the current ownership status to see whether the device owner is
130 void set_ownership_status(OwnershipService::Status status) { 123 // logged in and writes the data accumulated in |migration_values_| to proper
131 ownership_status_ = status; 124 // device settings.
132 } 125 void AttemptMigration();
133 void set_trusted_status(TrustedStatus status) {
134 trusted_status_ = status;
135 }
136 void set_retries_left(int retries) {
137 retries_left_ = retries;
138 }
139 126
140 // Pending callbacks that need to be invoked after settings verification. 127 // Pending callbacks that need to be invoked after settings verification.
141 std::vector<base::Closure> callbacks_; 128 std::vector<base::Closure> callbacks_;
142 129
143 SignedSettingsHelper* signed_settings_helper_; 130 DeviceSettingsService* device_settings_service_;
144 OwnershipService::Status ownership_status_; 131 mutable PrefValueMap migration_values_;
145 mutable scoped_ptr<SignedSettingsMigrationHelper> migration_helper_;
146 132
147 content::NotificationRegistrar registrar_; 133 TrustedStatus trusted_status_;
134 DeviceSettingsService::OwnershipStatus ownership_status_;
148 135
149 // In order to guard against occasional failure to fetch a property 136 // The device settings as currently reported through the CrosSettingsProvider
150 // we allow for some number of retries. 137 // interface. This may be different from the actual current device settings
151 int retries_left_; 138 // (which can be obtained from |device_settings_service_|) in case the device
139 // does not have an owner yet or there are pending changes that have not yet
140 // been written to session_manager.
141 enterprise_management::ChromeDeviceSettingsProto device_settings_;
152 142
153 enterprise_management::PolicyData policy_; 143 // A cache of values, indexed by the settings keys served through the
154 TrustedStatus trusted_status_; 144 // CrosSettingsProvider interface. This is always kept in sync with the raw
155 145 // data found in |device_settings_|.
156 PrefValueMap values_cache_; 146 PrefValueMap values_cache_;
157 147
158 // This is a queue for set requests, because those need to be sequential. 148 // This is a queue for set requests, because those need to be sequential.
159 typedef std::pair<std::string, base::Value*> PendingQueueElement; 149 typedef std::pair<std::string, base::Value*> PendingQueueElement;
160 std::vector<PendingQueueElement> pending_changes_; 150 std::deque<PendingQueueElement> pending_changes_;
151
152 // Weak pointer factory for creating store operation callbacks.
153 base::WeakPtrFactory<DeviceSettingsProvider> store_callback_factory_;
161 154
162 friend class DeviceSettingsProviderTest; 155 friend class DeviceSettingsProviderTest;
163 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, 156 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
164 InitializationTestUnowned); 157 InitializationTestUnowned);
165 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, 158 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest,
166 PolicyFailedPermanentlyNotification); 159 PolicyFailedPermanentlyNotification);
167 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification); 160 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, PolicyLoadNotification);
168 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); 161 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider);
169 }; 162 };
170 163
171 } // namespace chromeos 164 } // namespace chromeos
172 165
173 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_ 166 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698