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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 // login-manager/init/machine-info.conf. | 54 // login-manager/init/machine-info.conf. |
| 55 const char kMachineHardwareInfoEq[] = "="; | 55 const char kMachineHardwareInfoEq[] = "="; |
| 56 const char kMachineHardwareInfoDelim[] = " \n"; | 56 const char kMachineHardwareInfoDelim[] = " \n"; |
| 57 | 57 |
| 58 // File to get ECHO coupon info from, and key/value delimiters of | 58 // File to get ECHO coupon info from, and key/value delimiters of |
| 59 // the file. | 59 // the file. |
| 60 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; | 60 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; |
| 61 const char kEchoCouponEq[] = "="; | 61 const char kEchoCouponEq[] = "="; |
| 62 const char kEchoCouponDelim[] = "\n"; | 62 const char kEchoCouponDelim[] = "\n"; |
| 63 | 63 |
| 64 // File to get VPD info from, and key/value delimiters of the file. | 64 // Key/value delimiters for VPD file. |
| 65 const char kVpdFile[] = "/var/log/vpd_2.0.txt"; | |
| 66 const char kVpdEq[] = "="; | 65 const char kVpdEq[] = "="; |
| 67 const char kVpdDelim[] = "\n"; | 66 const char kVpdDelim[] = "\n"; |
| 68 | 67 |
| 69 // File to get regional data from. | 68 // File to get regional data from. |
| 70 const char kCrosRegions[] = "/usr/share/misc/cros-regions.json"; | 69 const char kCrosRegions[] = "/usr/share/misc/cros-regions.json"; |
| 71 | 70 |
| 72 // Timeout that we should wait for statistics to get loaded | 71 // Timeout that we should wait for statistics to get loaded |
| 73 const int kTimeoutSecs = 3; | 72 const int kTimeoutSecs = 3; |
| 74 | 73 |
| 75 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode. | 74 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode. |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 PathService::Get(chromeos::FILE_MACHINE_INFO, &machine_info_path); | 463 PathService::Get(chromeos::FILE_MACHINE_INFO, &machine_info_path); |
| 465 if (!base::SysInfo::IsRunningOnChromeOS() && | 464 if (!base::SysInfo::IsRunningOnChromeOS() && |
| 466 !base::PathExists(machine_info_path)) { | 465 !base::PathExists(machine_info_path)) { |
| 467 // Use time value to create an unique stub serial because clashes of the | 466 // Use time value to create an unique stub serial because clashes of the |
| 468 // same serial for the same domain invalidate earlier enrollments. Persist | 467 // same serial for the same domain invalidate earlier enrollments. Persist |
| 469 // to disk to keep it constant across restarts (required for re-enrollment | 468 // to disk to keep it constant across restarts (required for re-enrollment |
| 470 // testing). | 469 // testing). |
| 471 std::string stub_contents = | 470 std::string stub_contents = |
| 472 "\"serial_number\"=\"stub_" + | 471 "\"serial_number\"=\"stub_" + |
| 473 base::Int64ToString(base::Time::Now().ToJavaTime()) + "\"\n"; | 472 base::Int64ToString(base::Time::Now().ToJavaTime()) + "\"\n"; |
| 474 int bytes_written = base::WriteFile(machine_info_path, | 473 int bytes_written = base::WriteFile( |
| 475 stub_contents.c_str(), | 474 machine_info_path, stub_contents.c_str(), stub_contents.size()); |
| 476 stub_contents.size()); | |
| 477 // static_cast<int> is fine because stub_contents is small. | |
| 478 if (bytes_written < static_cast<int>(stub_contents.size())) { | 475 if (bytes_written < static_cast<int>(stub_contents.size())) { |
| 479 LOG(ERROR) << "Error writing machine info stub: " | 476 LOG(ERROR) << "Error writing machine info stub: " |
|
Daniel Erat
2017/03/23 23:35:23
nit: PLOG(ERROR) will include errno
Thiemo Nagel
2017/04/11 15:29:32
Done.
| |
| 480 << machine_info_path.value(); | 477 << machine_info_path.value(); |
| 481 } | 478 } |
| 482 } | 479 } |
| 483 | 480 |
| 481 base::FilePath vpd_path; | |
| 482 PathService::Get(chromeos::FILE_VPD, &vpd_path); | |
| 483 if (!base::SysInfo::IsRunningOnChromeOS() && !base::PathExists(vpd_path)) { | |
| 484 std::string stub_contents = "\"ActivateDate\"=\"2000-01\"\n"; | |
| 485 int bytes_written = | |
| 486 base::WriteFile(vpd_path, stub_contents.c_str(), stub_contents.size()); | |
| 487 if (bytes_written < static_cast<int>(stub_contents.size())) { | |
| 488 LOG(ERROR) << "Error writing vpd stub: " << vpd_path.value(); | |
|
Daniel Erat
2017/03/23 23:35:23
PLOG(ERROR) here as well
Thiemo Nagel
2017/04/11 15:29:32
Done.
| |
| 489 } | |
| 490 } | |
| 491 | |
| 484 parser.GetNameValuePairsFromFile(machine_info_path, | 492 parser.GetNameValuePairsFromFile(machine_info_path, |
| 485 kMachineHardwareInfoEq, | 493 kMachineHardwareInfoEq, |
| 486 kMachineHardwareInfoDelim); | 494 kMachineHardwareInfoDelim); |
| 487 parser.GetNameValuePairsFromFile(base::FilePath(kEchoCouponFile), | 495 parser.GetNameValuePairsFromFile(base::FilePath(kEchoCouponFile), |
| 488 kEchoCouponEq, | 496 kEchoCouponEq, |
| 489 kEchoCouponDelim); | 497 kEchoCouponDelim); |
| 490 parser.GetNameValuePairsFromFile(base::FilePath(kVpdFile), | 498 parser.GetNameValuePairsFromFile(vpd_path, |
| 491 kVpdEq, | 499 kVpdEq, |
| 492 kVpdDelim); | 500 kVpdDelim); |
| 493 | 501 |
| 494 // Ensure that the hardware class key is present with the expected | 502 // Ensure that the hardware class key is present with the expected |
| 495 // key name, and if it couldn't be retrieved, that the value is "unknown". | 503 // key name, and if it couldn't be retrieved, that the value is "unknown". |
| 496 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; | 504 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; |
| 497 if (hardware_class.empty() || hardware_class == kCrosSystemValueError) { | 505 if (hardware_class.empty() || hardware_class == kCrosSystemValueError) { |
| 498 machine_info_[kHardwareClassKey] = kHardwareClassValueUnknown; | 506 machine_info_[kHardwareClassKey] = kHardwareClassValueUnknown; |
| 499 } else { | 507 } else { |
| 500 machine_info_[kHardwareClassKey] = hardware_class; | 508 machine_info_[kHardwareClassKey] = hardware_class; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 return StatisticsProviderImpl::GetInstance(); | 625 return StatisticsProviderImpl::GetInstance(); |
| 618 } | 626 } |
| 619 | 627 |
| 620 // static | 628 // static |
| 621 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { | 629 void StatisticsProvider::SetTestProvider(StatisticsProvider* test_provider) { |
| 622 g_test_statistics_provider = test_provider; | 630 g_test_statistics_provider = test_provider; |
| 623 } | 631 } |
| 624 | 632 |
| 625 } // namespace system | 633 } // namespace system |
| 626 } // namespace chromeos | 634 } // namespace chromeos |
| OLD | NEW |