shill: service: Do active checks on PortalCheck and ProxyConfig

Change both properties to be derived strings.  Validate the various
values of the PortalCheck parameter.  Force a restart of portal
detection if either parameter changes, so that we can switch from
Portal to Online or vice vesa if by changing this parameter we are
changing the behavior of portal check.

BUG=chromium-os:29745
TEST=New unit tests.  Manual: Set Proxy configuration on a service
in portal state while on the login screen.

Change-Id: I86c386e61396a23103f99382c568372b4774f452
Reviewed-on: https://gerrit.chromium.org/gerrit/21027
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/device.cc b/device.cc
index 3ace719..a5c6ac8 100644
--- a/device.cc
+++ b/device.cc
@@ -236,6 +236,10 @@
   return false;
 }
 
+bool Device::IsConnectedToService(const ServiceRefPtr &service) const {
+  return service == selected_service_ && IsConnected();
+}
+
 string Device::GetRpcIdentifier() {
   return adaptor_->GetRpcIdentifier();
 }
@@ -450,6 +454,11 @@
   return true;
 }
 
+bool Device::RestartPortalDetection() {
+  StopPortalDetection();
+  return StartPortalDetection();
+}
+
 bool Device::RequestPortalDetection() {
   if (!selected_service_) {
     SLOG(Device, 2) << FriendlyName()
@@ -485,7 +494,17 @@
 }
 
 bool Device::StartPortalDetection() {
-  if (!manager_->IsPortalDetectionEnabled(technology())) {
+  DCHECK(selected_service_.get());
+  if (selected_service_->IsPortalDetectionDisabled()) {
+    SLOG(Device, 2) << "Service " << selected_service_->friendly_name()
+                    << ": Portal detection is disabled; "
+                    << "marking service online.";
+    SetServiceConnectedState(Service::kStateOnline);
+    return false;
+  }
+
+  if (selected_service_->IsPortalDetectionAuto() &&
+      !manager_->IsPortalDetectionEnabled(technology())) {
     // If portal detection is disabled for this technology, immediately set
     // the service state to "Online".
     SLOG(Device, 2) << "Device " << FriendlyName()
@@ -495,7 +514,6 @@
     return false;
   }
 
-  DCHECK(selected_service_.get());
   if (selected_service_->HasProxyConfig()) {
     // Services with HTTP proxy configurations should not be checked by the
     // connection manager, since we don't have the ability to evaluate