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 "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
19 #include "chromeos/dbus/session_manager_client.h" | 19 #include "chromeos/dbus/session_manager_client.h" |
20 #include "components/ownership/owner_settings_service.h" | |
21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
22 #include "crypto/scoped_nss_types.h" | 21 #include "crypto/scoped_nss_types.h" |
23 #include "policy/proto/device_management_backend.pb.h" | 22 #include "policy/proto/device_management_backend.pb.h" |
24 | 23 |
25 namespace crypto { | 24 namespace crypto { |
26 class RSAPrivateKey; | 25 class RSAPrivateKey; |
27 } | 26 } |
28 | 27 |
29 namespace ownership { | 28 namespace ownership { |
30 class OwnerKeyUtil; | 29 class OwnerKeyUtil; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 public: | 75 public: |
77 virtual ~Observer(); | 76 virtual ~Observer(); |
78 | 77 |
79 // Indicates device ownership status changes. | 78 // Indicates device ownership status changes. |
80 virtual void OwnershipStatusChanged() = 0; | 79 virtual void OwnershipStatusChanged() = 0; |
81 | 80 |
82 // Gets call after updates to the device settings. | 81 // Gets call after updates to the device settings. |
83 virtual void DeviceSettingsUpdated() = 0; | 82 virtual void DeviceSettingsUpdated() = 0; |
84 }; | 83 }; |
85 | 84 |
| 85 class PrivateKeyDelegate { |
| 86 public: |
| 87 typedef base::Callback<void(bool is_owner)> IsOwnerCallback; |
| 88 typedef base::Callback<void(std::string policy_blob)> |
| 89 AssembleAndSignPolicyCallback; |
| 90 |
| 91 virtual ~PrivateKeyDelegate() {} |
| 92 |
| 93 // Returns whether current user is owner or not. When this method |
| 94 // is called too early, incorrect result can be returned because |
| 95 // private key loading may be in progress. |
| 96 virtual bool IsOwner() = 0; |
| 97 |
| 98 // Determines whether current user is owner or not, responds via |
| 99 // |callback|. |
| 100 virtual void IsOwnerAsync(const IsOwnerCallback& callback) = 0; |
| 101 |
| 102 // Assembles and signs |policy|, responds via |callback|. |
| 103 virtual bool AssembleAndSignPolicyAsync( |
| 104 scoped_ptr<enterprise_management::PolicyData> policy, |
| 105 const AssembleAndSignPolicyCallback& callback) = 0; |
| 106 |
| 107 // Signs |settings| with the private half of the owner key and sends |
| 108 // the resulting policy blob to session manager for storage. The |
| 109 // result of the operation is reported through |callback|. If |
| 110 // successful, the updated device settings are present in |
| 111 // policy_data() and device_settings() when the callback runs. |
| 112 virtual void SignAndStoreAsync( |
| 113 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings, |
| 114 const base::Closure& callback) = 0; |
| 115 |
| 116 // Sets the management related settings in PolicyData. Note that if |
| 117 // |management_mode| is NOT_MANAGED, |request_token| and |device_id| |
| 118 // should be empty strings. The result of the operation is reported |
| 119 // through |callback|. |
| 120 virtual void SetManagementSettingsAsync( |
| 121 enterprise_management::PolicyData::ManagementMode management_mode, |
| 122 const std::string& request_token, |
| 123 const std::string& device_id, |
| 124 const base::Closure& callback) = 0; |
| 125 }; |
| 126 |
86 // Manage singleton instance. | 127 // Manage singleton instance. |
87 static void Initialize(); | 128 static void Initialize(); |
88 static bool IsInitialized(); | 129 static bool IsInitialized(); |
89 static void Shutdown(); | 130 static void Shutdown(); |
90 static DeviceSettingsService* Get(); | 131 static DeviceSettingsService* Get(); |
91 | 132 |
92 // Creates a device settings service instance. This is meant for unit tests, | 133 // Creates a device settings service instance. This is meant for unit tests, |
93 // production code uses the singleton returned by Get() above. | 134 // production code uses the singleton returned by Get() above. |
94 DeviceSettingsService(); | 135 DeviceSettingsService(); |
95 virtual ~DeviceSettingsService(); | 136 virtual ~DeviceSettingsService(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Determines the ownership status and reports the result to |callback|. This | 198 // Determines the ownership status and reports the result to |callback|. This |
158 // is guaranteed to never return OWNERSHIP_UNKNOWN. | 199 // is guaranteed to never return OWNERSHIP_UNKNOWN. |
159 void GetOwnershipStatusAsync(const OwnershipStatusCallback& callback); | 200 void GetOwnershipStatusAsync(const OwnershipStatusCallback& callback); |
160 | 201 |
161 // Checks whether we have the private owner key. | 202 // Checks whether we have the private owner key. |
162 bool HasPrivateOwnerKey(); | 203 bool HasPrivateOwnerKey(); |
163 | 204 |
164 // Sets the identity of the user that's interacting with the service. This is | 205 // Sets the identity of the user that's interacting with the service. This is |
165 // relevant only for writing settings through SignAndStore(). | 206 // relevant only for writing settings through SignAndStore(). |
166 void InitOwner(const std::string& username, | 207 void InitOwner(const std::string& username, |
167 const base::WeakPtr<ownership::OwnerSettingsService>& | 208 const base::WeakPtr<PrivateKeyDelegate>& delegate); |
168 owner_settings_service); | |
169 | |
170 const std::string& GetUsername() const; | 209 const std::string& GetUsername() const; |
171 | 210 |
172 // Adds an observer. | 211 // Adds an observer. |
173 void AddObserver(Observer* observer); | 212 void AddObserver(Observer* observer); |
174 // Removes an observer. | 213 // Removes an observer. |
175 void RemoveObserver(Observer* observer); | 214 void RemoveObserver(Observer* observer); |
176 | 215 |
177 // SessionManagerClient::Observer: | 216 // SessionManagerClient::Observer: |
178 virtual void OwnerKeySet(bool success) OVERRIDE; | 217 virtual void OwnerKeySet(bool success) OVERRIDE; |
179 virtual void PropertyChangeComplete(bool success) OVERRIDE; | 218 virtual void PropertyChangeComplete(bool success) OVERRIDE; |
180 | 219 |
181 private: | 220 private: |
182 friend class OwnerSettingsServiceChromeOS; | 221 friend class OwnerSettingsService; |
183 | 222 |
184 // Enqueues a new operation. Takes ownership of |operation| and starts it | 223 // Enqueues a new operation. Takes ownership of |operation| and starts it |
185 // right away if there is no active operation currently. | 224 // right away if there is no active operation currently. |
186 void Enqueue(SessionManagerOperation* operation); | 225 void Enqueue(SessionManagerOperation* operation); |
187 | 226 |
188 // Enqueues a load operation. | 227 // Enqueues a load operation. |
189 void EnqueueLoad(bool force_key_load); | 228 void EnqueueLoad(bool force_key_load); |
190 | 229 |
191 // Makes sure there's a reload operation so changes to the settings (and key, | 230 // 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. | 231 // in case force_key_load is set) are getting picked up. |
(...skipping 26 matching lines...) Expand all Loading... |
219 | 258 |
220 SessionManagerClient* session_manager_client_; | 259 SessionManagerClient* session_manager_client_; |
221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 260 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
222 | 261 |
223 Status store_status_; | 262 Status store_status_; |
224 | 263 |
225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 264 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
226 | 265 |
227 std::string username_; | 266 std::string username_; |
228 scoped_refptr<ownership::PublicKey> public_key_; | 267 scoped_refptr<ownership::PublicKey> public_key_; |
229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; | 268 base::WeakPtr<PrivateKeyDelegate> delegate_; |
230 | 269 |
231 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 270 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; | 271 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
233 | 272 |
234 // The queue of pending operations. The first operation on the queue is | 273 // The queue of pending operations. The first operation on the queue is |
235 // currently active; it gets removed and destroyed once it completes. | 274 // currently active; it gets removed and destroyed once it completes. |
236 std::deque<SessionManagerOperation*> pending_operations_; | 275 std::deque<SessionManagerOperation*> pending_operations_; |
237 | 276 |
238 ObserverList<Observer, true> observers_; | 277 ObserverList<Observer, true> observers_; |
239 | 278 |
(...skipping 12 matching lines...) Expand all Loading... |
252 ScopedTestDeviceSettingsService(); | 291 ScopedTestDeviceSettingsService(); |
253 ~ScopedTestDeviceSettingsService(); | 292 ~ScopedTestDeviceSettingsService(); |
254 | 293 |
255 private: | 294 private: |
256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 295 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
257 }; | 296 }; |
258 | 297 |
259 } // namespace chromeos | 298 } // namespace chromeos |
260 | 299 |
261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 300 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
OLD | NEW |