shill: Add function to pretty-print result from ConnectionHealthChecker.

BUG=chromium:229982
TEST=build and run unit-tests.

Change-Id: I19d0b29bca278d28d7521871e03f0c1097f821d6
Reviewed-on: https://gerrit.chromium.org/gerrit/47789
Reviewed-by: Arman Uguray <armansito@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/cellular.cc b/cellular.cc
index c7510ec..c051a59 100644
--- a/cellular.cc
+++ b/cellular.cc
@@ -363,7 +363,8 @@
 
 void Cellular::OnConnectionHealthCheckerResult(
       ConnectionHealthChecker::Result result) {
-  SLOG(Cellular, 2) << __func__ << "(Result = " << result << ")";
+  SLOG(Cellular, 2) << __func__ << "(Result = "
+                    << ConnectionHealthChecker::ResultToString(result) << ")";
 
   if (result == ConnectionHealthChecker::kResultElongatedTimeWait ||
       result == ConnectionHealthChecker::kResultCongestedTxQueue) {
diff --git a/connection_health_checker.cc b/connection_health_checker.cc
index 54b077b..ee635ee 100644
--- a/connection_health_checker.cc
+++ b/connection_health_checker.cc
@@ -119,6 +119,26 @@
   health_check_in_progress_ = false;
 }
 
+const char *ConnectionHealthChecker::ResultToString(
+    ConnectionHealthChecker::Result result) {
+  switch(result) {
+    case kResultUnknown:
+      return "Unknown";
+    case kResultInProgress:
+      return "InProgress";
+    case kResultConnectionFailure:
+      return "ConnectionFailure";
+    case kResultElongatedTimeWait:
+      return "ElongatedTimeWait";
+    case kResultCongestedTxQueue:
+      return "CongestedTxQueue";
+    case kResultSuccess:
+      return "Success";
+    default:
+      return "Invalid";
+  }
+}
+
 void ConnectionHealthChecker::SetupTcpConnection() {
   IPAddress ip = remote_ips_.front();
   SLOG(Connection, 3) << __func__ << ": Starting connection at "
diff --git a/connection_health_checker.h b/connection_health_checker.h
index f788878..22ace95 100644
--- a/connection_health_checker.h
+++ b/connection_health_checker.h
@@ -39,6 +39,7 @@
  public:
   typedef std::queue<IPAddress> IPAddressQueue;
 
+  // TODO(pprabhu): Rename kResultElongatedTimeWait to kResultTearDownFailure.
   enum Result {
     // There was some problem in the setup of ConnctionHealthChecker.
     // Could not attempt a tcp connection.
@@ -84,6 +85,8 @@
   // Calling Stop() on a Stop()ed health check is a no-op.
   virtual void Stop();
 
+  static const char *ResultToString(Result result);
+
   // Accessors.
   const IPAddressQueue &remote_ips() { return remote_ips_; }
   void set_run_data_test(bool val) { run_data_test_ = val; }
diff --git a/device.cc b/device.cc
index 9151093..7bb92e3 100644
--- a/device.cc
+++ b/device.cc
@@ -670,8 +670,10 @@
 
 void Device::OnConnectionHealthCheckerResult(
     ConnectionHealthChecker::Result result) {
-  SLOG(Device, 2) << FriendlyName()
-      << ": ConnectionHealthChecker result: " << result;
+  SLOG(Device, 2)
+      << FriendlyName()
+      << ": ConnectionHealthChecker result: "
+      << ConnectionHealthChecker::ResultToString(result);
 }
 
 bool Device::RestartPortalDetection() {