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_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/gtest_prod_util.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
17 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
19 | 20 |
20 namespace policy { | 21 namespace policy { |
21 | 22 |
22 // Brokers access to the enterprise-related installation-time attributes on | 23 // Brokers access to the enterprise-related installation-time attributes on |
23 // ChromeOS. | 24 // ChromeOS. |
24 // TODO(zelidrag, mnissler): Rename + move this class - http://crbug.com/249513. | 25 // TODO(zelidrag, mnissler): Rename + move this class - http://crbug.com/249513. |
25 class EnterpriseInstallAttributes { | 26 class EnterpriseInstallAttributes { |
26 public: | 27 public: |
27 // Return codes for LockDevice(). | 28 // Return codes for LockDevice(). |
28 enum LockResult { | 29 enum LockResult { |
29 LOCK_SUCCESS, | 30 LOCK_SUCCESS, |
30 LOCK_NOT_READY, | 31 LOCK_NOT_READY, |
31 LOCK_BACKEND_ERROR, | 32 LOCK_BACKEND_ERROR, |
32 LOCK_WRONG_USER, | 33 LOCK_WRONG_USER, |
33 }; | 34 }; |
34 | 35 |
35 // A callback to handle responses of methods returning a LockResult value. | 36 // A callback to handle responses of methods returning a LockResult value. |
36 typedef base::Callback<void(LockResult lock_result)> LockResultCallback; | 37 typedef base::Callback<void(LockResult lock_result)> LockResultCallback; |
37 | 38 |
38 // Constants for the possible device modes that can be stored in the lockbox. | 39 // Return serialized InstallAttributes of an enterprise-owned configuration. |
39 static const char kConsumerDeviceMode[]; | 40 static std::string GetEnterpriseOwnedInstallAttributesBlobForTesting( |
40 static const char kEnterpriseDeviceMode[]; | 41 const std::string& user_name); |
41 static const char kRetailKioskDeviceMode[]; | |
42 static const char kConsumerKioskDeviceMode[]; | |
43 static const char kUnknownDeviceMode[]; | |
44 | |
45 // Field names in the lockbox. | |
46 static const char kAttrEnterpriseDeviceId[]; | |
47 static const char kAttrEnterpriseDomain[]; | |
48 static const char kAttrEnterpriseMode[]; | |
49 static const char kAttrEnterpriseOwned[]; | |
50 static const char kAttrEnterpriseUser[]; | |
51 static const char kAttrConsumerKioskEnabled[]; | |
52 | 42 |
53 explicit EnterpriseInstallAttributes( | 43 explicit EnterpriseInstallAttributes( |
54 chromeos::CryptohomeClient* cryptohome_client); | 44 chromeos::CryptohomeClient* cryptohome_client); |
55 ~EnterpriseInstallAttributes(); | 45 ~EnterpriseInstallAttributes(); |
56 | 46 |
57 // Reads data from the cache file which is created early during the boot | 47 // Reads data from the cache file which is created early during the boot |
58 // process. The cache file is used to work around slow cryptohome startup, | 48 // process. The cache file is used to work around slow cryptohome startup, |
59 // which takes a while to register its DBus interface. See | 49 // which takes a while to register its DBus interface. See |
60 // http://crosbug.com/37367 for background on this. | 50 // http://crosbug.com/37367 for background on this. |
61 void ReadCacheFile(const base::FilePath& cache_file); | 51 void ReadCacheFile(const base::FilePath& cache_file); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 DeviceMode GetMode(); | 89 DeviceMode GetMode(); |
100 | 90 |
101 protected: | 91 protected: |
102 bool device_locked_; | 92 bool device_locked_; |
103 std::string registration_user_; | 93 std::string registration_user_; |
104 std::string registration_domain_; | 94 std::string registration_domain_; |
105 std::string registration_device_id_; | 95 std::string registration_device_id_; |
106 DeviceMode registration_mode_; | 96 DeviceMode registration_mode_; |
107 | 97 |
108 private: | 98 private: |
| 99 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 100 DeviceLockedFromOlderVersion); |
| 101 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 102 ReadCacheFile); |
| 103 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 104 ReadCacheFileForConsumerKiosk); |
| 105 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 106 VerifyFakeInstallAttributesCache); |
| 107 |
| 108 // Constants for the possible device modes that can be stored in the lockbox. |
| 109 static const char kConsumerDeviceMode[]; |
| 110 static const char kEnterpriseDeviceMode[]; |
| 111 static const char kRetailKioskDeviceMode[]; |
| 112 static const char kConsumerKioskDeviceMode[]; |
| 113 static const char kUnknownDeviceMode[]; |
| 114 |
| 115 // Field names in the lockbox. |
| 116 static const char kAttrEnterpriseDeviceId[]; |
| 117 static const char kAttrEnterpriseDomain[]; |
| 118 static const char kAttrEnterpriseMode[]; |
| 119 static const char kAttrEnterpriseOwned[]; |
| 120 static const char kAttrEnterpriseUser[]; |
| 121 static const char kAttrConsumerKioskEnabled[]; |
| 122 |
| 123 // Translates DeviceMode constants to strings used in the lockbox. |
| 124 std::string GetDeviceModeString(DeviceMode mode); |
| 125 |
| 126 // Translates strings used in the lockbox to DeviceMode values. |
| 127 DeviceMode GetDeviceModeFromString(const std::string& mode); |
| 128 |
109 // Decodes the install attributes provided in |attr_map|. | 129 // Decodes the install attributes provided in |attr_map|. |
110 void DecodeInstallAttributes( | 130 void DecodeInstallAttributes( |
111 const std::map<std::string, std::string>& attr_map); | 131 const std::map<std::string, std::string>& attr_map); |
112 | 132 |
113 // Helper for ReadImmutableAttributes. | 133 // Helper for ReadImmutableAttributes. |
114 void ReadAttributesIfReady( | 134 void ReadAttributesIfReady( |
115 const base::Closure& callback, | 135 const base::Closure& callback, |
116 chromeos::DBusMethodCallStatus call_status, | 136 chromeos::DBusMethodCallStatus call_status, |
117 bool result); | 137 bool result); |
118 | 138 |
(...skipping 14 matching lines...) Expand all Loading... |
133 chromeos::CryptohomeClient* cryptohome_client_; | 153 chromeos::CryptohomeClient* cryptohome_client_; |
134 | 154 |
135 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; | 155 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; |
136 | 156 |
137 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); | 157 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); |
138 }; | 158 }; |
139 | 159 |
140 } // namespace policy | 160 } // namespace policy |
141 | 161 |
142 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 162 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
OLD | NEW |