Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: chrome/browser/chromeos/settings/device_settings_service.h

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: Address Bernhard's comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
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/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/linked_ptr.h" 16 #include "base/memory/linked_ptr.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/observer_list.h" 18 #include "base/observer_list.h"
19 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 19 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
20 #include "chromeos/dbus/session_manager_client.h" 20 #include "chromeos/dbus/session_manager_client.h"
21 #include "components/ownership/owner_settings_service.h" 21 #include "components/ownership/owner_settings_service.h"
22 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
22 #include "components/policy/core/common/cloud/cloud_policy_validator.h" 23 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
23 #include "components/policy/proto/device_management_backend.pb.h" 24 #include "components/policy/proto/device_management_backend.pb.h"
24 #include "crypto/scoped_nss_types.h" 25 #include "crypto/scoped_nss_types.h"
25 26
26 namespace crypto { 27 namespace crypto {
27 class RSAPrivateKey; 28 class RSAPrivateKey;
28 } 29 }
29 30
30 namespace ownership { 31 namespace ownership {
31 class OwnerKeyUtil; 32 class OwnerKeyUtil;
32 class PublicKey; 33 class PublicKey;
33 } 34 }
34 35
35 namespace chromeos { 36 namespace chromeos {
36 37
37 class SessionManagerOperation; 38 class SessionManagerOperation;
38 39
39 // Deals with the low-level interface to Chromium OS device settings. Device 40 // Deals with the low-level interface to Chrome OS device settings. Device
40 // settings are stored in a protobuf that's protected by a cryptographic 41 // settings are stored in a protobuf that's protected by a cryptographic
41 // signature generated by a key in the device owner's possession. Key and 42 // signature generated by a key in the device owner's possession. Key and
42 // settings are brokered by the session_manager daemon. 43 // settings are brokered by the session_manager daemon.
43 // 44 //
44 // The purpose of DeviceSettingsService is to keep track of the current key and 45 // The purpose of DeviceSettingsService is to keep track of the current key and
45 // settings blob. For reading and writing device settings, use CrosSettings 46 // settings blob. For reading and writing device settings, use CrosSettings
46 // instead, which provides a high-level interface that allows for manipulation 47 // instead, which provides a high-level interface that allows for manipulation
47 // of individual settings. 48 // of individual settings.
48 // 49 //
49 // DeviceSettingsService generates notifications for key and policy update 50 // DeviceSettingsService generates notifications for key and policy update
50 // events so interested parties can reload state as appropriate. 51 // events so interested parties can reload state as appropriate.
51 class DeviceSettingsService : public SessionManagerClient::Observer { 52 class DeviceSettingsService : public SessionManagerClient::Observer {
52 public: 53 public:
53 // Indicates ownership status of the device. 54 // Indicates ownership status of the device (listed in upgrade order).
54 enum OwnershipStatus { 55 enum OwnershipStatus {
55 // Listed in upgrade order.
56 OWNERSHIP_UNKNOWN = 0, 56 OWNERSHIP_UNKNOWN = 0,
57 // Not yet owned.
57 OWNERSHIP_NONE, 58 OWNERSHIP_NONE,
59 // Either consumer ownership, cloud management or Active Directory
60 // management.
58 OWNERSHIP_TAKEN 61 OWNERSHIP_TAKEN
59 }; 62 };
60 63
61 typedef base::Callback<void(OwnershipStatus)> OwnershipStatusCallback; 64 typedef base::Callback<void(OwnershipStatus)> OwnershipStatusCallback;
62 65
63 // Status codes for Store(). 66 // Status codes for Store().
64 enum Status { 67 enum Status {
65 STORE_SUCCESS, 68 STORE_SUCCESS,
66 STORE_KEY_UNAVAILABLE, // Owner key not yet configured. 69 STORE_KEY_UNAVAILABLE, // Owner key not yet configured.
67 STORE_POLICY_ERROR, // Failure constructing the settings blob. 70 STORE_POLICY_ERROR, // Failure constructing the settings blob.
68 STORE_OPERATION_FAILED, // IPC to session_manager daemon failed. 71 STORE_OPERATION_FAILED, // IPC to session_manager daemon failed.
69 STORE_NO_POLICY, // No settings blob present. 72 STORE_NO_POLICY, // No settings blob present.
70 STORE_INVALID_POLICY, // Invalid settings blob. 73 STORE_INVALID_POLICY, // Invalid settings blob.
71 STORE_VALIDATION_ERROR, // Unrecoverable policy validation failure. 74 STORE_VALIDATION_ERROR, // Unrecoverable policy validation failure.
72 STORE_TEMP_VALIDATION_ERROR, // Temporary policy validation failure. 75 STORE_TEMP_VALIDATION_ERROR, // Temporary policy validation failure.
73 }; 76 };
74 77
75 // Observer interface. 78 // Observer interface.
76 class Observer { 79 class Observer {
77 public: 80 public:
78 virtual ~Observer(); 81 virtual ~Observer();
79 82
80 // Indicates device ownership status changes. 83 // Indicates device ownership status changes. This is triggered upon every
84 // browser start since the transition from uninitialized (OWNERSHIP_UNKNOWN)
85 // to initialized (either of OWNERSHIP_{NONE,TAKEN}) also counts as an
86 // ownership change.
81 virtual void OwnershipStatusChanged(); 87 virtual void OwnershipStatusChanged();
82 88
83 // Gets call after updates to the device settings. 89 // Gets called after updates to the device settings.
84 virtual void DeviceSettingsUpdated(); 90 virtual void DeviceSettingsUpdated();
85 91
86 virtual void OnDeviceSettingsServiceShutdown(); 92 virtual void OnDeviceSettingsServiceShutdown();
87 }; 93 };
88 94
89 // Manage singleton instance. 95 // Manage singleton instance.
90 static void Initialize(); 96 static void Initialize();
91 static bool IsInitialized(); 97 static bool IsInitialized();
92 static void Shutdown(); 98 static void Shutdown();
93 static DeviceSettingsService* Get(); 99 static DeviceSettingsService* Get();
94 100
95 // Creates a device settings service instance. This is meant for unit tests, 101 // Creates a device settings service instance. This is meant for unit tests,
96 // production code uses the singleton returned by Get() above. 102 // production code uses the singleton returned by Get() above.
97 DeviceSettingsService(); 103 DeviceSettingsService();
98 ~DeviceSettingsService() override; 104 ~DeviceSettingsService() override;
99 105
100 // To be called on startup once threads are initialized and DBus is ready. 106 // To be called on startup once threads are initialized and D-Bus is ready.
101 void SetSessionManager(SessionManagerClient* session_manager_client, 107 void SetSessionManager(SessionManagerClient* session_manager_client,
102 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util); 108 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util);
103 109
104 // Prevents the service from making further calls to session_manager_client 110 // Prevents the service from making further calls to session_manager_client
105 // and stops any pending operations. 111 // and stops any pending operations.
106 void UnsetSessionManager(); 112 void UnsetSessionManager();
107 113
114 // Must only be used with a |device_mode| that has been read and verified by
115 // the InstallAttributes class.
116 void SetDeviceMode(policy::DeviceMode device_mode);
117
108 const enterprise_management::PolicyData* policy_data() { 118 const enterprise_management::PolicyData* policy_data() {
109 return policy_data_.get(); 119 return policy_data_.get();
110 } 120 }
111 121
112 // Returns the currently active device settings. Returns nullptr if the device 122 // Returns the currently active device settings. Returns nullptr if the device
113 // settings have not been retrieved from session_manager yet. 123 // settings have not been retrieved from session_manager yet.
114 const enterprise_management::ChromeDeviceSettingsProto* 124 const enterprise_management::ChromeDeviceSettingsProto*
115 device_settings() const { 125 device_settings() const {
116 return device_settings_.get(); 126 return device_settings_.get();
117 } 127 }
118 128
119 // Returns the currently used owner key. 129 // Returns the currently used owner key.
120 scoped_refptr<ownership::PublicKey> GetPublicKey(); 130 scoped_refptr<ownership::PublicKey> GetPublicKey();
121 131
122 // Returns the status generated by the last operation. 132 // Returns the status generated by the last operation.
123 Status status() { 133 Status status() { return store_status_; }
124 return store_status_;
125 }
126 134
127 // Triggers an attempt to pull the public half of the owner key from disk and 135 // Triggers an attempt to pull the public half of the owner key from disk and
128 // load the device settings. 136 // load the device settings.
129 void Load(); 137 void Load();
130 138
131 // Stores a policy blob to session_manager. The result of the operation is 139 // Stores a policy blob to session_manager. The result of the operation is
132 // reported through |callback|. If successful, the updated device settings are 140 // reported through |callback|. If successful, the updated device settings are
133 // present in policy_data() and device_settings() when the callback runs. 141 // present in policy_data() and device_settings() when the callback runs.
134 void Store(std::unique_ptr<enterprise_management::PolicyFetchResponse> policy, 142 void Store(std::unique_ptr<enterprise_management::PolicyFetchResponse> policy,
135 const base::Closure& callback); 143 const base::Closure& callback);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void PropertyChangeComplete(bool success) override; 183 void PropertyChangeComplete(bool success) override;
176 184
177 private: 185 private:
178 friend class OwnerSettingsServiceChromeOS; 186 friend class OwnerSettingsServiceChromeOS;
179 187
180 // Enqueues a new operation. Takes ownership of |operation| and starts it 188 // Enqueues a new operation. Takes ownership of |operation| and starts it
181 // right away if there is no active operation currently. 189 // right away if there is no active operation currently.
182 void Enqueue(const linked_ptr<SessionManagerOperation>& operation); 190 void Enqueue(const linked_ptr<SessionManagerOperation>& operation);
183 191
184 // Enqueues a load operation. 192 // Enqueues a load operation.
185 void EnqueueLoad(bool force_key_load); 193 void EnqueueLoad(bool request_key_load);
186 194
187 // Makes sure there's a reload operation so changes to the settings (and key, 195 // Makes sure there's a reload operation so changes to the settings (and key,
188 // in case force_key_load is set) are getting picked up. 196 // in case |request_key_load| is set) are getting picked up.
189 void EnsureReload(bool force_key_load); 197 void EnsureReload(bool request_key_load);
190 198
191 // Runs the next pending operation. 199 // Runs the next pending operation.
192 void StartNextOperation(); 200 void StartNextOperation();
193 201
194 // Updates status, policy data and owner key from a finished operation. 202 // Updates status, policy data and owner key from a finished operation.
195 // Starts the next pending operation if available. 203 // Starts the next pending operation if available.
196 void HandleCompletedOperation(const base::Closure& callback, 204 void HandleCompletedOperation(const base::Closure& callback,
197 SessionManagerOperation* operation, 205 SessionManagerOperation* operation,
198 Status status); 206 Status status);
199 207
200 // Updates status and invokes the callback immediately. 208 // Updates status and invokes the callback immediately.
201 void HandleError(Status status, const base::Closure& callback); 209 void HandleError(Status status, const base::Closure& callback);
202 210
203 SessionManagerClient* session_manager_client_; 211 // Run OwnershipStatusChanged() for observers and push
212 // NOTIFICATION_OWNERSHIP_STATUS_CHANGED to NotificationService.
213 void NotifyOwnershipStatusChanged() const;
214
215 // Run DeviceSettingsUpdated() for observers.
216 void NotifyDeviceSettingsUpdated() const;
217
218 // Processes pending callbacks from GetOwnershipStatusAsync().
219 void RunPendingOwnershipStatusCallbacks();
220
221 SessionManagerClient* session_manager_client_ = nullptr;
204 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; 222 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_;
205 223
206 Status store_status_; 224 Status store_status_ = STORE_SUCCESS;
207 225
208 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; 226 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_;
209 227
210 std::string username_; 228 std::string username_;
211 scoped_refptr<ownership::PublicKey> public_key_; 229 scoped_refptr<ownership::PublicKey> public_key_;
212 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; 230 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_;
231 // Ownership status before the current session manager operation.
232 OwnershipStatus previous_ownership_status_ = OWNERSHIP_UNKNOWN;
213 233
214 std::unique_ptr<enterprise_management::PolicyData> policy_data_; 234 std::unique_ptr<enterprise_management::PolicyData> policy_data_;
215 std::unique_ptr<enterprise_management::ChromeDeviceSettingsProto> 235 std::unique_ptr<enterprise_management::ChromeDeviceSettingsProto>
216 device_settings_; 236 device_settings_;
217 237
238 policy::DeviceMode device_mode_ = policy::DEVICE_MODE_PENDING;
239
218 // The queue of pending operations. The first operation on the queue is 240 // The queue of pending operations. The first operation on the queue is
219 // currently active; it gets removed and destroyed once it completes. 241 // currently active; it gets removed and destroyed once it completes.
220 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_; 242 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_;
221 243
222 base::ObserverList<Observer> observers_; 244 base::ObserverList<Observer> observers_;
223 245
224 // For recoverable load errors how many retries are left before we give up. 246 // For recoverable load errors how many retries are left before we give up.
225 int load_retries_left_; 247 int load_retries_left_;
226 248
227 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; 249 base::WeakPtrFactory<DeviceSettingsService> weak_factory_;
228 250
229 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); 251 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService);
230 }; 252 };
231 253
232 // Helper class for tests. Initializes the DeviceSettingsService singleton on 254 // Helper class for tests. Initializes the DeviceSettingsService singleton on
233 // construction and tears it down again on destruction. 255 // construction and tears it down again on destruction.
234 class ScopedTestDeviceSettingsService { 256 class ScopedTestDeviceSettingsService {
235 public: 257 public:
236 ScopedTestDeviceSettingsService(); 258 ScopedTestDeviceSettingsService();
237 ~ScopedTestDeviceSettingsService(); 259 ~ScopedTestDeviceSettingsService();
238 260
239 private: 261 private:
240 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); 262 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService);
241 }; 263 };
242 264
243 } // namespace chromeos 265 } // namespace chromeos
244 266
245 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 267 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698