enum class fixups - testing non-zero
Fixups in preparation for changing the mojom C++ binding generator to
produce enum classes instead of just enums. Specifically, address
issues where enums were being tested for truth by assuming that they
would be implicitly converted to ints and checked for non-zero-ness.
BUG=
R=viettrungluu@chromium.org
Review URL: https://codereview.chromium.org/1355403002 .
diff --git a/examples/echo_terminal/main.cc b/examples/echo_terminal/main.cc
index 548a463..a199a5c 100644
--- a/examples/echo_terminal/main.cc
+++ b/examples/echo_terminal/main.cc
@@ -41,7 +41,7 @@
// |Read()| callback:
void OnRead(mojo::files::Error error, mojo::Array<uint8_t> bytes_read) {
- if (error) {
+ if (error != mojo::files::ERROR_OK) {
LOG(ERROR) << "Error: Read(): " << error;
delete this;
return;
@@ -71,7 +71,7 @@
// |Write()| callback:
void OnWrite(mojo::files::Error error, uint32_t num_bytes_written) {
- if (error) {
+ if (error != mojo::files::ERROR_OK) {
LOG(ERROR) << "Error: Write(): " << error;
delete this;
return;
diff --git a/services/files/directory_impl.cc b/services/files/directory_impl.cc
index 279c3bd..40aa33c 100644
--- a/services/files/directory_impl.cc
+++ b/services/files/directory_impl.cc
@@ -190,14 +190,16 @@
DCHECK(!path.is_null());
DCHECK(dir_fd_.is_valid());
- if (Error error = IsPathValid(path)) {
+ Error error = IsPathValid(path);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
// TODO(vtl): Make sure the path doesn't exit this directory (if appropriate).
// TODO(vtl): Maybe allow absolute paths?
- if (Error error = ValidateOpenFlags(open_flags, false)) {
+ error = ValidateOpenFlags(open_flags, false);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
@@ -235,14 +237,16 @@
DCHECK(!path.is_null());
DCHECK(dir_fd_.is_valid());
- if (Error error = IsPathValid(path)) {
+ Error error = IsPathValid(path);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
// TODO(vtl): Make sure the path doesn't exit this directory (if appropriate).
// TODO(vtl): Maybe allow absolute paths?
- if (Error error = ValidateOpenFlags(open_flags, false)) {
+ error = ValidateOpenFlags(open_flags, false);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
@@ -284,11 +288,14 @@
DCHECK(!new_path.is_null());
DCHECK(dir_fd_.is_valid());
- if (Error error = IsPathValid(path)) {
+ Error error = IsPathValid(path);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
- if (Error error = IsPathValid(new_path)) {
+
+ error = IsPathValid(new_path);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
@@ -309,13 +316,15 @@
DCHECK(!path.is_null());
DCHECK(dir_fd_.is_valid());
- if (Error error = IsPathValid(path)) {
+ Error error = IsPathValid(path);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
// TODO(vtl): See TODOs about |path| in OpenFile().
- if (Error error = ValidateDeleteFlags(delete_flags)) {
+ error = ValidateDeleteFlags(delete_flags);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
diff --git a/services/files/file_impl.cc b/services/files/file_impl.cc
index 4c1ca4a..ba0e058 100644
--- a/services/files/file_impl.cc
+++ b/services/files/file_impl.cc
@@ -71,11 +71,15 @@
callback.Run(ERROR_OUT_OF_RANGE, Array<uint8_t>());
return;
}
- if (Error error = IsOffsetValid(offset)) {
+
+ Error error = IsOffsetValid(offset);
+ if (error != ERROR_OK) {
callback.Run(error, Array<uint8_t>());
return;
}
- if (Error error = IsWhenceValid(whence)) {
+
+ error = IsWhenceValid(whence);
+ if (error != ERROR_OK) {
callback.Run(error, Array<uint8_t>());
return;
}
@@ -125,11 +129,15 @@
callback.Run(ERROR_OUT_OF_RANGE, 0);
return;
}
- if (Error error = IsOffsetValid(offset)) {
+
+ Error error = IsOffsetValid(offset);
+ if (error != ERROR_OK) {
callback.Run(error, 0);
return;
}
- if (Error error = IsWhenceValid(whence)) {
+
+ error = IsWhenceValid(whence);
+ if (error != ERROR_OK) {
callback.Run(error, 0);
return;
}
@@ -172,11 +180,15 @@
callback.Run(ERROR_CLOSED);
return;
}
- if (Error error = IsOffsetValid(offset)) {
+
+ Error error = IsOffsetValid(offset);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
- if (Error error = IsWhenceValid(whence)) {
+
+ error = IsWhenceValid(whence);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
@@ -194,11 +206,15 @@
callback.Run(ERROR_CLOSED);
return;
}
- if (Error error = IsOffsetValid(offset)) {
+
+ Error error = IsOffsetValid(offset);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
- if (Error error = IsWhenceValid(whence)) {
+
+ error = IsWhenceValid(whence);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
@@ -219,11 +235,15 @@
callback.Run(ERROR_CLOSED, 0);
return;
}
- if (Error error = IsOffsetValid(offset)) {
+
+ Error error = IsOffsetValid(offset);
+ if (error != ERROR_OK) {
callback.Run(error, 0);
return;
}
- if (Error error = IsWhenceValid(whence)) {
+
+ error = IsWhenceValid(whence);
+ if (error != ERROR_OK) {
callback.Run(error, 0);
return;
}
@@ -255,7 +275,9 @@
callback.Run(ERROR_INVALID_ARGUMENT);
return;
}
- if (Error error = IsOffsetValid(size)) {
+
+ Error error = IsOffsetValid(size);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
diff --git a/services/files/shared_impl.cc b/services/files/shared_impl.cc
index 8584f82..830eee3 100644
--- a/services/files/shared_impl.cc
+++ b/services/files/shared_impl.cc
@@ -60,11 +60,14 @@
DCHECK_NE(fd, -1);
struct timespec times[2];
- if (Error error = TimespecOrNowToStandardTimespec(atime.get(), ×[0])) {
+ Error error = TimespecOrNowToStandardTimespec(atime.get(), ×[0]);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}
- if (Error error = TimespecOrNowToStandardTimespec(mtime.get(), ×[1])) {
+
+ error = TimespecOrNowToStandardTimespec(mtime.get(), ×[1]);
+ if (error != ERROR_OK) {
callback.Run(error);
return;
}