Chromium Code Reviews| Index: chromeos/system/statistics_provider.cc |
| diff --git a/chromeos/system/statistics_provider.cc b/chromeos/system/statistics_provider.cc |
| index 18c697681aa5e6ff66a2578d14a6db441b2bcc91..8e40339151d9d4e765bf5fcde627ad0a0d93209c 100644 |
| --- a/chromeos/system/statistics_provider.cc |
| +++ b/chromeos/system/statistics_provider.cc |
| @@ -17,6 +17,7 @@ |
| #include "base/memory/singleton.h" |
| #include "base/path_service.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_util.h" |
| #include "base/synchronization/cancellation_flag.h" |
| #include "base/synchronization/waitable_event.h" |
| #include "base/sys_info.h" |
| @@ -41,13 +42,14 @@ const char* kCrosSystemTool[] = { "/usr/bin/crossystem" }; |
| const char kCrosSystemEq[] = "="; |
| const char kCrosSystemDelim[] = "\n"; |
| const char kCrosSystemCommentDelim[] = "#"; |
| -const char kCrosSystemUnknownValue[] = "(error)"; |
| +const char kCrosSystemValueError[] = "(error)"; |
| const char kHardwareClassCrosSystemKey[] = "hwid"; |
| -const char kUnknownHardwareClass[] = "unknown"; |
| +const char kHardwareClassValueUnknown[] = "unknown"; |
| -// File to get system vendor information from. |
| +// File to get system vendor information from. (x86-only) |
| const char kSystemVendorFile[] = "/sys/class/dmi/id/sys_vendor"; |
| +const char kSystemVendorValueUnknown[] = "unknown"; |
| // Key/value delimiters of machine hardware info file. machine-info is generated |
| // only for OOBE and enterprise enrollment and may not be present. See |
| @@ -158,6 +160,7 @@ const char kFirmwareTypeValueDeveloper[] = "developer"; |
| const char kFirmwareTypeValueNonchrome[] = "nonchrome"; |
| const char kFirmwareTypeValueNormal[] = "normal"; |
| const char kHardwareClassKey[] = "hardware_class"; |
| +const char kHardwareClassValueVM[] = "VM"; |
| const char kSystemVendorKey[] = "system_vendor"; |
| const char kOffersCouponCodeKey[] = "ubind_attribute"; |
| const char kOffersGroupCodeKey[] = "gbind_attribute"; |
| @@ -447,12 +450,6 @@ void StatisticsProviderImpl::LoadMachineStatistics(bool load_oem_manifest) { |
| } |
| } |
| - if (base::SysInfo::IsRunningOnChromeOS()) { |
| - std::string system_vendor; |
| - base::ReadFileToString(base::FilePath(kSystemVendorFile), &system_vendor); |
| - machine_info_[kSystemVendorKey] = system_vendor; |
| - } |
| - |
| parser.GetNameValuePairsFromFile(machine_info_path, |
| kMachineHardwareInfoEq, |
| kMachineHardwareInfoDelim); |
| @@ -466,10 +463,31 @@ void StatisticsProviderImpl::LoadMachineStatistics(bool load_oem_manifest) { |
| // Ensure that the hardware class key is present with the expected |
| // key name, and if it couldn't be retrieved, that the value is "unknown". |
| std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; |
| - if (hardware_class.empty() || hardware_class == kCrosSystemUnknownValue) |
| - machine_info_[kHardwareClassKey] = kUnknownHardwareClass; |
| - else |
| + if (hardware_class.empty() || hardware_class == kCrosSystemValueError) { |
| + machine_info_[kHardwareClassKey] = kHardwareClassValueUnknown; |
| + // If the HWID couldn't be retrieved and the the FWID is "nonchrome", assume |
| + // that ChromeOS is running inside a VM and set the HWID to "VM" |
|
Daniel Erat
2016/08/05 19:03:54
nit: s/ChromeOS/Chrome OS/; also add trailing peri
achuithb
2016/08/05 21:23:32
You should add a real test to detect that you're i
|
| + if (base::SysInfo::IsRunningOnChromeOS()) { |
| + if (machine_info_[kFirmwareTypeKey] == kFirmwareTypeValueNonchrome) { |
| + LOG(WARNING) << "Detected non-Chrome firmware with malformed HWID," |
|
Daniel Erat
2016/08/05 19:03:54
nit: maybe move this down and combine it with the
|
| + << " assuming VM environment."; |
| + machine_info_[kHardwareClassKey] = kHardwareClassValueVM; |
| + std::string system_vendor; |
| + base::ReadFileToString(base::FilePath(kSystemVendorFile), |
| + &system_vendor); |
| + base::TrimWhitespaceASCII(system_vendor, base::TRIM_ALL, |
| + &system_vendor); |
| + if (system_vendor.empty()) |
| + machine_info_[kSystemVendorKey] = kSystemVendorValueUnknown; |
|
Daniel Erat
2016/08/05 19:03:54
if i'm not misreading this, machine_info_[kSystemV
|
| + else |
| + machine_info_[kSystemVendorKey] = system_vendor; |
| + LOG(WARNING) << "The system vendor is '" |
| + << machine_info_[kSystemVendorKey] << "'."; |
| + } |
| + } |
| + } else { |
| machine_info_[kHardwareClassKey] = hardware_class; |
| + } |
| if (load_oem_manifest) { |
| // If kAppOemManifestFile switch is specified, load OEM Manifest file. |