Change ErrorCode into an enum class.
This change is needed in order for us to be able to import ErrorCode
symbols from chromeos_update_engine into chromeos_update_manager.
Unfortunately, shifting from plain 'enum' into an 'enum class' means
that the compiler treats the new class as a distinct type from int,
which in turn means that plenty of seamless arithmetic/bitwise
operations we used for manipulating error code values throughout the
code needed to be retrofitted with static_cast operators.
In the future, we should consider imposing a proper abstraction on
update engine error codes that'll prevent mingling with value encoding
directly and prevent such nastiness. It'll also make things more
coherent (types, semantics) and safer.
BUG=chromium:358329
TEST=Unit tests.
Change-Id: Ie55fa566b764cdab6c4785d995fb6daee4cb32d3
Reviewed-on: https://chromium-review.googlesource.com/203209
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/download_action.cc b/download_action.cc
index 8d211ea..6f4811a 100644
--- a/download_action.cc
+++ b/download_action.cc
@@ -33,7 +33,7 @@
system_state_(system_state),
http_fetcher_(http_fetcher),
writer_(NULL),
- code_(kErrorCodeSuccess),
+ code_(ErrorCode::kSuccess),
delegate_(NULL),
bytes_received_(0),
p2p_sharing_fd_(-1),
@@ -172,7 +172,7 @@
if (rc < 0) {
LOG(ERROR) << "Unable to open output file " << install_plan_.install_path;
// report error to processor
- processor_->ActionComplete(this, kErrorCodeInstallDeviceOpenError);
+ processor_->ActionComplete(this, ErrorCode::kInstallDeviceOpenError);
return;
}
if (delta_performer_.get() &&
@@ -181,7 +181,7 @@
LOG(ERROR) << "Unable to open kernel file "
<< install_plan_.kernel_install_path.c_str();
writer_->Close();
- processor_->ActionComplete(this, kErrorCodeKernelDeviceOpenError);
+ processor_->ActionComplete(this, ErrorCode::kKernelDeviceOpenError);
return;
}
if (delegate_) {
@@ -291,11 +291,11 @@
delegate_->SetDownloadStatus(false); // Set to inactive.
}
ErrorCode code =
- successful ? kErrorCodeSuccess : kErrorCodeDownloadTransferError;
- if (code == kErrorCodeSuccess && delta_performer_.get()) {
+ successful ? ErrorCode::kSuccess : ErrorCode::kDownloadTransferError;
+ if (code == ErrorCode::kSuccess && delta_performer_.get()) {
code = delta_performer_->VerifyPayload(install_plan_.payload_hash,
install_plan_.payload_size);
- if (code != kErrorCodeSuccess) {
+ if (code != ErrorCode::kSuccess) {
LOG(ERROR) << "Download of " << install_plan_.download_url
<< " failed due to payload verification error.";
// Delete p2p file, if applicable.
@@ -307,18 +307,18 @@
&install_plan_.rootfs_size,
&install_plan_.rootfs_hash)) {
LOG(ERROR) << "Unable to get new partition hash info.";
- code = kErrorCodeDownloadNewPartitionInfoError;
+ code = ErrorCode::kDownloadNewPartitionInfoError;
}
}
// Write the path to the output pipe if we're successful.
- if (code == kErrorCodeSuccess && HasOutputPipe())
+ if (code == ErrorCode::kSuccess && HasOutputPipe())
SetOutputObject(install_plan_);
processor_->ActionComplete(this, code);
}
void DownloadAction::TransferTerminated(HttpFetcher *fetcher) {
- if (code_ != kErrorCodeSuccess) {
+ if (code_ != ErrorCode::kSuccess) {
processor_->ActionComplete(this, code_);
}
}