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. The cache file is used to work around slow
58 // cryptohome startup, which takes a while to register its DBus interface.
59 // See http://crosbug.com/37367 for background on this.
60 void ReadCacheFile(const base::FilePath
& cache_file
);
62 // Makes sure the local caches for enterprise-related install attributes are
63 // up-to-date with what cryptohome has. This method checks the readiness of
64 // attributes and read them if ready. Actual read will be performed in
65 // ReadAttributesIfReady().
66 void ReadImmutableAttributes(const base::Closure
& callback
);
68 // Locks the device to be an enterprise device registered by the given user.
69 // This can also be called after the lock has already been taken, in which
70 // case it checks that the passed user agrees with the locked attribute.
71 // |callback| must not be null and is called with the result.
72 void LockDevice(const std::string
& user
,
73 DeviceMode device_mode
,
74 const std::string
& device_id
,
75 const LockResultCallback
& callback
);
77 // Checks whether this is an enterprise device.
78 bool IsEnterpriseDevice();
80 // Checks whether this is a consumer kiosk enabled device.
81 bool IsConsumerKioskDevice();
83 // Gets the domain this device belongs to or an empty string if the device is
84 // not an enterprise device.
85 std::string
GetDomain();
87 // Gets the user that registered the device. Returns an empty string if the
88 // device is not an enterprise device.
89 std::string
GetRegistrationUser();
91 // Gets the device id that was generated when the device was registered.
92 // Returns an empty string if the device is not an enterprise device or the
93 // device id was not stored in the lockbox (prior to R19).
94 std::string
GetDeviceId();
96 // Gets the mode the device was enrolled to. The return value for devices that
97 // are not locked yet will be DEVICE_MODE_UNKNOWN.
102 std::string registration_user_
;
103 std::string registration_domain_
;
104 std::string registration_device_id_
;
105 DeviceMode registration_mode_
;
108 // Decodes the install attributes provided in |attr_map|.
109 void DecodeInstallAttributes(
110 const std::map
<std::string
, std::string
>& attr_map
);
112 // Helper for ReadImmutableAttributes.
113 void ReadAttributesIfReady(
114 const base::Closure
& callback
,
115 chromeos::DBusMethodCallStatus call_status
,
118 // Helper for LockDevice(). Handles the result of InstallAttributesIsReady()
119 // and continue processing LockDevice if the result is true.
120 void LockDeviceIfAttributesIsReady(
121 const std::string
& user
,
122 DeviceMode device_mode
,
123 const std::string
& device_id
,
124 const LockResultCallback
& callback
,
125 chromeos::DBusMethodCallStatus call_status
,
128 // Confirms the registered user and invoke the callback.
129 void OnReadImmutableAttributes(const std::string
& user
,
130 const LockResultCallback
& callback
);
132 chromeos::CryptohomeClient
* cryptohome_client_
;
134 base::WeakPtrFactory
<EnterpriseInstallAttributes
> weak_ptr_factory_
;
136 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes
);
139 } // namespace policy
141 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_