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/linked_ptr.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
18 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 19 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
19 #include "chromeos/dbus/session_manager_client.h" | 20 #include "chromeos/dbus/session_manager_client.h" |
20 #include "components/ownership/owner_settings_service.h" | 21 #include "components/ownership/owner_settings_service.h" |
21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
22 #include "crypto/scoped_nss_types.h" | 23 #include "crypto/scoped_nss_types.h" |
23 #include "policy/proto/device_management_backend.pb.h" | 24 #include "policy/proto/device_management_backend.pb.h" |
24 | 25 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // Gets call after updates to the device settings. | 83 // Gets call after updates to the device settings. |
83 virtual void DeviceSettingsUpdated() = 0; | 84 virtual void DeviceSettingsUpdated() = 0; |
84 }; | 85 }; |
85 | 86 |
86 // Manage singleton instance. | 87 // Manage singleton instance. |
87 static void Initialize(); | 88 static void Initialize(); |
88 static bool IsInitialized(); | 89 static bool IsInitialized(); |
89 static void Shutdown(); | 90 static void Shutdown(); |
90 static DeviceSettingsService* Get(); | 91 static DeviceSettingsService* Get(); |
91 | 92 |
| 93 // Updates device |settings|. |
| 94 static void UpdateDeviceSettings( |
| 95 const std::string& path, |
| 96 const base::Value& value, |
| 97 enterprise_management::ChromeDeviceSettingsProto& settings); |
| 98 |
| 99 // Assembles PolicyData based on |settings|, |policy_data| and |
| 100 // |user_id|. |
| 101 static scoped_ptr<enterprise_management::PolicyData> AssemblePolicy( |
| 102 const std::string& user_id, |
| 103 const enterprise_management::PolicyData* policy_data, |
| 104 const enterprise_management::ChromeDeviceSettingsProto* settings); |
| 105 |
92 // Creates a device settings service instance. This is meant for unit tests, | 106 // Creates a device settings service instance. This is meant for unit tests, |
93 // production code uses the singleton returned by Get() above. | 107 // production code uses the singleton returned by Get() above. |
94 DeviceSettingsService(); | 108 DeviceSettingsService(); |
95 virtual ~DeviceSettingsService(); | 109 virtual ~DeviceSettingsService(); |
96 | 110 |
97 // To be called on startup once threads are initialized and DBus is ready. | 111 // To be called on startup once threads are initialized and DBus is ready. |
98 void SetSessionManager(SessionManagerClient* session_manager_client, | 112 void SetSessionManager(SessionManagerClient* session_manager_client, |
99 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util); | 113 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util); |
100 | 114 |
101 // Prevents the service from making further calls to session_manager_client | 115 // Prevents the service from making further calls to session_manager_client |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 bool HasPrivateOwnerKey(); | 176 bool HasPrivateOwnerKey(); |
163 | 177 |
164 // Sets the identity of the user that's interacting with the service. This is | 178 // Sets the identity of the user that's interacting with the service. This is |
165 // relevant only for writing settings through SignAndStore(). | 179 // relevant only for writing settings through SignAndStore(). |
166 void InitOwner(const std::string& username, | 180 void InitOwner(const std::string& username, |
167 const base::WeakPtr<ownership::OwnerSettingsService>& | 181 const base::WeakPtr<ownership::OwnerSettingsService>& |
168 owner_settings_service); | 182 owner_settings_service); |
169 | 183 |
170 const std::string& GetUsername() const; | 184 const std::string& GetUsername() const; |
171 | 185 |
| 186 ownership::OwnerSettingsService* GetOwnerSettingsService() const; |
| 187 |
172 // Adds an observer. | 188 // Adds an observer. |
173 void AddObserver(Observer* observer); | 189 void AddObserver(Observer* observer); |
174 // Removes an observer. | 190 // Removes an observer. |
175 void RemoveObserver(Observer* observer); | 191 void RemoveObserver(Observer* observer); |
176 | 192 |
| 193 // Returns true if there is a pending session manager operation. |
| 194 bool HasPendingOperations() const; |
| 195 |
| 196 // Returns false when it's not possible to enable/disable processing loop. |
| 197 bool EnableProcessingLoop(bool enabled); |
| 198 |
177 // SessionManagerClient::Observer: | 199 // SessionManagerClient::Observer: |
178 virtual void OwnerKeySet(bool success) override; | 200 virtual void OwnerKeySet(bool success) override; |
179 virtual void PropertyChangeComplete(bool success) override; | 201 virtual void PropertyChangeComplete(bool success) override; |
180 | 202 |
181 private: | 203 private: |
182 friend class OwnerSettingsServiceChromeOS; | 204 friend class OwnerSettingsServiceChromeOS; |
183 | 205 |
184 // Enqueues a new operation. Takes ownership of |operation| and starts it | 206 // Enqueues a new operation. Takes ownership of |operation| and starts it |
185 // right away if there is no active operation currently. | 207 // right away if there is no active operation currently. |
186 void Enqueue(SessionManagerOperation* operation); | 208 void Enqueue(const linked_ptr<SessionManagerOperation>& operation); |
187 | 209 |
188 // Enqueues a load operation. | 210 // Enqueues a load operation. |
189 void EnqueueLoad(bool force_key_load); | 211 void EnqueueLoad(bool force_key_load); |
190 | 212 |
| 213 // Enqueues a sign and store operation. |
| 214 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, |
| 215 const base::Closure& callback); |
| 216 |
191 // Makes sure there's a reload operation so changes to the settings (and key, | 217 // Makes sure there's a reload operation so changes to the settings (and key, |
192 // in case force_key_load is set) are getting picked up. | 218 // in case force_key_load is set) are getting picked up. |
193 void EnsureReload(bool force_key_load); | 219 void EnsureReload(bool force_key_load); |
194 | 220 |
195 // Runs the next pending operation. | 221 // Runs the next pending operation. |
196 void StartNextOperation(); | 222 void StartNextOperation(); |
197 | 223 |
198 // Updates status, policy data and owner key from a finished operation. | 224 // Updates status, policy data and owner key from a finished operation. |
199 // Starts the next pending operation if available. | 225 // Starts the next pending operation if available. |
200 void HandleCompletedOperation(const base::Closure& callback, | 226 void HandleCompletedOperation(const base::Closure& callback, |
201 SessionManagerOperation* operation, | 227 SessionManagerOperation* operation, |
202 Status status); | 228 Status status); |
203 | 229 |
204 // Updates status and invokes the callback immediately. | 230 // Updates status and invokes the callback immediately. |
205 void HandleError(Status status, const base::Closure& callback); | 231 void HandleError(Status status, const base::Closure& callback); |
206 | 232 |
207 // Called by OwnerSettingsService when sign-and-store operation completes. | |
208 void OnSignAndStoreOperationCompleted(Status status); | |
209 | |
210 void set_policy_data( | |
211 scoped_ptr<enterprise_management::PolicyData> policy_data) { | |
212 policy_data_ = policy_data.Pass(); | |
213 } | |
214 | |
215 void set_device_settings(scoped_ptr< | |
216 enterprise_management::ChromeDeviceSettingsProto> device_settings) { | |
217 device_settings_ = device_settings.Pass(); | |
218 } | |
219 | |
220 SessionManagerClient* session_manager_client_; | 233 SessionManagerClient* session_manager_client_; |
221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 234 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
222 | 235 |
223 Status store_status_; | 236 Status store_status_; |
224 | 237 |
225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 238 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
226 | 239 |
227 std::string username_; | 240 std::string username_; |
228 scoped_refptr<ownership::PublicKey> public_key_; | 241 scoped_refptr<ownership::PublicKey> public_key_; |
229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; | 242 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; |
230 | 243 |
231 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 244 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; | 245 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
233 | 246 |
234 // The queue of pending operations. The first operation on the queue is | 247 // The queue of pending operations. The first operation on the queue is |
235 // currently active; it gets removed and destroyed once it completes. | 248 // currently active; it gets removed and destroyed once it completes. |
236 std::deque<SessionManagerOperation*> pending_operations_; | 249 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_; |
237 | 250 |
238 ObserverList<Observer, true> observers_; | 251 // When true, session manager operations are not processed. |
| 252 bool processing_loop_enabled_; |
| 253 |
| 254 ObserverList<Observer> observers_; |
239 | 255 |
240 // For recoverable load errors how many retries are left before we give up. | 256 // For recoverable load errors how many retries are left before we give up. |
241 int load_retries_left_; | 257 int load_retries_left_; |
242 | 258 |
243 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; | 259 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; |
244 | 260 |
245 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); | 261 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); |
246 }; | 262 }; |
247 | 263 |
248 // Helper class for tests. Initializes the DeviceSettingsService singleton on | 264 // Helper class for tests. Initializes the DeviceSettingsService singleton on |
249 // construction and tears it down again on destruction. | 265 // construction and tears it down again on destruction. |
250 class ScopedTestDeviceSettingsService { | 266 class ScopedTestDeviceSettingsService { |
251 public: | 267 public: |
252 ScopedTestDeviceSettingsService(); | 268 ScopedTestDeviceSettingsService(); |
253 ~ScopedTestDeviceSettingsService(); | 269 ~ScopedTestDeviceSettingsService(); |
254 | 270 |
255 private: | 271 private: |
256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 272 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
257 }; | 273 }; |
258 | 274 |
259 } // namespace chromeos | 275 } // namespace chromeos |
260 | 276 |
261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 277 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
OLD | NEW |