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" |
20 #include "components/policy/core/common/cloud/cloud_policy_validator.h" | 21 #include "components/policy/core/common/cloud/cloud_policy_validator.h" |
21 #include "crypto/scoped_nss_types.h" | 22 #include "crypto/scoped_nss_types.h" |
22 #include "policy/proto/device_management_backend.pb.h" | 23 #include "policy/proto/device_management_backend.pb.h" |
23 | 24 |
24 namespace crypto { | 25 namespace crypto { |
25 class RSAPrivateKey; | 26 class RSAPrivateKey; |
26 } | 27 } |
27 | 28 |
28 namespace ownership { | 29 namespace ownership { |
29 class OwnerKeyUtil; | 30 class OwnerKeyUtil; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 public: | 76 public: |
76 virtual ~Observer(); | 77 virtual ~Observer(); |
77 | 78 |
78 // Indicates device ownership status changes. | 79 // Indicates device ownership status changes. |
79 virtual void OwnershipStatusChanged() = 0; | 80 virtual void OwnershipStatusChanged() = 0; |
80 | 81 |
81 // Gets call after updates to the device settings. | 82 // Gets call after updates to the device settings. |
82 virtual void DeviceSettingsUpdated() = 0; | 83 virtual void DeviceSettingsUpdated() = 0; |
83 }; | 84 }; |
84 | 85 |
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 | |
127 // Manage singleton instance. | 86 // Manage singleton instance. |
128 static void Initialize(); | 87 static void Initialize(); |
129 static bool IsInitialized(); | 88 static bool IsInitialized(); |
130 static void Shutdown(); | 89 static void Shutdown(); |
131 static DeviceSettingsService* Get(); | 90 static DeviceSettingsService* Get(); |
132 | 91 |
133 // Creates a device settings service instance. This is meant for unit tests, | 92 // Creates a device settings service instance. This is meant for unit tests, |
134 // production code uses the singleton returned by Get() above. | 93 // production code uses the singleton returned by Get() above. |
135 DeviceSettingsService(); | 94 DeviceSettingsService(); |
136 virtual ~DeviceSettingsService(); | 95 virtual ~DeviceSettingsService(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 // Determines the ownership status and reports the result to |callback|. This | 157 // Determines the ownership status and reports the result to |callback|. This |
199 // is guaranteed to never return OWNERSHIP_UNKNOWN. | 158 // is guaranteed to never return OWNERSHIP_UNKNOWN. |
200 void GetOwnershipStatusAsync(const OwnershipStatusCallback& callback); | 159 void GetOwnershipStatusAsync(const OwnershipStatusCallback& callback); |
201 | 160 |
202 // Checks whether we have the private owner key. | 161 // Checks whether we have the private owner key. |
203 bool HasPrivateOwnerKey(); | 162 bool HasPrivateOwnerKey(); |
204 | 163 |
205 // 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 |
206 // relevant only for writing settings through SignAndStore(). | 165 // relevant only for writing settings through SignAndStore(). |
207 void InitOwner(const std::string& username, | 166 void InitOwner(const std::string& username, |
208 const base::WeakPtr<PrivateKeyDelegate>& delegate); | 167 const base::WeakPtr<ownership::OwnerSettingsService>& |
| 168 owner_settings_service); |
| 169 |
209 const std::string& GetUsername() const; | 170 const std::string& GetUsername() const; |
210 | 171 |
211 // Adds an observer. | 172 // Adds an observer. |
212 void AddObserver(Observer* observer); | 173 void AddObserver(Observer* observer); |
213 // Removes an observer. | 174 // Removes an observer. |
214 void RemoveObserver(Observer* observer); | 175 void RemoveObserver(Observer* observer); |
215 | 176 |
216 // SessionManagerClient::Observer: | 177 // SessionManagerClient::Observer: |
217 virtual void OwnerKeySet(bool success) OVERRIDE; | 178 virtual void OwnerKeySet(bool success) OVERRIDE; |
218 virtual void PropertyChangeComplete(bool success) OVERRIDE; | 179 virtual void PropertyChangeComplete(bool success) OVERRIDE; |
219 | 180 |
220 private: | 181 private: |
221 friend class OwnerSettingsService; | 182 friend class OwnerSettingsServiceChromeOS; |
222 | 183 |
223 // Enqueues a new operation. Takes ownership of |operation| and starts it | 184 // Enqueues a new operation. Takes ownership of |operation| and starts it |
224 // right away if there is no active operation currently. | 185 // right away if there is no active operation currently. |
225 void Enqueue(SessionManagerOperation* operation); | 186 void Enqueue(SessionManagerOperation* operation); |
226 | 187 |
227 // Enqueues a load operation. | 188 // Enqueues a load operation. |
228 void EnqueueLoad(bool force_key_load); | 189 void EnqueueLoad(bool force_key_load); |
229 | 190 |
230 // 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, |
231 // in case force_key_load is set) are getting picked up. | 192 // in case force_key_load is set) are getting picked up. |
(...skipping 26 matching lines...) Expand all Loading... |
258 | 219 |
259 SessionManagerClient* session_manager_client_; | 220 SessionManagerClient* session_manager_client_; |
260 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | 221 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; |
261 | 222 |
262 Status store_status_; | 223 Status store_status_; |
263 | 224 |
264 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; | 225 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; |
265 | 226 |
266 std::string username_; | 227 std::string username_; |
267 scoped_refptr<ownership::PublicKey> public_key_; | 228 scoped_refptr<ownership::PublicKey> public_key_; |
268 base::WeakPtr<PrivateKeyDelegate> delegate_; | 229 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; |
269 | 230 |
270 scoped_ptr<enterprise_management::PolicyData> policy_data_; | 231 scoped_ptr<enterprise_management::PolicyData> policy_data_; |
271 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; | 232 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> device_settings_; |
272 | 233 |
273 // 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 |
274 // currently active; it gets removed and destroyed once it completes. | 235 // currently active; it gets removed and destroyed once it completes. |
275 std::deque<SessionManagerOperation*> pending_operations_; | 236 std::deque<SessionManagerOperation*> pending_operations_; |
276 | 237 |
277 ObserverList<Observer, true> observers_; | 238 ObserverList<Observer, true> observers_; |
278 | 239 |
(...skipping 12 matching lines...) Expand all Loading... |
291 ScopedTestDeviceSettingsService(); | 252 ScopedTestDeviceSettingsService(); |
292 ~ScopedTestDeviceSettingsService(); | 253 ~ScopedTestDeviceSettingsService(); |
293 | 254 |
294 private: | 255 private: |
295 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); | 256 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); |
296 }; | 257 }; |
297 | 258 |
298 } // namespace chromeos | 259 } // namespace chromeos |
299 | 260 |
300 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ | 261 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ |
OLD | NEW |