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