Add UpdateEngine.Attempt.ConnectionType metric.

This adds a new metric so we can track the how the device is connected
to the Internet when an attempt starts.

BUG=chromium:358339
TEST=New unit test + unit tests pass.

Change-Id: Ic5c2f50e2396e6baa288aca70906f7112ef7bca9
Reviewed-on: https://chromium-review.googlesource.com/192864
Reviewed-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
diff --git a/utils.cc b/utils.cc
index 0cde048..6d2abac 100644
--- a/utils.cc
+++ b/utils.cc
@@ -1125,6 +1125,41 @@
   return metrics::DownloadErrorCode::kInputMalformed;
 }
 
+metrics::ConnectionType GetConnectionType(
+    NetworkConnectionType type,
+    NetworkTethering tethering) {
+  switch (type) {
+    case kNetUnknown:
+      return metrics::ConnectionType::kUnknown;
+
+    case kNetEthernet:
+      if (tethering == NetworkTethering::kConfirmed)
+        return metrics::ConnectionType::kTetheredEthernet;
+      else
+        return metrics::ConnectionType::kEthernet;
+
+    case kNetWifi:
+      if (tethering == NetworkTethering::kConfirmed)
+        return metrics::ConnectionType::kTetheredWifi;
+      else
+        return metrics::ConnectionType::kWifi;
+
+    case kNetWimax:
+      return metrics::ConnectionType::kWimax;
+
+    case kNetBluetooth:
+      return metrics::ConnectionType::kBluetooth;
+
+    case kNetCellular:
+      return metrics::ConnectionType::kCellular;
+  }
+
+  LOG(ERROR) << "Unexpected network connection type: type=" << type
+             << ", tethering=" << static_cast<int>(tethering);
+
+  return metrics::ConnectionType::kUnknown;
+}
+
 // Returns a printable version of the various flags denoted in the higher order
 // bits of the given code. Returns an empty string if none of those bits are
 // set.