Commit 53d84ae8 authored by tnagel@chromium.org's avatar tnagel@chromium.org

Encapsulate data-format constants in EnterpriseInstallAttributes.

Also add mentioning that some constants have been copied to Chromium OS.

BUG=none

Review URL: https://codereview.chromium.org/397543005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283772 0039d316-1c4b-4281-b951-d872f2087c98
parent d4c56f65
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h" #include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
#include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chromeos/chromeos_paths.h" #include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h" #include "chromeos/dbus/fake_dbus_thread_manager.h"
...@@ -35,22 +34,14 @@ DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {} ...@@ -35,22 +34,14 @@ DevicePolicyCrosTestHelper::~DevicePolicyCrosTestHelper() {}
void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() { void DevicePolicyCrosTestHelper::MarkAsEnterpriseOwned() {
OverridePaths(); OverridePaths();
cryptohome::SerializedInstallAttributes install_attrs_proto; const std::string install_attrs_blob(
cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL; EnterpriseInstallAttributes::
GetEnterpriseOwnedInstallAttributesBlobForTesting(
attribute = install_attrs_proto.add_attributes(); device_policy_.policy_data().username()));
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
attribute->set_value("true");
attribute = install_attrs_proto.add_attributes();
attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
attribute->set_value(device_policy_.policy_data().username());
base::FilePath install_attrs_file; base::FilePath install_attrs_file;
ASSERT_TRUE( ASSERT_TRUE(
PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file)); PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &install_attrs_file));
const std::string install_attrs_blob(
install_attrs_proto.SerializeAsString());
ASSERT_EQ(static_cast<int>(install_attrs_blob.size()), ASSERT_EQ(static_cast<int>(install_attrs_blob.size()),
base::WriteFile(install_attrs_file, base::WriteFile(install_attrs_file,
install_attrs_blob.c_str(), install_attrs_blob.c_str(),
......
...@@ -22,40 +22,6 @@ namespace cryptohome_util = chromeos::cryptohome_util; ...@@ -22,40 +22,6 @@ namespace cryptohome_util = chromeos::cryptohome_util;
namespace { namespace {
// Translates DeviceMode constants to strings used in the lockbox.
std::string GetDeviceModeString(DeviceMode mode) {
switch (mode) {
case DEVICE_MODE_CONSUMER:
return EnterpriseInstallAttributes::kConsumerDeviceMode;
case DEVICE_MODE_ENTERPRISE:
return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
case DEVICE_MODE_RETAIL_KIOSK:
return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
case DEVICE_MODE_PENDING:
case DEVICE_MODE_NOT_SET:
break;
}
NOTREACHED() << "Invalid device mode: " << mode;
return EnterpriseInstallAttributes::kUnknownDeviceMode;
}
// Translates strings used in the lockbox to DeviceMode values.
DeviceMode GetDeviceModeFromString(
const std::string& mode) {
if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
return DEVICE_MODE_CONSUMER;
else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
return DEVICE_MODE_ENTERPRISE;
else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
return DEVICE_MODE_RETAIL_KIOSK;
else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
NOTREACHED() << "Unknown device mode string: " << mode;
return DEVICE_MODE_NOT_SET;
}
bool ReadMapKey(const std::map<std::string, std::string>& map, bool ReadMapKey(const std::map<std::string, std::string>& map,
const std::string& key, const std::string& key,
std::string* value) { std::string* value) {
...@@ -69,25 +35,23 @@ bool ReadMapKey(const std::map<std::string, std::string>& map, ...@@ -69,25 +35,23 @@ bool ReadMapKey(const std::map<std::string, std::string>& map,
} // namespace } // namespace
const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer"; // static
const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise"; std::string
const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk"; EnterpriseInstallAttributes::GetEnterpriseOwnedInstallAttributesBlobForTesting(
const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] = const std::string& user_name) {
"consumer_kiosk"; cryptohome::SerializedInstallAttributes install_attrs_proto;
const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown"; cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL;
const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] = attribute = install_attrs_proto.add_attributes();
"enterprise.device_id"; attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] = attribute->set_value("true");
"enterprise.domain";
const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] = attribute = install_attrs_proto.add_attributes();
"enterprise.mode"; attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] = attribute->set_value(user_name);
"enterprise.owned";
const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] = return install_attrs_proto.SerializeAsString();
"enterprise.user"; }
const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
"consumer.app_kiosk_enabled";
EnterpriseInstallAttributes::EnterpriseInstallAttributes( EnterpriseInstallAttributes::EnterpriseInstallAttributes(
chromeos::CryptohomeClient* cryptohome_client) chromeos::CryptohomeClient* cryptohome_client)
...@@ -333,6 +297,61 @@ DeviceMode EnterpriseInstallAttributes::GetMode() { ...@@ -333,6 +297,61 @@ DeviceMode EnterpriseInstallAttributes::GetMode() {
return registration_mode_; return registration_mode_;
} }
// Note that some of these constants have been copied to
// login_manager/device_policy_service.cc. Please make sure that all changes to
// the constants are reflected there as well.
const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer";
const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise";
const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk";
const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] =
"consumer_kiosk";
const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown";
const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] =
"enterprise.device_id";
const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] =
"enterprise.domain";
const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] =
"enterprise.mode";
const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] =
"enterprise.owned";
const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] =
"enterprise.user";
const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
"consumer.app_kiosk_enabled";
std::string EnterpriseInstallAttributes::GetDeviceModeString(DeviceMode mode) {
switch (mode) {
case DEVICE_MODE_CONSUMER:
return EnterpriseInstallAttributes::kConsumerDeviceMode;
case DEVICE_MODE_ENTERPRISE:
return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
case DEVICE_MODE_RETAIL_KIOSK:
return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
case DEVICE_MODE_PENDING:
case DEVICE_MODE_NOT_SET:
break;
}
NOTREACHED() << "Invalid device mode: " << mode;
return EnterpriseInstallAttributes::kUnknownDeviceMode;
}
DeviceMode EnterpriseInstallAttributes::GetDeviceModeFromString(
const std::string& mode) {
if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
return DEVICE_MODE_CONSUMER;
else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
return DEVICE_MODE_ENTERPRISE;
else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
return DEVICE_MODE_RETAIL_KIOSK;
else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
NOTREACHED() << "Unknown device mode string: " << mode;
return DEVICE_MODE_NOT_SET;
}
void EnterpriseInstallAttributes::DecodeInstallAttributes( void EnterpriseInstallAttributes::DecodeInstallAttributes(
const std::map<std::string, std::string>& attr_map) { const std::map<std::string, std::string>& attr_map) {
std::string enterprise_owned; std::string enterprise_owned;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_method_call_status.h"
...@@ -35,20 +36,9 @@ class EnterpriseInstallAttributes { ...@@ -35,20 +36,9 @@ class EnterpriseInstallAttributes {
// A callback to handle responses of methods returning a LockResult value. // A callback to handle responses of methods returning a LockResult value.
typedef base::Callback<void(LockResult lock_result)> LockResultCallback; typedef base::Callback<void(LockResult lock_result)> LockResultCallback;
// Constants for the possible device modes that can be stored in the lockbox. // Return serialized InstallAttributes of an enterprise-owned configuration.
static const char kConsumerDeviceMode[]; static std::string GetEnterpriseOwnedInstallAttributesBlobForTesting(
static const char kEnterpriseDeviceMode[]; const std::string& user_name);
static const char kRetailKioskDeviceMode[];
static const char kConsumerKioskDeviceMode[];
static const char kUnknownDeviceMode[];
// Field names in the lockbox.
static const char kAttrEnterpriseDeviceId[];
static const char kAttrEnterpriseDomain[];
static const char kAttrEnterpriseMode[];
static const char kAttrEnterpriseOwned[];
static const char kAttrEnterpriseUser[];
static const char kAttrConsumerKioskEnabled[];
explicit EnterpriseInstallAttributes( explicit EnterpriseInstallAttributes(
chromeos::CryptohomeClient* cryptohome_client); chromeos::CryptohomeClient* cryptohome_client);
...@@ -106,6 +96,36 @@ class EnterpriseInstallAttributes { ...@@ -106,6 +96,36 @@ class EnterpriseInstallAttributes {
DeviceMode registration_mode_; DeviceMode registration_mode_;
private: private:
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
DeviceLockedFromOlderVersion);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
ReadCacheFile);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
ReadCacheFileForConsumerKiosk);
FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest,
VerifyFakeInstallAttributesCache);
// Constants for the possible device modes that can be stored in the lockbox.
static const char kConsumerDeviceMode[];
static const char kEnterpriseDeviceMode[];
static const char kRetailKioskDeviceMode[];
static const char kConsumerKioskDeviceMode[];
static const char kUnknownDeviceMode[];
// Field names in the lockbox.
static const char kAttrEnterpriseDeviceId[];
static const char kAttrEnterpriseDomain[];
static const char kAttrEnterpriseMode[];
static const char kAttrEnterpriseOwned[];
static const char kAttrEnterpriseUser[];
static const char kAttrConsumerKioskEnabled[];
// Translates DeviceMode constants to strings used in the lockbox.
std::string GetDeviceModeString(DeviceMode mode);
// Translates strings used in the lockbox to DeviceMode values.
DeviceMode GetDeviceModeFromString(const std::string& mode);
// Decodes the install attributes provided in |attr_map|. // Decodes the install attributes provided in |attr_map|.
void DecodeInstallAttributes( void DecodeInstallAttributes(
const std::map<std::string, std::string>& attr_map); const std::map<std::string, std::string>& attr_map);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment