| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // Observer interface. | 75 // Observer interface. |
| 75 class Observer { | 76 class Observer { |
| 76 public: | 77 public: |
| 77 virtual ~Observer(); | 78 virtual ~Observer(); |
| 78 | 79 |
| 79 // Indicates device ownership status changes. | 80 // Indicates device ownership status changes. |
| 80 virtual void OwnershipStatusChanged() = 0; | 81 virtual void OwnershipStatusChanged() = 0; |
| 81 | 82 |
| 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; |
| 85 |
| 86 virtual void OnDeviceSettingsServiceShutdown() = 0; |
| 84 }; | 87 }; |
| 85 | 88 |
| 86 // Manage singleton instance. | 89 // Manage singleton instance. |
| 87 static void Initialize(); | 90 static void Initialize(); |
| 88 static bool IsInitialized(); | 91 static bool IsInitialized(); |
| 89 static void Shutdown(); | 92 static void Shutdown(); |
| 90 static DeviceSettingsService* Get(); | 93 static DeviceSettingsService* Get(); |
| 91 | 94 |
| 92 // Creates a device settings service instance. This is meant for unit tests, | 95 // Creates a device settings service instance. This is meant for unit tests, |
| 93 // production code uses the singleton returned by Get() above. | 96 // production code uses the singleton returned by Get() above. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Signs |settings| with the private half of the owner key and sends the | 134 // Signs |settings| with the private half of the owner key and sends the |
| 132 // resulting policy blob to session manager for storage. The result of the | 135 // resulting policy blob to session manager for storage. The result of the |
| 133 // operation is reported through |callback|. If successful, the updated device | 136 // operation is reported through |callback|. If successful, the updated device |
| 134 // settings are present in policy_data() and device_settings() when the | 137 // settings are present in policy_data() and device_settings() when the |
| 135 // callback runs. | 138 // callback runs. |
| 136 void SignAndStore( | 139 void SignAndStore( |
| 137 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, | 140 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> new_settings, |
| 138 const base::Closure& callback); | 141 const base::Closure& callback); |
| 139 | 142 |
| 140 // Sets the management related settings in PolicyData. | 143 // Sets the management related settings in PolicyData. |
| 144 // |
| 145 // TODO (ygorshenin@, crbug.com/230018): move this to the |
| 146 // OwnerSettingsService. |
| 141 void SetManagementSettings( | 147 void SetManagementSettings( |
| 142 enterprise_management::PolicyData::ManagementMode management_mode, | 148 enterprise_management::PolicyData::ManagementMode management_mode, |
| 143 const std::string& request_token, | 149 const std::string& request_token, |
| 144 const std::string& device_id, | 150 const std::string& device_id, |
| 145 const base::Closure& callback); | 151 const base::Closure& callback); |
| 146 | 152 |
| 147 // Stores a policy blob to session_manager. The result of the operation is | 153 // Stores a policy blob to session_manager. The result of the operation is |
| 148 // reported through |callback|. If successful, the updated device settings are | 154 // reported through |callback|. If successful, the updated device settings are |
| 149 // present in policy_data() and device_settings() when the callback runs. | 155 // present in policy_data() and device_settings() when the callback runs. |
| 150 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, | 156 void Store(scoped_ptr<enterprise_management::PolicyFetchResponse> policy, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 bool HasPrivateOwnerKey(); | 168 bool HasPrivateOwnerKey(); |
| 163 | 169 |
| 164 // Sets the identity of the user that's interacting with the service. This is | 170 // Sets the identity of the user that's interacting with the service. This is |
| 165 // relevant only for writing settings through SignAndStore(). | 171 // relevant only for writing settings through SignAndStore(). |
| 166 void InitOwner(const std::string& username, | 172 void InitOwner(const std::string& username, |
| 167 const base::WeakPtr<ownership::OwnerSettingsService>& | 173 const base::WeakPtr<ownership::OwnerSettingsService>& |
| 168 owner_settings_service); | 174 owner_settings_service); |
| 169 | 175 |
| 170 const std::string& GetUsername() const; | 176 const std::string& GetUsername() const; |
| 171 | 177 |
| 178 ownership::OwnerSettingsService* GetOwnerSettingsService() const; |
| 179 |
| 172 // Adds an observer. | 180 // Adds an observer. |
| 173 void AddObserver(Observer* observer); | 181 void AddObserver(Observer* observer); |
| 174 // Removes an observer. | 182 // Removes an observer. |
| 175 void RemoveObserver(Observer* observer); | 183 void RemoveObserver(Observer* observer); |
| 176 | 184 |
| 177 // SessionManagerClient::Observer: | 185 // SessionManagerClient::Observer: |
| 178 virtual void OwnerKeySet(bool success) override; | 186 virtual void OwnerKeySet(bool success) override; |
| 179 virtual void PropertyChangeComplete(bool success) override; | 187 virtual void PropertyChangeComplete(bool success) override; |
| 180 | 188 |
| 181 private: | 189 private: |
| 182 friend class OwnerSettingsServiceChromeOS; | 190 friend class OwnerSettingsServiceChromeOS; |
| 183 | 191 |
| 184 // Enqueues a new operation. Takes ownership of |operation| and starts it | 192 // Enqueues a new operation. Takes ownership of |operation| and starts it |
| 185 // right away if there is no active operation currently. | 193 // right away if there is no active operation currently. |
| 186 void Enqueue(SessionManagerOperation* operation); | 194 void Enqueue(const linked_ptr<SessionManagerOperation>& operation); |
| 187 | 195 |
| 188 // Enqueues a load operation. | 196 // Enqueues a load operation. |
| 189 void EnqueueLoad(bool force_key_load); | 197 void EnqueueLoad(bool force_key_load); |
| 190 | 198 |
| 199 // Enqueues a sign and store operation. |
| 200 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, |
| 201 const base::Closure& callback); |
| 202 |
| 191 // Makes sure there's a reload operation so changes to the settings (and key, | 203 // 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. | 204 // in case force_key_load is set) are getting picked up. |
| 193 void EnsureReload(bool force_key_load); | 205 void EnsureReload(bool force_key_load); |
| 194 | 206 |
| 195 // Runs the next pending operation. | 207 // Runs the next pending operation. |
| 196 void StartNextOperation(); | 208 void StartNextOperation(); |
| 197 | 209 |
| 198 // Updates status, policy data and owner key from a finished operation. | 210 // Updates status, policy data and owner key from a finished operation. |
| 199 // Starts the next pending operation if available. | 211 // Starts the next pending operation if available. |
| 200 void HandleCompletedOperation(const base::Closure& callback, | 212 void HandleCompletedOperation(const base::Closure& callback, |
| 201 SessionManagerOperation* operation, | 213 SessionManagerOperation* operation, |
| 202 Status status); | 214 Status status); |
| 203 | 215 |
| 204 // Updates status and invokes the callback immediately. | 216 // Updates status and invokes the callback immediately. |
| 205 void HandleError(Status status, const base::Closure& callback); | 217 void HandleError(Status status, const base::Closure& callback); |
| 206 | 218 |
| 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_; | 219 SessionManagerClient* session_manager_client_; |
| 221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 220 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
| 222 | 221 |
| 223 Status store_status_; | 222 Status store_status_; |
| 224 | 223 |
| 225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 224 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
| 226 | 225 |
| 227 std::string username_; | 226 std::string username_; |
| 228 scoped_refptr<ownership::PublicKey> public_key_; | 227 scoped_refptr<ownership::PublicKey> public_key_; |
| 229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; | 228 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; |
| 230 | 229 |
| 231 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 230 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
| 232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; | 231 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
| 233 | 232 |
| 234 // The queue of pending operations. The first operation on the queue is | 233 // The queue of pending operations. The first operation on the queue is |
| 235 // currently active; it gets removed and destroyed once it completes. | 234 // currently active; it gets removed and destroyed once it completes. |
| 236 std::deque<SessionManagerOperation*> pending_operations_; | 235 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_; |
| 237 | 236 |
| 238 ObserverList<Observer, true> observers_; | 237 ObserverList<Observer> observers_; |
| 239 | 238 |
| 240 // For recoverable load errors how many retries are left before we give up. | 239 // For recoverable load errors how many retries are left before we give up. |
| 241 int load_retries_left_; | 240 int load_retries_left_; |
| 242 | 241 |
| 243 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; | 242 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; |
| 244 | 243 |
| 245 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); | 244 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); |
| 246 }; | 245 }; |
| 247 | 246 |
| 248 // Helper class for tests. Initializes the DeviceSettingsService singleton on | 247 // Helper class for tests. Initializes the DeviceSettingsService singleton on |
| 249 // construction and tears it down again on destruction. | 248 // construction and tears it down again on destruction. |
| 250 class ScopedTestDeviceSettingsService { | 249 class ScopedTestDeviceSettingsService { |
| 251 public: | 250 public: |
| 252 ScopedTestDeviceSettingsService(); | 251 ScopedTestDeviceSettingsService(); |
| 253 ~ScopedTestDeviceSettingsService(); | 252 ~ScopedTestDeviceSettingsService(); |
| 254 | 253 |
| 255 private: | 254 private: |
| 256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 255 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
| 257 }; | 256 }; |
| 258 | 257 |
| 259 } // namespace chromeos | 258 } // namespace chromeos |
| 260 | 259 |
| 261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 260 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
| OLD | NEW |