shill: Assign "Default" status to the best connection

Set the highest-ranked connection to be the "Default".
As a result, the highest priority default route will
move with the highest-ranked connection in the service
list.

Bonus changes:
 * Service now formally holds a reference to the Connection
   object, so call a "SetConnection" method instead of a
   Create/Destroy of the HTTPProxy.
 * Actually start the routing table service, and do a couple
   minor fixes due to how the kernel actually accepts metric
   changes.

BUG=chromium-os:7607,chromium-os:23993
TEST=New Unit Test + Manual (watch routes while inserting
USB-Ethernet on a machine connected to WiFi)

Change-Id: Iddf1ed766238d9e8adc97bb54fc12b527f86239f
Reviewed-on: https://gerrit.chromium.org/gerrit/12685
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/device_unittest.cc b/device_unittest.cc
index 5b9cc3c..0a10427 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -180,6 +180,14 @@
   EXPECT_EQ(string::npos, to_process.find('/'));
 }
 
+MATCHER(IsNullRefPtr, "") {
+  return !arg;
+}
+
+MATCHER(NotNullRefPtr, "") {
+  return arg;
+}
+
 TEST_F(DeviceTest, SelectedService) {
   EXPECT_FALSE(device_->selected_service_.get());
   device_->SetServiceState(Service::kStateAssociating);
@@ -199,14 +207,14 @@
   EXPECT_CALL(*service.get(), state())
     .WillOnce(Return(Service::kStateUnknown));
   EXPECT_CALL(*service.get(), SetState(Service::kStateIdle));
-  EXPECT_CALL(*service.get(), DestroyHTTPProxy());
+  EXPECT_CALL(*service.get(), SetConnection(IsNullRefPtr()));
   device_->SelectService(NULL);
 
   // A service in the "Failure" state should not be reset to "Idle"
   device_->SelectService(service);
   EXPECT_CALL(*service.get(), state())
     .WillOnce(Return(Service::kStateFailure));
-  EXPECT_CALL(*service.get(), DestroyHTTPProxy());
+  EXPECT_CALL(*service.get(), SetConnection(IsNullRefPtr()));
   device_->SelectService(NULL);
 }
 
@@ -217,7 +225,7 @@
                                   manager()));
   device_->SelectService(service);
   EXPECT_CALL(*service.get(), SetState(Service::kStateDisconnected));
-  EXPECT_CALL(*service.get(), DestroyHTTPProxy());
+  EXPECT_CALL(*service.get(), SetConnection(IsNullRefPtr()));
   device_->IPConfigUpdatedCallback(NULL, false);
 }
 
@@ -231,7 +239,7 @@
   scoped_refptr<MockIPConfig> ipconfig = new MockIPConfig(control_interface(),
                                                           kDeviceName);
   EXPECT_CALL(*service.get(), SetState(Service::kStateConnected));
-  EXPECT_CALL(*service.get(), CreateHTTPProxy(_));
+  EXPECT_CALL(*service.get(), SetConnection(NotNullRefPtr()));
   device_->IPConfigUpdatedCallback(ipconfig.get(), true);
 }