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