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_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
18 #include "chromeos/dbus/session_manager_client.h" | 19 #include "chromeos/dbus/session_manager_client.h" |
19 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
20 #include "crypto/scoped_nss_types.h" | 21 #include "crypto/scoped_nss_types.h" |
21 #include "policy/proto/device_management_backend.pb.h" | 22 #include "policy/proto/device_management_backend.pb.h" |
22 | 23 |
23 namespace crypto { | 24 namespace crypto { |
24 class RSAPrivateKey; | 25 class RSAPrivateKey; |
25 } | 26 } |
26 | 27 |
27 namespace enterprise_management { | |
28 class ChromeDeviceSettingsProto; | |
29 } | |
30 | |
31 namespace chromeos { | 28 namespace chromeos { |
32 | 29 |
33 class OwnerKeyUtil; | 30 class OwnerKeyUtil; |
34 class PublicKey; | 31 class PublicKey; |
35 class SessionManagerOperation; | 32 class SessionManagerOperation; |
36 | 33 |
37 // Deals with the low-level interface to Chromium OS device settings. Device | 34 // Deals with the low-level interface to Chromium OS device settings. Device |
38 // settings are stored in a protobuf that's protected by a cryptographic | 35 // settings are stored in a protobuf that's protected by a cryptographic |
39 // signature generated by a key in the device owner's possession. Key and | 36 // signature generated by a key in the device owner's possession. Key and |
40 // settings are brokered by the session_manager daemon. | 37 // settings are brokered by the session_manager daemon. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 virtual bool IsOwner() = 0; | 93 virtual bool IsOwner() = 0; |
97 | 94 |
98 // Determines whether current user is owner or not, responds via | 95 // Determines whether current user is owner or not, responds via |
99 // |callback|. | 96 // |callback|. |
100 virtual void IsOwnerAsync(const IsOwnerCallback& callback) = 0; | 97 virtual void IsOwnerAsync(const IsOwnerCallback& callback) = 0; |
101 | 98 |
102 // Assembles and signs |policy|, responds via |callback|. | 99 // Assembles and signs |policy|, responds via |callback|. |
103 virtual bool AssembleAndSignPolicyAsync( | 100 virtual bool AssembleAndSignPolicyAsync( |
104 scoped_ptr<enterprise_management::PolicyData> policy, | 101 scoped_ptr<enterprise_management::PolicyData> policy, |
105 const AssembleAndSignPolicyCallback& callback) = 0; | 102 const AssembleAndSignPolicyCallback& callback) = 0; |
| 103 |
| 104 // Signs |settings| with the private half of the owner key and sends |
| 105 // the resulting policy blob to session manager for storage. The |
| 106 // result of the operation is reported through |callback|. If |
| 107 // successful, the updated device settings are present in |
| 108 // policy_data() and device_settings() when the callback runs. |
| 109 virtual void SignAndStoreAsync( |
| 110 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings, |
| 111 const base::Closure& callback) = 0; |
| 112 |
| 113 // Sets the management related settings in PolicyData. Note that if |
| 114 // |management_mode| is NOT_MANAGED, |request_token| and |device_id| |
| 115 // should be empty strings. The result of the operation is reported |
| 116 // through |callback|. |
| 117 virtual void SetManagementSettingsAsync( |
| 118 enterprise_management::PolicyData::ManagementMode management_mode, |
| 119 const std::string& request_token, |
| 120 const std::string& device_id, |
| 121 const base::Closure& callback) = 0; |
106 }; | 122 }; |
107 | 123 |
108 // Manage singleton instance. | 124 // Manage singleton instance. |
109 static void Initialize(); | 125 static void Initialize(); |
110 static bool IsInitialized(); | 126 static bool IsInitialized(); |
111 static void Shutdown(); | 127 static void Shutdown(); |
112 static DeviceSettingsService* Get(); | 128 static DeviceSettingsService* Get(); |
113 | 129 |
114 // Creates a device settings service instance. This is meant for unit tests, | 130 // Creates a device settings service instance. This is meant for unit tests, |
115 // production code uses the singleton returned by Get() above. | 131 // production code uses the singleton returned by Get() above. |
116 DeviceSettingsService(); | 132 DeviceSettingsService(); |
117 virtual ~DeviceSettingsService(); | 133 virtual ~DeviceSettingsService(); |
118 | 134 |
119 // To be called on startup once threads are initialized and DBus is ready. | 135 // To be called on startup once threads are initialized and DBus is ready. |
120 void SetSessionManager(SessionManagerClient* session_manager_client, | 136 void SetSessionManager(SessionManagerClient* session_manager_client, |
121 scoped_refptr<OwnerKeyUtil> owner_key_util); | 137 scoped_refptr<OwnerKeyUtil> owner_key_util); |
122 | 138 |
123 // Prevents the service from making further calls to session_manager_client | 139 // Prevents the service from making further calls to session_manager_client |
124 // and stops any pending operations. | 140 // and stops any pending operations. |
125 void UnsetSessionManager(); | 141 void UnsetSessionManager(); |
126 | 142 |
| 143 SessionManagerClient* session_manager_client() const { |
| 144 return session_manager_client_; |
| 145 } |
| 146 |
127 // Returns the currently active device settings. Returns NULL if the device | 147 // Returns the currently active device settings. Returns NULL if the device |
128 // settings have not been retrieved from session_manager yet. | 148 // settings have not been retrieved from session_manager yet. |
129 const enterprise_management::PolicyData* policy_data() { | 149 const enterprise_management::PolicyData* policy_data() { |
130 return policy_data_.get(); | 150 return policy_data_.get(); |
131 } | 151 } |
132 const enterprise_management::ChromeDeviceSettingsProto* | 152 const enterprise_management::ChromeDeviceSettingsProto* |
133 device_settings() const { | 153 device_settings() const { |
134 return device_settings_.get(); | 154 return device_settings_.get(); |
135 } | 155 } |
136 | 156 |
(...skipping 11 matching lines...) Expand all Loading... |
148 | 168 |
149 // Signs |settings| with the private half of the owner key and sends the | 169 // Signs |settings| with the private half of the owner key and sends the |
150 // resulting policy blob to session manager for storage. The result of the | 170 // resulting policy blob to session manager for storage. The result of the |
151 // operation is reported through |callback|. If successful, the updated device | 171 // operation is reported through |callback|. If successful, the updated device |
152 // settings are present in policy_data() and device_settings() when the | 172 // settings are present in policy_data() and device_settings() when the |
153 // callback runs. | 173 // callback runs. |
154 void SignAndStore( | 174 void SignAndStore( |
155 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, | 175 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, |
156 const base::Closure& callback); | 176 const base::Closure& callback); |
157 | 177 |
158 // Sets the management related settings in PolicyData. Note that if | 178 // Sets the management related settings in PolicyData. |
159 // |management_mode| is NOT_MANAGED, |request_token| and |device_id| should be | |
160 // empty strings. | |
161 void SetManagementSettings( | 179 void SetManagementSettings( |
162 enterprise_management::PolicyData::ManagementMode management_mode, | 180 enterprise_management::PolicyData::ManagementMode management_mode, |
163 const std::string& request_token, | 181 const std::string& request_token, |
164 const std::string& device_id, | 182 const std::string& device_id, |
165 const base::Closure& callback); | 183 const base::Closure& callback); |
166 | 184 |
167 // Stores a policy blob to session_manager. The result of the operation is | 185 // Stores a policy blob to session_manager. The result of the operation is |
168 // reported through |callback|. If successful, the updated device settings are | 186 // reported through |callback|. If successful, the updated device settings are |
169 // present in policy_data() and device_settings() when the callback runs. | 187 // present in policy_data() and device_settings() when the callback runs. |
170 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, | 188 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, |
(...skipping 19 matching lines...) Expand all Loading... |
190 // Adds an observer. | 208 // Adds an observer. |
191 void AddObserver(Observer* observer); | 209 void AddObserver(Observer* observer); |
192 // Removes an observer. | 210 // Removes an observer. |
193 void RemoveObserver(Observer* observer); | 211 void RemoveObserver(Observer* observer); |
194 | 212 |
195 // SessionManagerClient::Observer: | 213 // SessionManagerClient::Observer: |
196 virtual void OwnerKeySet(bool success) OVERRIDE; | 214 virtual void OwnerKeySet(bool success) OVERRIDE; |
197 virtual void PropertyChangeComplete(bool success) OVERRIDE; | 215 virtual void PropertyChangeComplete(bool success) OVERRIDE; |
198 | 216 |
199 private: | 217 private: |
| 218 friend class OwnerSettingsService; |
| 219 |
200 // Enqueues a new operation. Takes ownership of |operation| and starts it | 220 // Enqueues a new operation. Takes ownership of |operation| and starts it |
201 // right away if there is no active operation currently. | 221 // right away if there is no active operation currently. |
202 void Enqueue(SessionManagerOperation* operation); | 222 void Enqueue(SessionManagerOperation* operation); |
203 | 223 |
204 // Enqueues a load operation. | 224 // Enqueues a load operation. |
205 void EnqueueLoad(bool force_key_load); | 225 void EnqueueLoad(bool force_key_load); |
206 | 226 |
207 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, | |
208 const base::Closure& callback); | |
209 | |
210 // Makes sure there's a reload operation so changes to the settings (and key, | 227 // Makes sure there's a reload operation so changes to the settings (and key, |
211 // in case force_key_load is set) are getting picked up. | 228 // in case force_key_load is set) are getting picked up. |
212 void EnsureReload(bool force_key_load); | 229 void EnsureReload(bool force_key_load); |
213 | 230 |
214 // Runs the next pending operation. | 231 // Runs the next pending operation. |
215 void StartNextOperation(); | 232 void StartNextOperation(); |
216 | 233 |
217 // Updates status, policy data and owner key from a finished operation. | 234 // Updates status, policy data and owner key from a finished operation. |
218 // Starts the next pending operation if available. | 235 // Starts the next pending operation if available. |
219 void HandleCompletedOperation(const base::Closure& callback, | 236 void HandleCompletedOperation(const base::Closure& callback, |
220 SessionManagerOperation* operation, | 237 SessionManagerOperation* operation, |
221 Status status); | 238 Status status); |
222 | 239 |
223 // Updates status and invokes the callback immediately. | 240 // Updates status and invokes the callback immediately. |
224 void HandleError(Status status, const base::Closure& callback); | 241 void HandleError(Status status, const base::Closure& callback); |
225 | 242 |
226 // Assembles PolicyData based on |settings| and the current |policy_data_| | 243 // Called by OwnerSettingsService when sign-and-store operation completes. |
227 // and |username_|. | 244 void OnSignAndStoreOperationCompleted(Status status); |
228 scoped_ptr<enterprise_management::PolicyData> AssemblePolicy( | |
229 const enterprise_management::ChromeDeviceSettingsProto& settings) const; | |
230 | 245 |
231 // Returns the current management mode. | 246 void set_policy_data( |
232 enterprise_management::PolicyData::ManagementMode GetManagementMode() const; | 247 scoped_ptr<enterprise_management::PolicyData> policy_data) { |
| 248 policy_data_ = policy_data.Pass(); |
| 249 } |
233 | 250 |
234 // Returns true if it is okay to transfer from the current mode to the new | 251 void set_device_settings(scoped_ptr< |
235 // mode. This function should be called in SetManagementMode(). | 252 enterprise_management::ChromeDeviceSettingsProto> device_settings) { |
236 bool CheckManagementModeTransition( | 253 device_settings_ = device_settings.Pass(); |
237 enterprise_management::PolicyData::ManagementMode new_mode) const; | 254 } |
238 | 255 |
239 SessionManagerClient* session_manager_client_; | 256 SessionManagerClient* session_manager_client_; |
240 scoped_refptr<OwnerKeyUtil> owner_key_util_; | 257 scoped_refptr<OwnerKeyUtil> owner_key_util_; |
241 | 258 |
242 Status store_status_; | 259 Status store_status_; |
243 | 260 |
244 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 261 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
245 | 262 |
246 std::string username_; | 263 std::string username_; |
247 scoped_refptr<PublicKey> public_key_; | 264 scoped_refptr<PublicKey> public_key_; |
(...skipping 23 matching lines...) Expand all Loading... |
271 ScopedTestDeviceSettingsService(); | 288 ScopedTestDeviceSettingsService(); |
272 ~ScopedTestDeviceSettingsService(); | 289 ~ScopedTestDeviceSettingsService(); |
273 | 290 |
274 private: | 291 private: |
275 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 292 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
276 }; | 293 }; |
277 | 294 |
278 } // namespace chromeos | 295 } // namespace chromeos |
279 | 296 |
280 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 297 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
OLD | NEW |