shill: Reporting of device's connection status

Report device's connection status to UMA stats periodically. Possible status
are offline (not connected to an AP), connected (connected to an AP), and
online (connected to an AP with internet connectivity). When the device is
in online state, it will report both connected and online to UMA stats.

This data will allow us to determine the percentage of time when the device
have internet connectivity, also the percentage of time when the device is
connected to an AP but without internet connectivity.

While at it, update the old IsOnline function in manager.cc to IsConnected
to be more semantically correct, since that function return true if there is a
service that's in connected or above state. And Add a new IsOnline function
which will return true only if there is a service that's in online state.

BUG=chromium:392990
TEST=unit tests, manual
Manual Test:
1. Boot up a chrome device without any network connectivity.
2. Wait for 3 minutes, and browse to "chrome://histograms", veriyf
   there is a histogram for "Network.Shill.DeviceConnectionStatus"
   with a hit for bucket 0 (offline).
3. Connect the chrome device to an AP without internet connectivity.
4. Wait for 3 minutes, and browse to "chrome://histograms", verify
   there is a hit for bucket 1 (connected) for histogram
   "Network.Shill.DeviceConnectionStatus".
5. Connect the chrome device to an AP with internet connectivity.
6. Wait for 3 minutes, and browse to "chrome://histograms", verify
   there sia hit for bucket 1 (connected) and 2 (online) for
   histogram "Network.Shill.DeviceConnectionStatus".

Change-Id: I1a949b17398214d745ca1d5a37e35202e087181a
Reviewed-on: https://chromium-review.googlesource.com/207960
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Peter Qiu <zqiu@chromium.org>
Tested-by: Peter Qiu <zqiu@chromium.org>
diff --git a/metrics.h b/metrics.h
index f1f85c0..0086fed 100644
--- a/metrics.h
+++ b/metrics.h
@@ -289,6 +289,14 @@
     kNetworkProblemMax
   };
 
+  // Device's connection status.
+  enum ConnectionStatus {
+    kConnectionStatusOffline = 0,
+    kConnectionStatusConnected = 1,
+    kConnectionStatusOnline = 2,
+    kConnectionStatusMax
+  };
+
   static const char kMetricDisconnectSuffix[];
   static const int kMetricDisconnectMax;
   static const int kMetricDisconnectMin;
@@ -490,6 +498,9 @@
   // Network problem detected by traffic monitor
   static const char kMetricNetworkProblemDetectedSuffix[];
 
+  // Device's connection status.
+  static const char kMetricDeviceConnectionStatus[];
+
   explicit Metrics(EventDispatcher *dispatcher);
   virtual ~Metrics();
 
@@ -682,6 +693,9 @@
   virtual void NotifyNetworkProblemDetected(
       Technology::Identifier technology_id, int reason);
 
+  // Notifies this object about current connection status (online vs offline).
+  virtual void NotifyDeviceConnectionStatus(Metrics::ConnectionStatus status);
+
   // Sends linear histogram data to UMA.
   virtual bool SendEnumToUMA(const std::string &name, int sample, int max);