Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/system/statistics_provider.h" | 5 #include "chromeos/system/statistics_provider.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_util.h" | |
| 20 #include "base/synchronization/cancellation_flag.h" | 21 #include "base/synchronization/cancellation_flag.h" |
| 21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/sys_info.h" | 23 #include "base/sys_info.h" |
| 23 #include "base/task_runner.h" | 24 #include "base/task_runner.h" |
| 24 #include "base/threading/thread_restrictions.h" | 25 #include "base/threading/thread_restrictions.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "base/values.h" | 27 #include "base/values.h" |
| 27 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h" | 28 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h" |
| 28 #include "chromeos/chromeos_constants.h" | 29 #include "chromeos/chromeos_constants.h" |
| 29 #include "chromeos/chromeos_paths.h" | 30 #include "chromeos/chromeos_paths.h" |
| 30 #include "chromeos/chromeos_switches.h" | 31 #include "chromeos/chromeos_switches.h" |
| 31 #include "chromeos/system/name_value_pairs_parser.h" | 32 #include "chromeos/system/name_value_pairs_parser.h" |
| 32 | 33 |
| 33 namespace chromeos { | 34 namespace chromeos { |
| 34 namespace system { | 35 namespace system { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Path to the tool used to get system info, and delimiters for the output | 39 // Path to the tool used to get system info, and delimiters for the output |
| 39 // format of the tool. | 40 // format of the tool. |
| 40 const char* kCrosSystemTool[] = { "/usr/bin/crossystem" }; | 41 const char* kCrosSystemTool[] = { "/usr/bin/crossystem" }; |
| 41 const char kCrosSystemEq[] = "="; | 42 const char kCrosSystemEq[] = "="; |
| 42 const char kCrosSystemDelim[] = "\n"; | 43 const char kCrosSystemDelim[] = "\n"; |
| 43 const char kCrosSystemCommentDelim[] = "#"; | 44 const char kCrosSystemCommentDelim[] = "#"; |
| 44 const char kCrosSystemUnknownValue[] = "(error)"; | 45 const char kCrosSystemValueError[] = "(error)"; |
| 45 | 46 |
| 46 const char kHardwareClassCrosSystemKey[] = "hwid"; | 47 const char kHardwareClassCrosSystemKey[] = "hwid"; |
| 47 const char kUnknownHardwareClass[] = "unknown"; | 48 const char kHardwareClassValueUnknown[] = "unknown"; |
| 48 | 49 |
| 49 // File to get system vendor information from. | 50 // File to get system vendor information from. (x86-only) |
| 50 const char kSystemVendorFile[] = "/sys/class/dmi/id/sys_vendor"; | 51 const char kSystemVendorFile[] = "/sys/class/dmi/id/sys_vendor"; |
| 52 const char kSystemVendorValueUnknown[] = "unknown"; | |
| 51 | 53 |
| 52 // Key/value delimiters of machine hardware info file. machine-info is generated | 54 // Key/value delimiters of machine hardware info file. machine-info is generated |
| 53 // only for OOBE and enterprise enrollment and may not be present. See | 55 // only for OOBE and enterprise enrollment and may not be present. See |
| 54 // login-manager/init/machine-info.conf. | 56 // login-manager/init/machine-info.conf. |
| 55 const char kMachineHardwareInfoEq[] = "="; | 57 const char kMachineHardwareInfoEq[] = "="; |
| 56 const char kMachineHardwareInfoDelim[] = " \n"; | 58 const char kMachineHardwareInfoDelim[] = " \n"; |
| 57 | 59 |
| 58 // File to get ECHO coupon info from, and key/value delimiters of | 60 // File to get ECHO coupon info from, and key/value delimiters of |
| 59 // the file. | 61 // the file. |
| 60 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; | 62 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 const char kCheckEnrollmentKey[] = "check_enrollment"; | 153 const char kCheckEnrollmentKey[] = "check_enrollment"; |
| 152 const char kCustomizationIdKey[] = "customization_id"; | 154 const char kCustomizationIdKey[] = "customization_id"; |
| 153 const char kDevSwitchBootKey[] = "devsw_boot"; | 155 const char kDevSwitchBootKey[] = "devsw_boot"; |
| 154 const char kDevSwitchBootValueDev[] = "1"; | 156 const char kDevSwitchBootValueDev[] = "1"; |
| 155 const char kDevSwitchBootValueVerified[] = "0"; | 157 const char kDevSwitchBootValueVerified[] = "0"; |
| 156 const char kFirmwareTypeKey[] = "mainfw_type"; | 158 const char kFirmwareTypeKey[] = "mainfw_type"; |
| 157 const char kFirmwareTypeValueDeveloper[] = "developer"; | 159 const char kFirmwareTypeValueDeveloper[] = "developer"; |
| 158 const char kFirmwareTypeValueNonchrome[] = "nonchrome"; | 160 const char kFirmwareTypeValueNonchrome[] = "nonchrome"; |
| 159 const char kFirmwareTypeValueNormal[] = "normal"; | 161 const char kFirmwareTypeValueNormal[] = "normal"; |
| 160 const char kHardwareClassKey[] = "hardware_class"; | 162 const char kHardwareClassKey[] = "hardware_class"; |
| 163 const char kHardwareClassValueVM[] = "VM"; | |
| 161 const char kSystemVendorKey[] = "system_vendor"; | 164 const char kSystemVendorKey[] = "system_vendor"; |
| 162 const char kOffersCouponCodeKey[] = "ubind_attribute"; | 165 const char kOffersCouponCodeKey[] = "ubind_attribute"; |
| 163 const char kOffersGroupCodeKey[] = "gbind_attribute"; | 166 const char kOffersGroupCodeKey[] = "gbind_attribute"; |
| 164 const char kRlzBrandCodeKey[] = "rlz_brand_code"; | 167 const char kRlzBrandCodeKey[] = "rlz_brand_code"; |
| 165 const char kWriteProtectSwitchBootKey[] = "wpsw_boot"; | 168 const char kWriteProtectSwitchBootKey[] = "wpsw_boot"; |
| 166 const char kWriteProtectSwitchBootValueOff[] = "0"; | 169 const char kWriteProtectSwitchBootValueOff[] = "0"; |
| 167 const char kWriteProtectSwitchBootValueOn[] = "1"; | 170 const char kWriteProtectSwitchBootValueOn[] = "1"; |
| 168 const char kRegionKey[] = "region"; | 171 const char kRegionKey[] = "region"; |
| 169 const char kInitialLocaleKey[] = "initial_locale"; | 172 const char kInitialLocaleKey[] = "initial_locale"; |
| 170 const char kInitialTimezoneKey[] = "initial_timezone"; | 173 const char kInitialTimezoneKey[] = "initial_timezone"; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 int bytes_written = base::WriteFile(machine_info_path, | 443 int bytes_written = base::WriteFile(machine_info_path, |
| 441 stub_contents.c_str(), | 444 stub_contents.c_str(), |
| 442 stub_contents.size()); | 445 stub_contents.size()); |
| 443 // static_cast<int> is fine because stub_contents is small. | 446 // static_cast<int> is fine because stub_contents is small. |
| 444 if (bytes_written < static_cast<int>(stub_contents.size())) { | 447 if (bytes_written < static_cast<int>(stub_contents.size())) { |
| 445 LOG(ERROR) << "Error writing machine info stub: " | 448 LOG(ERROR) << "Error writing machine info stub: " |
| 446 << machine_info_path.value(); | 449 << machine_info_path.value(); |
| 447 } | 450 } |
| 448 } | 451 } |
| 449 | 452 |
| 450 if (base::SysInfo::IsRunningOnChromeOS()) { | |
| 451 std::string system_vendor; | |
| 452 base::ReadFileToString(base::FilePath(kSystemVendorFile), &system_vendor); | |
| 453 machine_info_[kSystemVendorKey] = system_vendor; | |
| 454 } | |
| 455 | |
| 456 parser.GetNameValuePairsFromFile(machine_info_path, | 453 parser.GetNameValuePairsFromFile(machine_info_path, |
| 457 kMachineHardwareInfoEq, | 454 kMachineHardwareInfoEq, |
| 458 kMachineHardwareInfoDelim); | 455 kMachineHardwareInfoDelim); |
| 459 parser.GetNameValuePairsFromFile(base::FilePath(kEchoCouponFile), | 456 parser.GetNameValuePairsFromFile(base::FilePath(kEchoCouponFile), |
| 460 kEchoCouponEq, | 457 kEchoCouponEq, |
| 461 kEchoCouponDelim); | 458 kEchoCouponDelim); |
| 462 parser.GetNameValuePairsFromFile(base::FilePath(kVpdFile), | 459 parser.GetNameValuePairsFromFile(base::FilePath(kVpdFile), |
| 463 kVpdEq, | 460 kVpdEq, |
| 464 kVpdDelim); | 461 kVpdDelim); |
| 465 | 462 |
| 466 // Ensure that the hardware class key is present with the expected | 463 // Ensure that the hardware class key is present with the expected |
| 467 // key name, and if it couldn't be retrieved, that the value is "unknown". | 464 // key name, and if it couldn't be retrieved, that the value is "unknown". |
| 468 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; | 465 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; |
| 469 if (hardware_class.empty() || hardware_class == kCrosSystemUnknownValue) | 466 if (hardware_class.empty() || hardware_class == kCrosSystemValueError) { |
| 470 machine_info_[kHardwareClassKey] = kUnknownHardwareClass; | 467 machine_info_[kHardwareClassKey] = kHardwareClassValueUnknown; |
| 471 else | 468 // If the HWID couldn't be retrieved and the the FWID is "nonchrome", assume |
| 469 // 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
| |
| 470 if (base::SysInfo::IsRunningOnChromeOS()) { | |
| 471 if (machine_info_[kFirmwareTypeKey] == kFirmwareTypeValueNonchrome) { | |
| 472 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
| |
| 473 << " assuming VM environment."; | |
| 474 machine_info_[kHardwareClassKey] = kHardwareClassValueVM; | |
| 475 std::string system_vendor; | |
| 476 base::ReadFileToString(base::FilePath(kSystemVendorFile), | |
| 477 &system_vendor); | |
| 478 base::TrimWhitespaceASCII(system_vendor, base::TRIM_ALL, | |
| 479 &system_vendor); | |
| 480 if (system_vendor.empty()) | |
| 481 machine_info_[kSystemVendorKey] = kSystemVendorValueUnknown; | |
|
Daniel Erat
2016/08/05 19:03:54
if i'm not misreading this, machine_info_[kSystemV
| |
| 482 else | |
| 483 machine_info_[kSystemVendorKey] = system_vendor; | |
| 484 LOG(WARNING) << "The system vendor is '" | |
| 485 << machine_info_[kSystemVendorKey] << "'."; | |
| 486 } | |
| 487 } | |
| 488 } else { | |
| 472 machine_info_[kHardwareClassKey] = hardware_class; | 489 machine_info_[kHardwareClassKey] = hardware_class; |
| 490 } | |
| 473 | 491 |
| 474 if (load_oem_manifest) { | 492 if (load_oem_manifest) { |
| 475 // If kAppOemManifestFile switch is specified, load OEM Manifest file. | 493 // If kAppOemManifestFile switch is specified, load OEM Manifest file. |
| 476 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 494 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 477 if (command_line->HasSwitch(switches::kAppOemManifestFile)) { | 495 if (command_line->HasSwitch(switches::kAppOemManifestFile)) { |
| 478 LoadOemManifestFromFile( | 496 LoadOemManifestFromFile( |
| 479 command_line->GetSwitchValuePath(switches::kAppOemManifestFile)); | 497 command_line->GetSwitchValuePath(switches::kAppOemManifestFile)); |
| 480 } else if (base::SysInfo::IsRunningOnChromeOS()) { | 498 } else if (base::SysInfo::IsRunningOnChromeOS()) { |
| 481 LoadOemManifestFromFile(base::FilePath(kOemManifestFilePath)); | 499 LoadOemManifestFromFile(base::FilePath(kOemManifestFilePath)); |
| 482 } | 500 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 return StatisticsProviderImpl::GetInstance(); | 589 return StatisticsProviderImpl::GetInstance(); |
| 572 } | 590 } |
| 573 | 591 |
| 574 // static | 592 // static |
| 575 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { | 593 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { |
| 576 g_test_statistics_provider = test_provider; | 594 g_test_statistics_provider = test_provider; |
| 577 } | 595 } |
| 578 | 596 |
| 579 } // namespace system | 597 } // namespace system |
| 580 } // namespace chromeos | 598 } // namespace chromeos |
| OLD | NEW |