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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/compiler_specific.h"
14 #include "base/files/file_path.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chromeos/dbus/cryptohome_client.h"
17 #include "chromeos/dbus/dbus_method_call_status.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
22 // Brokers access to the enterprise-related installation-time attributes on
24 // TODO(zelidrag, mnissler): Rename + move this class - http://crbug.com/249513.
25 class EnterpriseInstallAttributes {
27 // Return codes for LockDevice().
35 // A callback to handle responses of methods returning a LockResult value.
36 typedef base::Callback<void(LockResult lock_result)> LockResultCallback;
38 // Constants for the possible device modes that can be stored in the lockbox.
39 static const char kConsumerDeviceMode[];
40 static const char kEnterpiseDeviceMode[];
41 static const char kRetailKioskDeviceMode[];
42 static const char kConsumerKioskDeviceMode[];
43 static const char kUnknownDeviceMode[];
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[];
53 explicit EnterpriseInstallAttributes(
54 chromeos::CryptohomeClient* cryptohome_client);
55 ~EnterpriseInstallAttributes();
57 // 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,
59 // which takes a while to register its DBus interface. See
60 // http://crosbug.com/37367 for background on this.
61 void ReadCacheFile(const base::FilePath& cache_file);
63 // Makes sure the local caches for enterprise-related install attributes are
64 // up-to-date with what cryptohome has. This method checks the readiness of
65 // attributes and read them if ready. Actual read will be performed in
66 // ReadAttributesIfReady().
67 void ReadImmutableAttributes(const base::Closure& callback);
69 // Locks the device to be an enterprise device registered by the given user.
70 // This can also be called after the lock has already been taken, in which
71 // case it checks that the passed user agrees with the locked attribute.
72 // |callback| must not be null and is called with the result.
73 void LockDevice(const std::string& user,
74 DeviceMode device_mode,
75 const std::string& device_id,
76 const LockResultCallback& callback);
78 // Checks whether this is an enterprise device.
79 bool IsEnterpriseDevice();
81 // Checks whether this is a consumer kiosk enabled device.
82 bool IsConsumerKioskDeviceWithAutoLaunch();
84 // Gets the domain this device belongs to or an empty string if the device is
85 // not an enterprise device.
86 std::string GetDomain();
88 // Gets the user that registered the device. Returns an empty string if the
89 // device is not an enterprise device.
90 std::string GetRegistrationUser();
92 // Gets the device id that was generated when the device was registered.
93 // Returns an empty string if the device is not an enterprise device or the
94 // device id was not stored in the lockbox (prior to R19).
95 std::string GetDeviceId();
97 // Gets the mode the device was enrolled to. The return value for devices that
98 // are not locked yet will be DEVICE_MODE_UNKNOWN.
103 std::string registration_user_;
104 std::string registration_domain_;
105 std::string registration_device_id_;
106 DeviceMode registration_mode_;
109 // Decodes the install attributes provided in |attr_map|.
110 void DecodeInstallAttributes(
111 const std::map<std::string, std::string>& attr_map);
113 // Helper for ReadImmutableAttributes.
114 void ReadAttributesIfReady(
115 const base::Closure& callback,
116 chromeos::DBusMethodCallStatus call_status,
119 // Helper for LockDevice(). Handles the result of InstallAttributesIsReady()
120 // and continue processing LockDevice if the result is true.
121 void LockDeviceIfAttributesIsReady(
122 const std::string& user,
123 DeviceMode device_mode,
124 const std::string& device_id,
125 const LockResultCallback& callback,
126 chromeos::DBusMethodCallStatus call_status,
129 // Confirms the registered user and invoke the callback.
130 void OnReadImmutableAttributes(const std::string& user,
131 const LockResultCallback& callback);
133 chromeos::CryptohomeClient* cryptohome_client_;
135 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_;
137 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes);
140 } // namespace policy
142 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_