PolicyManager: Convert EvalStatus to a enum class.

This simple patch converts EvalStatus to a enum class to have better
type checking over the enum and group the constants on a namespace.

BUG=chromium:340871
TEST=Build and run unit tests.

Change-Id: I56e8d52325c5de578a6c78c7c85c9dccf61d48a1
Reviewed-on: https://chromium-review.googlesource.com/189635
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/chromeos_policy.cc b/policy_manager/chromeos_policy.cc
index 95578aa..cd10918 100644
--- a/policy_manager/chromeos_policy.cc
+++ b/policy_manager/chromeos_policy.cc
@@ -15,7 +15,7 @@
                                               bool* result) const {
   // TODO(deymo): Write this policy implementation with the actual policy.
   *result = true;
-  return EvalStatusSucceeded;
+  return EvalStatus::kSucceeded;
 }
 
 }  // namespace chromeos_policy_manager
diff --git a/policy_manager/default_policy.h b/policy_manager/default_policy.h
index 20f6668..f5fe89d 100644
--- a/policy_manager/default_policy.h
+++ b/policy_manager/default_policy.h
@@ -22,7 +22,7 @@
                                         std::string* error,
                                         bool* result) const {
     *result = true;
-    return EvalStatusSucceeded;
+    return EvalStatus::kSucceeded;
   }
 
  private:
diff --git a/policy_manager/policy.h b/policy_manager/policy.h
index 7554824..762b9a5 100644
--- a/policy_manager/policy.h
+++ b/policy_manager/policy.h
@@ -11,10 +11,10 @@
 namespace chromeos_policy_manager {
 
 // The three different results of a policy request.
-enum EvalStatus {
-  EvalStatusFailed,
-  EvalStatusSucceeded,
-  EvalStatusAskMeAgainLater,
+enum class EvalStatus {
+  kFailed,
+  kSucceeded,
+  kAskMeAgainLater,
 };
 
 // The Policy class is an interface to the ensemble of policy requests that the
@@ -31,8 +31,8 @@
   // first argument, a State instance, a returned error message, a returned
   // value and optionally followed by one or more arbitrary constant arguments.
   //
-  // When the implementation fails, the method returns EvalStatusFailed and sets
-  // the |error| string.
+  // When the implementation fails, the method returns EvalStatus::kFailed and
+  // sets the |error| string.
 
   // UpdateCheckAllowed returns whether it is allowed to request an update check
   // to Omaha.
diff --git a/policy_manager/policy_manager-inl.h b/policy_manager/policy_manager-inl.h
index e4b9666..798860f 100644
--- a/policy_manager/policy_manager-inl.h
+++ b/policy_manager/policy_manager-inl.h
@@ -20,13 +20,13 @@
   EvalStatus status = (policy_.get()->*policy_method)(&ec, state_.get(), &error,
                                                       result, args...);
 
-  if (status == EvalStatusFailed) {
+  if (status == EvalStatus::kFailed) {
     LOG(WARNING) << "PolicyRequest() failed with error: " << error;
     error.clear();
     status = (default_policy_.*policy_method)(&ec, state_.get(), &error,
                                               result, args...);
 
-    if (status == EvalStatusFailed) {
+    if (status == EvalStatus::kFailed) {
       LOG(WARNING) << "Request to DefaultPolicy also failed, passing error.";
     }
   }
diff --git a/policy_manager/policy_manager.h b/policy_manager/policy_manager.h
index d0be4e2..b84f493 100644
--- a/policy_manager/policy_manager.h
+++ b/policy_manager/policy_manager.h
@@ -30,10 +30,11 @@
   // |policy_method|.
   //
   // When the policy request succeeds, the |result| is set and the method
-  // returns EvalStatusSucceeded, otherwise, the |result| may not be set. Also,
-  // if the policy implementation should block, this method returns immediately
-  // with EvalStatusAskMeAgainLater. In case of failure EvalStatusFailed is
-  // returned and the |error| message is set, which must not be NULL.
+  // returns EvalStatus::kSucceeded, otherwise, the |result| may not be set.
+  // Also, if the policy implementation should block, this method returns
+  // immediately with EvalStatus::kAskMeAgainLater. In case of failure
+  // EvalStatus::kFailed is returned and the |error| message is set, which must
+  // not be NULL.
   //
   // An example call to this method is:
   //   pm.PolicyRequest(&Policy::SomePolicyMethod, &bool_result, arg1, arg2);
@@ -51,7 +52,7 @@
   scoped_ptr<const Policy> policy_;
 
   // A safe default value to the current policy. This policy is used whenever
-  // a policy implementation fails with EvalStatusFailed.
+  // a policy implementation fails with EvalStatus::kFailed.
   const DefaultPolicy default_policy_;
 
   // State Providers.
diff --git a/policy_manager/policy_manager_unittest.cc b/policy_manager/policy_manager_unittest.cc
index ba001c9..b9253d3 100644
--- a/policy_manager/policy_manager_unittest.cc
+++ b/policy_manager/policy_manager_unittest.cc
@@ -39,7 +39,7 @@
                                         string* error,
                                         bool* result) const {
     *error = "FailingPolicy failed.";
-    return EvalStatusFailed;
+    return EvalStatus::kFailed;
   }
 };
 
@@ -48,14 +48,14 @@
   virtual EvalStatus UpdateCheckAllowed(EvaluationContext* ec, State* state,
                                         string* error,
                                         bool* result) const {
-    return EvalStatusAskMeAgainLater;
+    return EvalStatus::kAskMeAgainLater;
   }
 };
 
 TEST_F(PmPolicyManagerTest, PolicyRequestCall) {
   bool result;
   EvalStatus status = pmut_.PolicyRequest(&Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatusSucceeded);
+  EXPECT_EQ(status, EvalStatus::kSucceeded);
 }
 
 TEST_F(PmPolicyManagerTest, PolicyRequestCallsPolicy) {
@@ -65,9 +65,9 @@
 
   // Tests that the method is called on the policy_ instance.
   EXPECT_CALL(*policy, UpdateCheckAllowed(_, _, _, _))
-      .WillOnce(Return(EvalStatusSucceeded));
+      .WillOnce(Return(EvalStatus::kSucceeded));
   EvalStatus status = pmut_.PolicyRequest(&Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatusSucceeded);
+  EXPECT_EQ(status, EvalStatus::kSucceeded);
 }
 
 TEST_F(PmPolicyManagerTest, PolicyRequestCallsDefaultOnError) {
@@ -77,7 +77,7 @@
   // which will set this as true.
   bool result = false;
   EvalStatus status = pmut_.PolicyRequest(&Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatusSucceeded);
+  EXPECT_EQ(status, EvalStatus::kSucceeded);
   EXPECT_TRUE(result);
 }
 
@@ -86,7 +86,7 @@
   bool result;
 
   EvalStatus status = pmut_.PolicyRequest(&Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatusAskMeAgainLater);
+  EXPECT_EQ(status, EvalStatus::kAskMeAgainLater);
 }
 
 }  // namespace chromeos_policy_manager