update_engine: Add UMA stats for rollback
Adding the following UMA stats:
- UpdateEngine.Check.TargetVersion: first section of the Chrome OS
target version set by device policy. Sent during update checks if
target version policy is set.
- UpdateEngine.Check.RollbackTargetVersion: first section of the
Chrome OS target version if rollback is also allowed. Sent during
update checks if both policies are set.
- UpdateEngine.EnterpriseRollback.Success: first section of the
Chrome OS version to which rollback succeeded. Sent after
successful installation of the rollback image.
- UpdateEngine.EnterpriseRollback.Failure: first section of the
Chrome OS version to which rollback failed. Sent after
installation of the rollback image failed.
Chromium CL of the new histograms: crrev.com/c/1069129
BUG=chromium:843622
TEST='cros_run_unit_tests --board=caroline --packages update_engine'
Change-Id: I0b76fa286498ae0a1830a90034734ed9aa5efd3d
Reviewed-on: https://chromium-review.googlesource.com/1062033
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Marton Hunyady <hunyadym@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jesse Doherty <jwd@chromium.org>
diff --git a/common/utils.cc b/common/utils.cc
index f651823..68cad51 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -291,7 +291,10 @@
return true;
}
-bool PReadAll(const FileDescriptorPtr& fd, void* buf, size_t count, off_t offset,
+bool PReadAll(const FileDescriptorPtr& fd,
+ void* buf,
+ size_t count,
+ off_t offset,
ssize_t* out_bytes_read) {
TEST_AND_RETURN_FALSE_ERRNO(fd->Seek(offset, SEEK_SET) !=
static_cast<off_t>(-1));
@@ -1067,6 +1070,18 @@
return true;
}
+int VersionPrefix(const std::string& version) {
+ if (version.empty()) {
+ return 0;
+ }
+ vector<string> tokens = base::SplitString(
+ version, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ int value;
+ if (tokens.empty() || !base::StringToInt(tokens[0], &value))
+ return -1; // Target version is invalid.
+ return value;
+}
+
} // namespace utils
} // namespace chromeos_update_engine