diff options
author | Bertrand SIMONNET <bsimonnet@google.com> | 2015-08-04 15:06:21 -0700 |
---|---|---|
committer | Gaurav Shah <gauravsh@google.com> | 2015-08-10 21:23:28 +0000 |
commit | 52e1d55fd20cfb51178c65ec12f6e83aa0e5e503 (patch) | |
tree | 09b22344db19ef2ff6df9fc5421f1ee2e2d73110 /metrics | |
parent | eeb7ef02840a0aea976917e7a38fb340f93f8b34 (diff) | |
download | core-52e1d55fd20cfb51178c65ec12f6e83aa0e5e503.tar.gz core-52e1d55fd20cfb51178c65ec12f6e83aa0e5e503.tar.bz2 core-52e1d55fd20cfb51178c65ec12f6e83aa0e5e503.zip |
metrics: Cleanup the system profile setter.
Android does not use some of the original mechanisms available in Chrome
OS, so simplify the code by removing them.
BUG: 22879597
Change-Id: I25d71f464cb99d4ca51eab758695fcd59c1d2f3d
Diffstat (limited to 'metrics')
-rw-r--r-- | metrics/uploader/system_profile_cache.cc | 134 | ||||
-rw-r--r-- | metrics/uploader/system_profile_cache.h | 29 | ||||
-rw-r--r-- | metrics/uploader/upload_service.cc | 2 |
3 files changed, 28 insertions, 137 deletions
diff --git a/metrics/uploader/system_profile_cache.cc b/metrics/uploader/system_profile_cache.cc index 00def44af..30a1ff55b 100644 --- a/metrics/uploader/system_profile_cache.cc +++ b/metrics/uploader/system_profile_cache.cc @@ -16,7 +16,6 @@ #include "persistent_integer.h" #include "uploader/metrics_log_base.h" #include "uploader/proto/chrome_user_metrics_extension.pb.h" -#include "vboot/crossystem.h" namespace { @@ -63,43 +62,24 @@ 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_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"; + std::string channel; + if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) || + !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version) || + !base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", + &profile_.build_target_id)) { + LOG(ERROR) << "Could not initialize system profile."; return false; } - std::string channel_string; - 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)) { - DLOG(INFO) << "Set the product id to " << profile_.product_id; - } - profile_.client_id = - testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile); + testing_ ? "client_id_test" : + GetPersistentGUID(metrics::kMetricsGUIDFilePath); + profile_.hardware_class = "unknown"; + profile_.channel = ProtoChannelFromString(channel); // Increment the session_id everytime we initialize this. If metrics_daemon // does not crash, this should correspond to the number of reboots of the // system. - // TODO(bsimonnet): Change this to map to the number of time system-services - // is started. session_id_->Add(1); profile_.session_id = static_cast<int32_t>(session_id_->Get()); @@ -123,21 +103,21 @@ void SystemProfileCache::Populate( metrics_proto->set_session_id(profile_.session_id); // Sets the product id. - metrics_proto->set_product(profile_.product_id); + metrics_proto->set_product(9); metrics::SystemProfileProto* profile_proto = metrics_proto->mutable_system_profile(); profile_proto->mutable_hardware()->set_hardware_class( profile_.hardware_class); - profile_proto->set_app_version(profile_.app_version); + profile_proto->set_app_version(profile_.version); profile_proto->set_channel(profile_.channel); - - metrics::SystemProfileProto_OS* os = profile_proto->mutable_os(); - os->set_name(profile_.os_name); - os->set_version(profile_.os_version); + metrics::SystemProfileProto_BrilloDeviceData* device_data = + profile_proto->mutable_brillo(); + device_data->set_build_target_id(profile_.build_target_id); } -std::string SystemProfileCache::GetPersistentGUID(const std::string& filename) { +std::string SystemProfileCache::GetPersistentGUID( + const std::string& filename) { std::string guid; base::FilePath filepath(filename); if (!base::ReadFileToString(filepath, &guid)) { @@ -149,87 +129,15 @@ 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<std::string> 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); - - if (testing_) { - // if we are in test mode, we do not call crossystem directly. - DLOG(INFO) << "skipping hardware id"; - *hwid = ""; - return true; - } - - char buffer[128]; - if (buffer != VbGetSystemPropertyString("hwid", buffer, sizeof(buffer))) { - LOG(ERROR) << "error getting hwid"; - return false; - } - - *hwid = std::string(buffer); - return true; -} - -bool SystemProfileCache::GetProductId(int* product_id) const { - chromeos::OsReleaseReader reader; - if (testing_) { - base::FilePath root(config_root_); - reader.LoadTestingOnly(root); - } else { - reader.Load(); - } - - std::string id; - if (reader.GetString(kProductIdFieldName, &id)) { - CHECK(base::StringToInt(id, product_id)) << "Failed to convert product_id " - << id << " to int."; - return true; - } - return false; -} - metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString( const std::string& channel) { - - if (channel == "stable-channel") { + if (channel == "stable") { return metrics::SystemProfileProto::CHANNEL_STABLE; - } else if (channel == "dev-channel") { + } else if (channel == "dev") { return metrics::SystemProfileProto::CHANNEL_DEV; - } else if (channel == "beta-channel") { + } else if (channel == "beta") { return metrics::SystemProfileProto::CHANNEL_BETA; - } else if (channel == "canary-channel") { + } else if (channel == "canary") { return metrics::SystemProfileProto::CHANNEL_CANARY; } diff --git a/metrics/uploader/system_profile_cache.h b/metrics/uploader/system_profile_cache.h index 4a492c24e..b6ff3377c 100644 --- a/metrics/uploader/system_profile_cache.h +++ b/metrics/uploader/system_profile_cache.h @@ -21,14 +21,12 @@ class ChromeUserMetricsExtension; } struct SystemProfile { - std::string os_name; - std::string os_version; - metrics::SystemProfileProto::Channel channel; - std::string app_version; + std::string version; std::string hardware_class; std::string client_id; - int32_t session_id; - int32_t product_id; + int session_id; + metrics::SystemProfileProto::Channel channel; + std::string build_target_id; }; // Retrieves general system informations needed by the protobuf for context and @@ -42,9 +40,9 @@ class SystemProfileCache : public SystemProfileSetter { SystemProfileCache(bool testing, const std::string& config_root); // Populates the ProfileSystem protobuf with system information. - void Populate(metrics::ChromeUserMetricsExtension* profile_proto) override; + void Populate(metrics::ChromeUserMetricsExtension* metrics_proto) override; - // Converts a string representation of the channel (|channel|-channel) to a + // Converts a string representation of the channel to a // SystemProfileProto_Channel static metrics::SystemProfileProto_Channel ProtoChannelFromString( const std::string& channel); @@ -65,21 +63,6 @@ class SystemProfileCache : public SystemProfileSetter { // Initializes |profile_| only if it has not been yet initialized. bool InitializeOrCheck(); - // Gets the hardware ID using crossystem - bool GetHardwareId(std::string* hwid); - - // 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.cc b/metrics/uploader/upload_service.cc index f24b0a850..34110045a 100644 --- a/metrics/uploader/upload_service.cc +++ b/metrics/uploader/upload_service.cc @@ -21,7 +21,7 @@ #include "serialization/serialization_utils.h" #include "uploader/metrics_log.h" #include "uploader/sender_http.h" -#include "uploader/system_profile_cache.h" +#include "uploader/system_profile_setter.h" const int UploadService::kMaxFailedUpload = 10; |