blob: 312bd77c7393d36aa06962ad5d951b804d078147 [file] [log] [blame]
[email protected]d59799992012-02-24 13:04:041// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6c900e52011-04-18 11:09:072// 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]6c900e52011-04-18 11:09:077
[email protected]aea6e3b2013-01-18 00:27:538#include <map>
[email protected]6c900e52011-04-18 11:09:079#include <string>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
[email protected]aea6e3b2013-01-18 00:27:5313#include "base/file_path.h"
[email protected]d59799992012-02-24 13:04:0414#include "chrome/browser/policy/cloud_policy_constants.h"
[email protected]6c900e52011-04-18 11:09:0715
16namespace chromeos {
17class CryptohomeLibrary;
18}
19
20namespace policy {
21
22// Brokers access to the enterprise-related installation-time attributes on
23// ChromeOS.
24class 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]aea6e3b2013-01-18 00:27:5334 // Standard cache file name.
[email protected]650b2d52013-02-10 03:41:4535 static const base::FilePath::CharType kCacheFilePath[];
[email protected]aea6e3b2013-01-18 00:27:5336
[email protected]6c900e52011-04-18 11:09:0737 explicit EnterpriseInstallAttributes(chromeos::CryptohomeLibrary* cryptohome);
38
[email protected]aea6e3b2013-01-18 00:27:5339 // 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]650b2d52013-02-10 03:41:4542 void ReadCacheFile(const base::FilePath& cache_file);
[email protected]aea6e3b2013-01-18 00:27:5343
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]6c900e52011-04-18 11:09:0748 // 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]d59799992012-02-24 13:04:0451 LockResult LockDevice(const std::string& user,
52 DeviceMode device_mode,
53 const std::string& device_id) WARN_UNUSED_RESULT;
[email protected]6c900e52011-04-18 11:09:0754
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]d59799992012-02-24 13:04:0466 // 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]6c900e52011-04-18 11:09:0775 private:
[email protected]aea6e3b2013-01-18 00:27:5376 // Decodes the install attributes provided in |attr_map|.
77 void DecodeInstallAttributes(
78 const std::map<std::string, std::string>& attr_map);
[email protected]6c900e52011-04-18 11:09:0779
80 chromeos::CryptohomeLibrary* cryptohome_;
81
82 bool device_locked_;
83 std::string registration_user_;
[email protected]d59799992012-02-24 13:04:0484 std::string registration_domain_;
85 std::string registration_device_id_;
86 DeviceMode registration_mode_;
[email protected]6c900e52011-04-18 11:09:0787
88 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes);
89};
90
91} // namespace policy
92
93#endif // CHROME_BROWSER_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_