shill: Add new metrics for tracking device presence status per technology

The new metrics will track the presence or absence of a device of
each technology type.

BUG=chromium:411510
TEST=unit tests, manual test
Manual Test:
1. Log in to a peppy device, wait around 3 minutes.
2. Browse to "chrome://histograms", verify histogram
   "Network.Shill.Ethernet.DevicePresenceStatus" with a hit for
   bucket 1 (present), "Network.Shill.Wifi.DevicePresenceStatus"
   with a hit for bucket 1 (present),
   "Network.Shill.Cellular.DevicePresenceStatus" with a hit for
   bucket 0 (not present), and "Network.Shill.Wimax.DevicePresenceStatus"
   with a hit for bucket 0 (not present).

Change-Id: I1571bdbaf2abf7d2fc909389638105e4213dce5a
Reviewed-on: https://chromium-review.googlesource.com/217786
Reviewed-by: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
diff --git a/manager_unittest.cc b/manager_unittest.cc
index de49880..5c06d65 100644
--- a/manager_unittest.cc
+++ b/manager_unittest.cc
@@ -2470,7 +2470,7 @@
       .WillOnce(Return(false));
   EXPECT_CALL(mock_metrics,
       NotifyDeviceConnectionStatus(Metrics::kConnectionStatusOffline));
-  manager()->ConnectionStatusCheckTask();
+  manager()->ConnectionStatusCheck();
 
   // Device connected, but not online.
   EXPECT_CALL(*mock_service.get(), IsConnected())
@@ -2481,7 +2481,7 @@
       NotifyDeviceConnectionStatus(Metrics::kConnectionStatusOnline)).Times(0);
   EXPECT_CALL(mock_metrics,
       NotifyDeviceConnectionStatus(Metrics::kConnectionStatusConnected));
-  manager()->ConnectionStatusCheckTask();
+  manager()->ConnectionStatusCheck();
 
   // Device connected and online.
   EXPECT_CALL(*mock_service.get(), IsConnected())
@@ -2492,7 +2492,37 @@
       NotifyDeviceConnectionStatus(Metrics::kConnectionStatusOnline));
   EXPECT_CALL(mock_metrics,
       NotifyDeviceConnectionStatus(Metrics::kConnectionStatusConnected));
-  manager()->ConnectionStatusCheckTask();
+  manager()->ConnectionStatusCheck();
+}
+
+TEST_F(ManagerTest, DevicePresenceStatusCheck) {
+  // Setup mock metrics and service.
+  MockMetrics mock_metrics(dispatcher());
+  SetMetrics(&mock_metrics);
+
+  manager()->RegisterDevice(mock_devices_[0]);
+  manager()->RegisterDevice(mock_devices_[1]);
+  manager()->RegisterDevice(mock_devices_[2]);
+  manager()->RegisterDevice(mock_devices_[3]);
+
+  ON_CALL(*mock_devices_[0].get(), technology())
+      .WillByDefault(Return(Technology::kEthernet));
+  ON_CALL(*mock_devices_[1].get(), technology())
+      .WillByDefault(Return(Technology::kWifi));
+  ON_CALL(*mock_devices_[2].get(), technology())
+      .WillByDefault(Return(Technology::kCellular));
+  ON_CALL(*mock_devices_[3].get(), technology())
+      .WillByDefault(Return(Technology::kWifi));
+
+  EXPECT_CALL(mock_metrics,
+      NotifyDevicePresenceStatus(Technology::kEthernet, true));
+  EXPECT_CALL(mock_metrics,
+      NotifyDevicePresenceStatus(Technology::kWifi, true));
+  EXPECT_CALL(mock_metrics,
+      NotifyDevicePresenceStatus(Technology::kWiMax, false));
+  EXPECT_CALL(mock_metrics,
+      NotifyDevicePresenceStatus(Technology::kCellular, true));
+  manager()->DevicePresenceStatusCheck();
 }
 
 TEST_F(ManagerTest, SortServicesWithConnection) {