[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 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_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | ||||
6 | #define CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | ||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 7 | |
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 8 | #include <map> |
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 9 | #include <string> |
10 | |||||
11 | #include "base/basictypes.h" | ||||
12 | #include "base/compiler_specific.h" | ||||
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 13 | #include "base/file_path.h" |
[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 14 | #include "chrome/browser/policy/cloud_policy_constants.h" |
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 15 | |
16 | namespace chromeos { | ||||
17 | class CryptohomeLibrary; | ||||
18 | } | ||||
19 | |||||
20 | namespace policy { | ||||
21 | |||||
22 | // Brokers access to the enterprise-related installation-time attributes on | ||||
23 | // ChromeOS. | ||||
24 | class EnterpriseInstallAttributes { | ||||
25 | public: | ||||
26 | // Return codes for LockDevice(). | ||||
27 | enum LockResult { | ||||
28 | LOCK_SUCCESS, | ||||
29 | LOCK_NOT_READY, | ||||
30 | LOCK_BACKEND_ERROR, | ||||
31 | LOCK_WRONG_USER, | ||||
32 | }; | ||||
33 | |||||
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 34 | // Standard cache file name. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame^] | 35 | static const base::FilePath::CharType kCacheFilePath[]; |
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 36 | |
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 37 | explicit EnterpriseInstallAttributes(chromeos::CryptohomeLibrary* cryptohome); |
38 | |||||
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 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. | ||||
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame^] | 42 | void ReadCacheFile(const base::FilePath& cache_file); |
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 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 | |||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 48 | // Locks the device to be an enterprise device registered by the given user. |
49 | // This can also be called after the lock has already been taken, in which | ||||
50 | // case it checks that the passed user agrees with the locked attribute. | ||||
[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 51 | LockResult LockDevice(const std::string& user, |
52 | DeviceMode device_mode, | ||||
53 | const std::string& device_id) WARN_UNUSED_RESULT; | ||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 54 | |
55 | // Checks whether this is an enterprise device. | ||||
56 | bool IsEnterpriseDevice(); | ||||
57 | |||||
58 | // Gets the domain this device belongs to or an empty string if the device is | ||||
59 | // not an enterprise device. | ||||
60 | std::string GetDomain(); | ||||
61 | |||||
62 | // Gets the user that registered the device. Returns an empty string if the | ||||
63 | // device is not an enterprise device. | ||||
64 | std::string GetRegistrationUser(); | ||||
65 | |||||
[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 66 | // Gets the device id that was generated when the device was registered. |
67 | // Returns an empty string if the device is not an enterprise device or the | ||||
68 | // device id was not stored in the lockbox (prior to R19). | ||||
69 | std::string GetDeviceId(); | ||||
70 | |||||
71 | // Gets the mode the device was enrolled to. The return value for devices that | ||||
72 | // are not locked yet will be DEVICE_MODE_UNKNOWN. | ||||
73 | DeviceMode GetMode(); | ||||
74 | |||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 75 | private: |
[email protected] | aea6e3b | 2013-01-18 00:27:53 | [diff] [blame] | 76 | // Decodes the install attributes provided in |attr_map|. |
77 | void DecodeInstallAttributes( | ||||
78 | const std::map<std::string, std::string>& attr_map); | ||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 79 | |
80 | chromeos::CryptohomeLibrary* cryptohome_; | ||||
81 | |||||
82 | bool device_locked_; | ||||
83 | std::string registration_user_; | ||||
[email protected] | d5979999 | 2012-02-24 13:04:04 | [diff] [blame] | 84 | std::string registration_domain_; |
85 | std::string registration_device_id_; | ||||
86 | DeviceMode registration_mode_; | ||||
[email protected] | 6c900e5 | 2011-04-18 11:09:07 | [diff] [blame] | 87 | |
88 | DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); | ||||
89 | }; | ||||
90 | |||||
91 | } // namespace policy | ||||
92 | |||||
93 | #endif // CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |