1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/enterprise/signals/device_info_fetcher.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/enterprise/signals/device_info_fetcher_mac.h"
#elif BUILDFLAG(IS_WIN)
#include "chrome/browser/enterprise/signals/device_info_fetcher_win.h"
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/enterprise/signals/device_info_fetcher_linux.h"
#endif
namespace enterprise_signals {
using SettingValue = device_signals::SettingValue;
namespace {
// When true, will force DeviceInfoFetcher::CreateInstance to return a stubbed
// instance. Used for testing.
bool force_stub_for_testing = false;
// When true, will force DeviceInfoFetcher to return duplicate mac addresses in
// the signal.
bool force_duplicate_mac_addresses = false;
// Stub implementation of DeviceInfoFetcher.
class StubDeviceFetcher : public DeviceInfoFetcher {
public:
StubDeviceFetcher() = default;
~StubDeviceFetcher() override = default;
StubDeviceFetcher(const StubDeviceFetcher&) = delete;
StubDeviceFetcher& operator=(const StubDeviceFetcher&) = delete;
DeviceInfo Fetch() override {
DeviceInfo device_info;
device_info.os_name = "stubOS";
device_info.os_version = "0.0.0.0";
device_info.security_patch_level = "security patch level";
device_info.device_host_name = "midnightshift";
device_info.device_model = "topshot";
device_info.serial_number = "twirlchange";
device_info.secure_boot_enabled = SettingValue::ENABLED;
device_info.screen_lock_secured = SettingValue::ENABLED;
device_info.disk_encrypted = SettingValue::DISABLED;
device_info.mac_addresses.push_back("00:00:00:00:00:00");
if (force_duplicate_mac_addresses) {
device_info.mac_addresses.push_back("00:00:00:00:00:00");
}
device_info.windows_machine_domain = "MACHINE_DOMAIN";
device_info.windows_user_domain = "USER_DOMAIN";
return device_info;
}
};
} // namespace
DeviceInfo::DeviceInfo() = default;
DeviceInfo::~DeviceInfo() = default;
DeviceInfo::DeviceInfo(const DeviceInfo&) = default;
DeviceInfo::DeviceInfo(DeviceInfo&&) = default;
DeviceInfoFetcher::DeviceInfoFetcher() = default;
DeviceInfoFetcher::~DeviceInfoFetcher() = default;
// static
std::unique_ptr<DeviceInfoFetcher> DeviceInfoFetcher::CreateInstance() {
if (force_stub_for_testing) {
return std::make_unique<StubDeviceFetcher>();
}
return CreateInstanceInternal();
}
#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_WIN) && \
!(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
// static
std::unique_ptr<DeviceInfoFetcher> DeviceInfoFetcher::CreateInstanceInternal() {
return std::make_unique<StubDeviceFetcher>();
}
#endif
// static
std::unique_ptr<DeviceInfoFetcher>
DeviceInfoFetcher::CreateStubInstanceForTesting() {
return std::make_unique<StubDeviceFetcher>();
}
// static
void DeviceInfoFetcher::SetForceStubForTesting(bool should_force) {
force_stub_for_testing = should_force;
}
// static
void DeviceInfoFetcher::SetForceDuplicateMacAddressesForTesting(
bool should_force) {
force_duplicate_mac_addresses = should_force;
}
} // namespace enterprise_signals
|