diff --git a/metrics/uploader/system_profile_cache.cc b/metrics/uploader/system_profile_cache.cc index 54c269390..28e0f0923 100644 --- a/metrics/uploader/system_profile_cache.cc +++ b/metrics/uploader/system_profile_cache.cc @@ -12,6 +12,7 @@ #include "base/guid.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/string_util.h" #include "base/sys_info.h" #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" #include "metrics/persistent_integer.h" @@ -26,6 +27,21 @@ const char kProductIdFieldName[] = "GOOGLE_METRICS_PRODUCT_ID"; } // namespace +std::string ChannelToString( + const metrics::SystemProfileProto_Channel& channel) { + switch (channel) { + case metrics::SystemProfileProto::CHANNEL_STABLE: + return "STABLE"; + case metrics::SystemProfileProto::CHANNEL_DEV: + return "DEV"; + case metrics::SystemProfileProto::CHANNEL_BETA: + return "BETA"; + case metrics::SystemProfileProto::CHANNEL_CANARY: + return "CANARY"; + default: + return "UNKNOWN"; + } +} SystemProfileCache::SystemProfileCache() : initialized_(false), @@ -48,12 +64,17 @@ bool SystemProfileCache::Initialize() { CHECK(!initialized_) << "this should be called only once in the metrics_daemon lifetime."; + std::string chromeos_version; + std::string board; + std::string build_type; if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_NAME", &profile_.os_name) || !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &profile_.os_version) || - !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_DESCRIPTION", - &profile_.app_version) || + !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD", &board) || + !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE", + &build_type) || + !GetChromeOSVersion(&chromeos_version) || !GetHardwareId(&profile_.hardware_class)) { DLOG(ERROR) << "failing to initialize profile cache"; return false; @@ -63,6 +84,9 @@ bool SystemProfileCache::Initialize() { base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &channel_string); profile_.channel = ProtoChannelFromString(channel_string); + profile_.app_version = chromeos_version + " (" + build_type + ")" + + ChannelToString(profile_.channel) + " " + board; + // If the product id is not defined, use the default one from the protobuf. profile_.product_id = metrics::ChromeUserMetricsExtension::CHROME; if (GetProductId(&profile_.product_id)) { @@ -126,6 +150,39 @@ std::string SystemProfileCache::GetPersistentGUID(const std::string& filename) { return guid; } +bool SystemProfileCache::GetChromeOSVersion(std::string* version) { + if (testing_) { + *version = "0.0.0.0"; + return true; + } + + std::string milestone, build, branch, patch; + unsigned tmp; + if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_CHROME_MILESTONE", + &milestone) && + base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_NUMBER", + &build) && + base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BRANCH_NUMBER", + &branch) && + base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_PATCH_NUMBER", + &patch)) { + // Convert to uint to ensure those fields are positive numbers. + if (base::StringToUint(milestone, &tmp) && + base::StringToUint(build, &tmp) && + base::StringToUint(branch, &tmp) && + base::StringToUint(patch, &tmp)) { + std::vector parts = {milestone, build, branch, patch}; + *version = JoinString(parts, '.'); + return true; + } + DLOG(INFO) << "The milestone, build, branch or patch is not a positive " + << "number."; + return false; + } + DLOG(INFO) << "Field missing from /etc/lsb-release"; + return false; +} + bool SystemProfileCache::GetHardwareId(std::string* hwid) { CHECK(hwid); diff --git a/metrics/uploader/system_profile_cache.h b/metrics/uploader/system_profile_cache.h index 95f554f8e..bbfc90def 100644 --- a/metrics/uploader/system_profile_cache.h +++ b/metrics/uploader/system_profile_cache.h @@ -72,6 +72,15 @@ class SystemProfileCache : public SystemProfileSetter { // Gets the product ID from the GOOGLE_METRICS_PRODUCT_ID field. bool GetProductId(int* product_id) const; + // Generate the formatted chromeos version from the fields in + // /etc/lsb-release. The format is A.B.C.D where A, B, C and D are positive + // integer representing: + // * the chrome milestone + // * the build number + // * the branch number + // * the patch number + bool GetChromeOSVersion(std::string* version); + bool initialized_; bool testing_; std::string config_root_; diff --git a/metrics/uploader/upload_service_test.cc b/metrics/uploader/upload_service_test.cc index ff96f85ac..363c8c18a 100644 --- a/metrics/uploader/upload_service_test.cc +++ b/metrics/uploader/upload_service_test.cc @@ -189,7 +189,9 @@ TEST_F(UploadServiceTest, ValuesInConfigFileAreSent) { "CHROMEOS_RELEASE_NAME=" + name + "\nCHROMEOS_RELEASE_VERSION=version\n" "CHROMEOS_RELEASE_DESCRIPTION=description beta-channel test\n" - "CHROMEOS_RELEASE_TRACK=beta-channel"); + "CHROMEOS_RELEASE_TRACK=beta-channel\n" + "CHROMEOS_RELEASE_BUILD_TYPE=developer build\n" + "CHROMEOS_RELEASE_BOARD=myboard"); base::SysInfo::SetChromeOSVersionInfoForTest(content, base::Time()); scoped_ptr histogram =