shill: Create HTTPProxy for connected services

When an a Connection is created on a Device, ask the
Service to create an HTTPProxy.  The Service will
then expose the port number for the proxy as an RPC
property.  Whenever the Service is unselected by
the Device, or the connection terminates, ask the
Service to destroy the proxy.

The Service owns the HTTPProxy so that it can report
the proxy port in its properties.

BUG=chromium-os:21664
TEST=Add expectations for DestroyProxy in unit tests.
Manual: Ensure that "list-services" shows the proxy
port on a successful connection, and "curl -x" to
this proxy succeeds.

Change-Id: I24a1f7a23c0fc4577b48aed7bec370fba6edc342
Reviewed-on: https://gerrit.chromium.org/gerrit/12625
Reviewed-by: mukesh agrawal <quiche@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 8f032b4..5b9cc3c 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -199,15 +199,42 @@
   EXPECT_CALL(*service.get(), state())
     .WillOnce(Return(Service::kStateUnknown));
   EXPECT_CALL(*service.get(), SetState(Service::kStateIdle));
+  EXPECT_CALL(*service.get(), DestroyHTTPProxy());
   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());
   device_->SelectService(NULL);
 }
 
+TEST_F(DeviceTest, IPConfigUpdatedFailure) {
+  scoped_refptr<MockService> service(
+      new StrictMock<MockService>(control_interface(),
+                                  dispatcher(),
+                                  manager()));
+  device_->SelectService(service);
+  EXPECT_CALL(*service.get(), SetState(Service::kStateDisconnected));
+  EXPECT_CALL(*service.get(), DestroyHTTPProxy());
+  device_->IPConfigUpdatedCallback(NULL, false);
+}
+
+TEST_F(DeviceTest, IPConfigUpdatedSuccess) {
+  scoped_refptr<MockService> service(
+      new StrictMock<MockService>(control_interface(),
+                                  dispatcher(),
+                                  manager()));
+  device_->SelectService(service);
+  device_->manager_ = manager();
+  scoped_refptr<MockIPConfig> ipconfig = new MockIPConfig(control_interface(),
+                                                          kDeviceName);
+  EXPECT_CALL(*service.get(), SetState(Service::kStateConnected));
+  EXPECT_CALL(*service.get(), CreateHTTPProxy(_));
+  device_->IPConfigUpdatedCallback(ipconfig.get(), true);
+}
+
 TEST_F(DeviceTest, Stop) {
   device_->ipconfig_ = new IPConfig(&control_interface_, kDeviceName);
   scoped_refptr<MockService> service(