shill: Create an IPAddress store in Manager for ConnectionHealthChecker

(1) Added class IPAddressStore
(2) Added an IPAddressStore object to Manager
(3) ConnectionHealthChecker uses this object so that the store persists
    across Device resets.

BUG=chromium:232883
TEST=(1)build and run unit-tests.
     (2)Check that DHCP renewal works -- connect the device to the same
        wifi network twice and verify wifi is connected.

Change-Id: Ia5ee314db46c3de2e037f59c1f99a248c80e4ef9
Reviewed-on: https://gerrit.chromium.org/gerrit/49487
Reviewed-by: Prathmesh Prabhu <pprabhu@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Commit-Queue: Prathmesh Prabhu <pprabhu@chromium.org>
diff --git a/connection_health_checker.h b/connection_health_checker.h
index 6bc870e..3efef07 100644
--- a/connection_health_checker.h
+++ b/connection_health_checker.h
@@ -27,6 +27,7 @@
 class Error;
 class EventDispatcher;
 class IPAddress;
+class IPAddressStore;
 class SocketInfoReader;
 
 // The ConnectionHealthChecker class implements the facilities to test
@@ -39,7 +40,6 @@
 //   -(3)- Connectivity OK (TCP connection established, is healthy)
 class ConnectionHealthChecker {
  public:
-  typedef std::vector<IPAddress> IPAddresses;
 
   enum Result {
     // There was some problem in the setup of ConnctionHealthChecker.
@@ -64,6 +64,7 @@
 
   ConnectionHealthChecker(ConnectionRefPtr connection,
                           EventDispatcher *dispatcher,
+                          IPAddressStore *remote_ips,
                           const base::Callback<void(Result)> &result_callback);
   virtual ~ConnectionHealthChecker();
 
@@ -75,6 +76,11 @@
   // to attempt the TCP connection with.
   virtual void AddRemoteIP(IPAddress ip);
 
+  // Change the associated Connection on the Device.
+  // This will restart any ongoing health check. Any ongoing DNS query will be
+  // dropped (not restarted).
+  virtual void SetConnection(ConnectionRefPtr connection);
+
   // Start a connection health check. The health check involves one or more
   // attempts at establishing and using a TCP connection. |result_callback_| is
   // called with the final result of the check. |result_callback_| will always
@@ -93,10 +99,9 @@
   static const char *ResultToString(Result result);
 
   // Accessors.
-  const IPAddresses &remote_ips() const { return remote_ips_; }
+  const IPAddressStore *remote_ips() const { return remote_ips_; }
   virtual bool health_check_in_progress() const;
 
-
  protected:
   // For unit-tests.
   void set_dispatcher(EventDispatcher *dispatcher) {
@@ -127,14 +132,20 @@
     old_transmit_queue_value_ = val;
   }
   Result health_check_result() const { return health_check_result_; }
+  AsyncConnection *tcp_connection() const { return tcp_connection_.get(); }
+  Connection *connection() const { return connection_.get(); }
+
  private:
   friend class ConnectionHealthCheckerTest;
   FRIEND_TEST(ConnectionHealthCheckerTest, GarbageCollectDNSClients);
   FRIEND_TEST(ConnectionHealthCheckerTest, GetSocketInfo);
   FRIEND_TEST(ConnectionHealthCheckerTest, NextHealthCheckSample);
   FRIEND_TEST(ConnectionHealthCheckerTest, OnConnectionComplete);
+  FRIEND_TEST(ConnectionHealthCheckerTest, SetConnection);
   FRIEND_TEST(ConnectionHealthCheckerTest, VerifySentData);
 
+  // List of static IPs for connection health check.
+  static const char *kDefaultRemoteIPPool[];
   // Time to wait for DNS server.
   static const int kDNSTimeoutMilliseconds;
   static const int kInvalidSocket;
@@ -152,12 +163,11 @@
   static const int kMinSuccessfulSendAttempts;
   // Number of DNS queries to be spawned when a new remote URL is added.
   static const int kNumDNSQueries;
+  static const uint16 kRemotePort;
   // Time to wait before testing successful data transfer / disconnect after
   // request is made on the device.
   static const int kTCPStateUpdateWaitMilliseconds;
 
-  static const uint16 kRemotePort;
-
   // Callback for DnsClient
   void GetDNSResult(const Error &error, const IPAddress &ip);
   void GarbageCollectDNSClients();
@@ -179,15 +189,13 @@
   // The connection on which the health check is being run.
   ConnectionRefPtr connection_;
   EventDispatcher *dispatcher_;
-
-  // The client function to call to report the result.
+  // Set of IPs to create TCP connection with for the health check.
+  IPAddressStore *remote_ips_;
   base::Callback<void(Result)> result_callback_;
 
   scoped_ptr<Sockets> socket_;
   base::WeakPtrFactory<ConnectionHealthChecker> weak_ptr_factory_;
 
-  // Set of IPs to create TCP connection with for the health check.
-  IPAddresses remote_ips_;
   // Callback passed to |tcp_connection_| to report an established TCP
   // connection.
   const base::Callback<void(bool, int)> connection_complete_callback_;