| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 172 // Adds an observer. | 186 // Adds an observer. |
| 173 void AddObserver(Observer* observer); | 187 void AddObserver(Observer* observer); |
| 174 // Removes an observer. | 188 // Removes an observer. |
| 175 void RemoveObserver(Observer* observer); | 189 void RemoveObserver(Observer* observer); |
| 176 | 190 |
| 191 // Returns true if there is a pending session manager operation. |
| 192 bool HasPendingOperations() const; |
| 193 |
| 194 // Returns false when it's not possible to enable/disable processing loop. |
| 195 bool EnableProcessingLoop(bool enabled); |
| 196 |
| 177 // SessionManagerClient::Observer: | 197 // SessionManagerClient::Observer: |
| 178 virtual void OwnerKeySet(bool success) override; | 198 virtual void OwnerKeySet(bool success) override; |
| 179 virtual void PropertyChangeComplete(bool success) override; | 199 virtual void PropertyChangeComplete(bool success) override; |
| 180 | 200 |
| 181 private: | 201 private: |
| 182 friend class OwnerSettingsServiceChromeOS; | 202 friend class OwnerSettingsServiceChromeOS; |
| 183 | 203 |
| 184 // Enqueues a new operation. Takes ownership of |operation| and starts it | 204 // Enqueues a new operation. Takes ownership of |operation| and starts it |
| 185 // right away if there is no active operation currently. | 205 // right away if there is no active operation currently. |
| 186 void Enqueue(SessionManagerOperation* operation); | 206 void Enqueue(const linked_ptr<SessionManagerOperation>& operation); |
| 187 | 207 |
| 188 // Enqueues a load operation. | 208 // Enqueues a load operation. |
| 189 void EnqueueLoad(bool force_key_load); | 209 void EnqueueLoad(bool force_key_load); |
| 190 | 210 |
| 211 // Enqueues a sign and store operation. |
| 212 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, |
| 213 const base::Closure& callback); |
| 214 |
| 191 // Makes sure there's a reload operation so changes to the settings (and key, | 215 // 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. | 216 // in case force_key_load is set) are getting picked up. |
| 193 void EnsureReload(bool force_key_load); | 217 void EnsureReload(bool force_key_load); |
| 194 | 218 |
| 195 // Runs the next pending operation. | 219 // Runs the next pending operation. |
| 196 void StartNextOperation(); | 220 void StartNextOperation(); |
| 197 | 221 |
| 198 // Updates status, policy data and owner key from a finished operation. | 222 // Updates status, policy data and owner key from a finished operation. |
| 199 // Starts the next pending operation if available. | 223 // Starts the next pending operation if available. |
| 200 void HandleCompletedOperation(const base::Closure& callback, | 224 void HandleCompletedOperation(const base::Closure& callback, |
| 201 SessionManagerOperation* operation, | 225 SessionManagerOperation* operation, |
| 202 Status status); | 226 Status status); |
| 203 | 227 |
| 204 // Updates status and invokes the callback immediately. | 228 // Updates status and invokes the callback immediately. |
| 205 void HandleError(Status status, const base::Closure& callback); | 229 void HandleError(Status status, const base::Closure& callback); |
| 206 | 230 |
| 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_; | 231 SessionManagerClient* session_manager_client_; |
| 221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 232 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
| 222 | 233 |
| 223 Status store_status_; | 234 Status store_status_; |
| 224 | 235 |
| 225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 236 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
| 226 | 237 |
| 227 std::string username_; | 238 std::string username_; |
| 228 scoped_refptr<ownership::PublicKey> public_key_; | 239 scoped_refptr<ownership::PublicKey> public_key_; |
| 229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; | 240 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; |
| 230 | 241 |
| 231 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 242 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
| 232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; | 243 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
| 233 | 244 |
| 234 // The queue of pending operations. The first operation on the queue is | 245 // The queue of pending operations. The first operation on the queue is |
| 235 // currently active; it gets removed and destroyed once it completes. | 246 // currently active; it gets removed and destroyed once it completes. |
| 236 std::deque<SessionManagerOperation*> pending_operations_; | 247 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_; |
| 237 | 248 |
| 238 ObserverList<Observer, true> observers_; | 249 // When true, session manager operations are not processed. |
| 250 bool processing_loop_enabled_; |
| 251 |
| 252 ObserverList<Observer> observers_; |
| 239 | 253 |
| 240 // For recoverable load errors how many retries are left before we give up. | 254 // For recoverable load errors how many retries are left before we give up. |
| 241 int load_retries_left_; | 255 int load_retries_left_; |
| 242 | 256 |
| 243 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; | 257 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; |
| 244 | 258 |
| 245 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); | 259 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); |
| 246 }; | 260 }; |
| 247 | 261 |
| 248 // Helper class for tests. Initializes the DeviceSettingsService singleton on | 262 // Helper class for tests. Initializes the DeviceSettingsService singleton on |
| 249 // construction and tears it down again on destruction. | 263 // construction and tears it down again on destruction. |
| 250 class ScopedTestDeviceSettingsService { | 264 class ScopedTestDeviceSettingsService { |
| 251 public: | 265 public: |
| 252 ScopedTestDeviceSettingsService(); | 266 ScopedTestDeviceSettingsService(); |
| 253 ~ScopedTestDeviceSettingsService(); | 267 ~ScopedTestDeviceSettingsService(); |
| 254 | 268 |
| 255 private: | 269 private: |
| 256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 270 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
| 257 }; | 271 }; |
| 258 | 272 |
| 259 } // namespace chromeos | 273 } // namespace chromeos |
| 260 | 274 |
| 261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 275 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
| OLD | NEW |