OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
7 | |
8 #include <deque> | |
9 #include <vector> | |
10 | |
11 #include "base/callback.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/macros.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 #include "base/threading/thread_checker.h" | |
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
17 #include "chromeos/dbus/session_manager_client.h" | |
18 #include "chromeos/tpm_token_loader.h" | |
19 #include "components/keyed_service/core/keyed_service.h" | |
20 #include "components/ownership/owner_key_util.h" | |
21 #include "content/public/browser/notification_observer.h" | |
22 #include "content/public/browser/notification_registrar.h" | |
23 | |
24 class Profile; | |
25 | |
26 namespace chromeos { | |
27 | |
28 class SessionManagerOperation; | |
29 | |
30 // This class reloads owner key from profile NSS slots. | |
31 // | |
32 // TODO (ygorshenin@): move write path for device settings here | |
33 // (crbug.com/230018). | |
34 class OwnerSettingsService : public DeviceSettingsService::PrivateKeyDelegate, | |
35 public KeyedService, | |
36 public content::NotificationObserver, | |
37 public TPMTokenLoader::Observer, | |
38 public SessionManagerClient::Observer { | |
39 public: | |
40 virtual ~OwnerSettingsService(); | |
41 | |
42 base::WeakPtr<OwnerSettingsService> as_weak_ptr() { | |
43 return weak_factory_.GetWeakPtr(); | |
44 } | |
45 | |
46 // DeviceSettingsService::PrivateKeyDelegate implementation: | |
47 virtual bool IsOwner() OVERRIDE; | |
48 virtual void IsOwnerAsync(const IsOwnerCallback& callback) OVERRIDE; | |
49 virtual bool AssembleAndSignPolicyAsync( | |
50 scoped_ptr<enterprise_management::PolicyData> policy, | |
51 const AssembleAndSignPolicyCallback& callback) OVERRIDE; | |
52 virtual void SignAndStoreAsync( | |
53 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> settings, | |
54 const base::Closure& callback) OVERRIDE; | |
55 virtual void SetManagementSettingsAsync( | |
56 enterprise_management::PolicyData::ManagementMode management_mode, | |
57 const std::string& request_token, | |
58 const std::string& device_id, | |
59 const base::Closure& callback) OVERRIDE; | |
60 | |
61 // NotificationObserver implementation: | |
62 virtual void Observe(int type, | |
63 const content::NotificationSource& source, | |
64 const content::NotificationDetails& details) OVERRIDE; | |
65 | |
66 // TPMTokenLoader::Observer: | |
67 virtual void OnTPMTokenReady() OVERRIDE; | |
68 | |
69 // SessionManagerClient::Observer: | |
70 virtual void OwnerKeySet(bool success) OVERRIDE; | |
71 | |
72 // Checks if the user is the device owner, without the user profile having to | |
73 // been initialized. Should be used only if login state is in safe mode. | |
74 static void IsOwnerForSafeModeAsync( | |
75 const std::string& user_id, | |
76 const std::string& user_hash, | |
77 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, | |
78 const IsOwnerCallback& callback); | |
79 | |
80 static void SetDeviceSettingsServiceForTesting( | |
81 DeviceSettingsService* device_settings_service); | |
82 | |
83 private: | |
84 friend class OwnerSettingsServiceFactory; | |
85 | |
86 OwnerSettingsService( | |
87 Profile* profile, | |
88 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | |
89 | |
90 // Reloads private key from profile's NSS slots. Responds via call | |
91 // to OnPrivateKeyLoaded(). | |
92 void ReloadPrivateKey(); | |
93 | |
94 // Called when ReloadPrivateKey() completes it's work. | |
95 void OnPrivateKeyLoaded(scoped_refptr<ownership::PublicKey> public_key, | |
96 scoped_refptr<ownership::PrivateKey> private_key); | |
97 | |
98 // Puts request to perform sign-and-store operation in the queue. | |
99 void EnqueueSignAndStore(scoped_ptr<enterprise_management::PolicyData> policy, | |
100 const base::Closure& callback); | |
101 | |
102 // Performs next operation in the queue. | |
103 void StartNextOperation(); | |
104 | |
105 // Called when sign-and-store operation completes it's work. | |
106 void HandleCompletedOperation(const base::Closure& callback, | |
107 SessionManagerOperation* operation, | |
108 DeviceSettingsService::Status status); | |
109 | |
110 // Called when it's not possible to store settings. | |
111 void HandleError(DeviceSettingsService::Status status, | |
112 const base::Closure& callback); | |
113 | |
114 // Returns testing instance of OwnerKeyUtil when it's set, otherwise | |
115 // returns |owner_key_util_|. | |
116 scoped_refptr<ownership::OwnerKeyUtil> GetOwnerKeyUtil(); | |
117 | |
118 // Returns testing instance of DeviceSettingsService when it's set, | |
119 // otherwise returns pointer to a singleton instance, when it's | |
120 // initialized. | |
121 DeviceSettingsService* GetDeviceSettingsService(); | |
122 | |
123 // Profile this service instance belongs to. | |
124 Profile* profile_; | |
125 | |
126 // User ID this service instance belongs to. | |
127 std::string user_id_; | |
128 | |
129 scoped_refptr<ownership::PublicKey> public_key_; | |
130 | |
131 scoped_refptr<ownership::PrivateKey> private_key_; | |
132 | |
133 scoped_refptr<ownership::OwnerKeyUtil> owner_key_util_; | |
134 | |
135 std::vector<IsOwnerCallback> pending_is_owner_callbacks_; | |
136 | |
137 // Whether profile still needs to be initialized. | |
138 bool waiting_for_profile_creation_; | |
139 | |
140 // Whether TPM token still needs to be initialized. | |
141 bool waiting_for_tpm_token_; | |
142 | |
143 // The queue of pending sign-and-store operations. The first operation on the | |
144 // queue is currently active; it gets removed and destroyed once it completes. | |
145 std::deque<SessionManagerOperation*> pending_operations_; | |
146 | |
147 content::NotificationRegistrar registrar_; | |
148 | |
149 base::ThreadChecker thread_checker_; | |
150 | |
151 base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | |
152 | |
153 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | |
154 }; | |
155 | |
156 } // namespace chromeos | |
157 | |
158 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | |
OLD | NEW |