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