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

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

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: 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
(...skipping 20 matching lines...) Expand all
70 STORE_INVALID_POLICY, // Invalid settings blob. 71 STORE_INVALID_POLICY, // Invalid settings blob.
71 STORE_VALIDATION_ERROR, // Unrecoverable policy validation failure. 72 STORE_VALIDATION_ERROR, // Unrecoverable policy validation failure.
72 STORE_TEMP_VALIDATION_ERROR, // Temporary policy validation failure. 73 STORE_TEMP_VALIDATION_ERROR, // Temporary policy validation failure.
73 }; 74 };
74 75
75 // Observer interface. 76 // Observer interface.
76 class Observer { 77 class Observer {
77 public: 78 public:
78 virtual ~Observer(); 79 virtual ~Observer();
79 80
80 // Indicates device ownership status changes. 81 // Indicates device ownership status changes. Not called for the transition
emaxx 2016/11/11 15:25:09 Is this special behavior for the AD case really ne
Thiemo Nagel 2016/11/16 19:11:01 I agree that this isn't pretty. Fixed.
82 // to Active Directory management.
81 virtual void OwnershipStatusChanged(); 83 virtual void OwnershipStatusChanged();
82 84
83 // Gets call after updates to the device settings. 85 // Gets call after updates to the device settings.
84 virtual void DeviceSettingsUpdated(); 86 virtual void DeviceSettingsUpdated();
85 87
86 virtual void OnDeviceSettingsServiceShutdown(); 88 virtual void OnDeviceSettingsServiceShutdown();
87 }; 89 };
88 90
89 // Manage singleton instance. 91 // Manage singleton instance.
90 static void Initialize(); 92 static void Initialize();
91 static bool IsInitialized(); 93 static bool IsInitialized();
92 static void Shutdown(); 94 static void Shutdown();
93 static DeviceSettingsService* Get(); 95 static DeviceSettingsService* Get();
94 96
95 // Creates a device settings service instance. This is meant for unit tests, 97 // Creates a device settings service instance. This is meant for unit tests,
96 // production code uses the singleton returned by Get() above. 98 // production code uses the singleton returned by Get() above.
97 DeviceSettingsService(); 99 DeviceSettingsService();
98 ~DeviceSettingsService() override; 100 ~DeviceSettingsService() override;
99 101
100 // To be called on startup once threads are initialized and DBus is ready. 102 // To be called on startup once threads are initialized and D-Bus is ready.
101 void SetSessionManager(SessionManagerClient* session_manager_client, 103 void SetSessionManager(SessionManagerClient* session_manager_client,
102 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util); 104 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util);
103 105
104 // Prevents the service from making further calls to session_manager_client 106 // Prevents the service from making further calls to session_manager_client
105 // and stops any pending operations. 107 // and stops any pending operations.
106 void UnsetSessionManager(); 108 void UnsetSessionManager();
107 109
110 // Value must have been read and verified through InstallAttributes.
111 void SetDeviceMode(policy::DeviceMode device_mode);
112
108 const enterprise_management::PolicyData* policy_data() { 113 const enterprise_management::PolicyData* policy_data() {
109 return policy_data_.get(); 114 return policy_data_.get();
110 } 115 }
111 116
112 // Returns the currently active device settings. Returns nullptr if the device 117 // Returns the currently active device settings. Returns nullptr if the device
113 // settings have not been retrieved from session_manager yet. 118 // settings have not been retrieved from session_manager yet.
114 const enterprise_management::ChromeDeviceSettingsProto* 119 const enterprise_management::ChromeDeviceSettingsProto*
115 device_settings() const { 120 device_settings() const {
116 return device_settings_.get(); 121 return device_settings_.get();
117 } 122 }
118 123
119 // Returns the currently used owner key. 124 // Returns the currently used owner key.
120 scoped_refptr<ownership::PublicKey> GetPublicKey(); 125 scoped_refptr<ownership::PublicKey> GetPublicKey();
121 126
122 // Returns the status generated by the last operation. 127 // Returns the status generated by the last operation.
123 Status status() { 128 Status status() { return store_status_; }
124 return store_status_;
125 }
126 129
127 // Triggers an attempt to pull the public half of the owner key from disk and 130 // Triggers an attempt to pull the public half of the owner key from disk and
128 // load the device settings. 131 // load the device settings.
129 void Load(); 132 void Load();
130 133
131 // Stores a policy blob to session_manager. The result of the operation is 134 // Stores a policy blob to session_manager. The result of the operation is
132 // reported through |callback|. If successful, the updated device settings are 135 // reported through |callback|. If successful, the updated device settings are
133 // present in policy_data() and device_settings() when the callback runs. 136 // present in policy_data() and device_settings() when the callback runs.
134 void Store(std::unique_ptr<enterprise_management::PolicyFetchResponse> policy, 137 void Store(std::unique_ptr<enterprise_management::PolicyFetchResponse> policy,
135 const base::Closure& callback); 138 const base::Closure& callback);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 // Updates status, policy data and owner key from a finished operation. 197 // Updates status, policy data and owner key from a finished operation.
195 // Starts the next pending operation if available. 198 // Starts the next pending operation if available.
196 void HandleCompletedOperation(const base::Closure& callback, 199 void HandleCompletedOperation(const base::Closure& callback,
197 SessionManagerOperation* operation, 200 SessionManagerOperation* operation,
198 Status status); 201 Status status);
199 202
200 // Updates status and invokes the callback immediately. 203 // Updates status and invokes the callback immediately.
201 void HandleError(Status status, const base::Closure& callback); 204 void HandleError(Status status, const base::Closure& callback);
202 205
206 void RunPendingOwnershipStatusCallbacks();
207
203 SessionManagerClient* session_manager_client_; 208 SessionManagerClient* session_manager_client_;
204 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; 209 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_;
205 210
206 Status store_status_; 211 Status store_status_;
207 212
208 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_; 213 std::vector<OwnershipStatusCallback> pending_ownership_status_callbacks_;
209 214
210 std::string username_; 215 std::string username_;
211 scoped_refptr<ownership::PublicKey> public_key_; 216 scoped_refptr<ownership::PublicKey> public_key_;
212 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_; 217 base::WeakPtr<ownership::OwnerSettingsService> owner_settings_service_;
213 218
214 std::unique_ptr<enterprise_management::PolicyData> policy_data_; 219 std::unique_ptr<enterprise_management::PolicyData> policy_data_;
215 std::unique_ptr<enterprise_management::ChromeDeviceSettingsProto> 220 std::unique_ptr<enterprise_management::ChromeDeviceSettingsProto>
216 device_settings_; 221 device_settings_;
217 222
223 policy::DeviceMode device_mode_;
224
218 // The queue of pending operations. The first operation on the queue is 225 // The queue of pending operations. The first operation on the queue is
219 // currently active; it gets removed and destroyed once it completes. 226 // currently active; it gets removed and destroyed once it completes.
220 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_; 227 std::deque<linked_ptr<SessionManagerOperation>> pending_operations_;
221 228
222 base::ObserverList<Observer> observers_; 229 base::ObserverList<Observer> observers_;
223 230
224 // For recoverable load errors how many retries are left before we give up. 231 // For recoverable load errors how many retries are left before we give up.
225 int load_retries_left_; 232 int load_retries_left_;
226 233
227 base::WeakPtrFactory<DeviceSettingsService> weak_factory_; 234 base::WeakPtrFactory<DeviceSettingsService> weak_factory_;
228 235
229 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService); 236 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsService);
230 }; 237 };
231 238
232 // Helper class for tests. Initializes the DeviceSettingsService singleton on 239 // Helper class for tests. Initializes the DeviceSettingsService singleton on
233 // construction and tears it down again on destruction. 240 // construction and tears it down again on destruction.
234 class ScopedTestDeviceSettingsService { 241 class ScopedTestDeviceSettingsService {
235 public: 242 public:
236 ScopedTestDeviceSettingsService(); 243 ScopedTestDeviceSettingsService();
237 ~ScopedTestDeviceSettingsService(); 244 ~ScopedTestDeviceSettingsService();
238 245
239 private: 246 private:
240 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService); 247 DISALLOW_COPY_AND_ASSIGN(ScopedTestDeviceSettingsService);
241 }; 248 };
242 249
243 } // namespace chromeos 250 } // namespace chromeos
244 251
245 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_ 252 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_SETTINGS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698