| OLD | NEW |
| 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_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 5 #ifndef CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| 6 #define CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 6 #define CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/file_path.h" |
| 12 #include "chrome/browser/policy/cloud_policy_constants.h" | 14 #include "chrome/browser/policy/cloud_policy_constants.h" |
| 13 | 15 |
| 14 namespace chromeos { | 16 namespace chromeos { |
| 15 class CryptohomeLibrary; | 17 class CryptohomeLibrary; |
| 16 } | 18 } |
| 17 | 19 |
| 18 namespace policy { | 20 namespace policy { |
| 19 | 21 |
| 20 // Brokers access to the enterprise-related installation-time attributes on | 22 // Brokers access to the enterprise-related installation-time attributes on |
| 21 // ChromeOS. | 23 // ChromeOS. |
| 22 class EnterpriseInstallAttributes { | 24 class EnterpriseInstallAttributes { |
| 23 public: | 25 public: |
| 24 // Return codes for LockDevice(). | 26 // Return codes for LockDevice(). |
| 25 enum LockResult { | 27 enum LockResult { |
| 26 LOCK_SUCCESS, | 28 LOCK_SUCCESS, |
| 27 LOCK_NOT_READY, | 29 LOCK_NOT_READY, |
| 28 LOCK_BACKEND_ERROR, | 30 LOCK_BACKEND_ERROR, |
| 29 LOCK_WRONG_USER, | 31 LOCK_WRONG_USER, |
| 30 }; | 32 }; |
| 31 | 33 |
| 34 // Standard cache file name. |
| 35 static const FilePath::CharType kCacheFilePath[]; |
| 36 |
| 32 explicit EnterpriseInstallAttributes(chromeos::CryptohomeLibrary* cryptohome); | 37 explicit EnterpriseInstallAttributes(chromeos::CryptohomeLibrary* cryptohome); |
| 33 | 38 |
| 39 // Reads data from the cache file. The cache file is used to work around slow |
| 40 // cryptohome startup, which takes a while to register its DBus interface. |
| 41 // See http://crosbug.com/37367 for background on this. |
| 42 void ReadCacheFile(const FilePath& cache_file); |
| 43 |
| 44 // Makes sure the local caches for enterprise-related install attributes are |
| 45 // up-to-date with what cryptohome has. |
| 46 void ReadImmutableAttributes(); |
| 47 |
| 34 // Locks the device to be an enterprise device registered by the given user. | 48 // Locks the device to be an enterprise device registered by the given user. |
| 35 // This can also be called after the lock has already been taken, in which | 49 // This can also be called after the lock has already been taken, in which |
| 36 // case it checks that the passed user agrees with the locked attribute. | 50 // case it checks that the passed user agrees with the locked attribute. |
| 37 LockResult LockDevice(const std::string& user, | 51 LockResult LockDevice(const std::string& user, |
| 38 DeviceMode device_mode, | 52 DeviceMode device_mode, |
| 39 const std::string& device_id) WARN_UNUSED_RESULT; | 53 const std::string& device_id) WARN_UNUSED_RESULT; |
| 40 | 54 |
| 41 // Checks whether this is an enterprise device. | 55 // Checks whether this is an enterprise device. |
| 42 bool IsEnterpriseDevice(); | 56 bool IsEnterpriseDevice(); |
| 43 | 57 |
| 44 // Gets the domain this device belongs to or an empty string if the device is | 58 // Gets the domain this device belongs to or an empty string if the device is |
| 45 // not an enterprise device. | 59 // not an enterprise device. |
| 46 std::string GetDomain(); | 60 std::string GetDomain(); |
| 47 | 61 |
| 48 // Gets the user that registered the device. Returns an empty string if the | 62 // Gets the user that registered the device. Returns an empty string if the |
| 49 // device is not an enterprise device. | 63 // device is not an enterprise device. |
| 50 std::string GetRegistrationUser(); | 64 std::string GetRegistrationUser(); |
| 51 | 65 |
| 52 // Gets the device id that was generated when the device was registered. | 66 // Gets the device id that was generated when the device was registered. |
| 53 // Returns an empty string if the device is not an enterprise device or the | 67 // Returns an empty string if the device is not an enterprise device or the |
| 54 // device id was not stored in the lockbox (prior to R19). | 68 // device id was not stored in the lockbox (prior to R19). |
| 55 std::string GetDeviceId(); | 69 std::string GetDeviceId(); |
| 56 | 70 |
| 57 // Gets the mode the device was enrolled to. The return value for devices that | 71 // Gets the mode the device was enrolled to. The return value for devices that |
| 58 // are not locked yet will be DEVICE_MODE_UNKNOWN. | 72 // are not locked yet will be DEVICE_MODE_UNKNOWN. |
| 59 DeviceMode GetMode(); | 73 DeviceMode GetMode(); |
| 60 | 74 |
| 61 private: | 75 private: |
| 62 // Makes sure the local caches for enterprise-related install attributes are | 76 // Decodes the install attributes provided in |attr_map|. |
| 63 // up-to-date with what cryptohome has. | 77 void DecodeInstallAttributes( |
| 64 void ReadImmutableAttributes(); | 78 const std::map<std::string, std::string>& attr_map); |
| 65 | 79 |
| 66 chromeos::CryptohomeLibrary* cryptohome_; | 80 chromeos::CryptohomeLibrary* cryptohome_; |
| 67 | 81 |
| 68 bool device_locked_; | 82 bool device_locked_; |
| 69 std::string registration_user_; | 83 std::string registration_user_; |
| 70 std::string registration_domain_; | 84 std::string registration_domain_; |
| 71 std::string registration_device_id_; | 85 std::string registration_device_id_; |
| 72 DeviceMode registration_mode_; | 86 DeviceMode registration_mode_; |
| 73 | 87 |
| 74 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); | 88 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); |
| 75 }; | 89 }; |
| 76 | 90 |
| 77 } // namespace policy | 91 } // namespace policy |
| 78 | 92 |
| 79 #endif // CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 93 #endif // CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| OLD | NEW |