[net] Move DnsConfigService to NetworkChangeNotifier.

This merges DnsConfigWatcher back into DnsConfigService and installs
DnsConfigService at NetworkChangeNotifier. It removes |detail| from
OnDNSChanged callback, and exposes NetworkChangeNotifier::GetDnsConfig.

BUG=142142


Review URL: https://chromiumcodereview.appspot.com/10873018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154485 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index 10c50642..a23841f 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -7,23 +7,21 @@
 
 #include "base/basictypes.h"
 #include "base/observer_list_threadsafe.h"
-#include "base/synchronization/lock.h"
 #include "net/base/net_export.h"
 
 class GURL;
 
 namespace net {
 
+struct DnsConfig;
 class HistogramWatcher;
 class NetworkChangeNotifierFactory;
 
-namespace internal {
-class DnsConfigWatcher;
-
 #if defined(OS_LINUX)
+namespace internal {
 class AddressTrackerLinux;
-#endif
 }
+#endif
 
 // NetworkChangeNotifier monitors the system for network changes, and notifies
 // registered observers of those events.  Observers may register on any thread,
@@ -32,22 +30,6 @@
 // destroyed on the same thread.
 class NET_EXPORT NetworkChangeNotifier {
  public:
-  // Flags which are ORed together to form |detail| in OnDNSChanged.
-  //
-  // TODO(akalin): Name this enum type and use it instead of plain
-  // 'unsigned' in OnDNSChanged.  ORing together enum values always
-  // results in a valid enum value by the C++ standard.
-  enum {
-    // The DNS configuration (name servers, suffix search) has changed.
-    CHANGE_DNS_SETTINGS = 1 << 0,
-    // The HOSTS file has changed.
-    CHANGE_DNS_HOSTS = 1 << 1,
-    // The watcher has started.
-    CHANGE_DNS_WATCH_STARTED = 1 << 2,
-    // The watcher has failed and will not be available until further notice.
-    CHANGE_DNS_WATCH_FAILED = 1 << 3,
-  };
-
   // Using the terminology of the Network Information API:
   // http://www.w3.org/TR/netinfo-api.
   enum ConnectionType {
@@ -93,8 +75,8 @@
   class NET_EXPORT DNSObserver {
    public:
     // Will be called when the DNS settings of the system may have changed.
-    // The flags set in |detail| provide the specific set of changes.
-    virtual void OnDNSChanged(unsigned detail) = 0;
+    // Use GetDnsConfig to obtain the current settings.
+    virtual void OnDNSChanged() = 0;
 
    protected:
     DNSObserver() {}
@@ -108,7 +90,7 @@
 
   // See the description of NetworkChangeNotifier::GetConnectionType().
   // Implementations must be thread-safe. Implementations must also be
-  // cheap as this could be called (repeatedly) from the IO thread.
+  // cheap as this could be called (repeatedly) from the network thread.
   virtual ConnectionType GetCurrentConnectionType() const = 0;
 
   // Replaces the default class factory instance of NetworkChangeNotifier class.
@@ -131,6 +113,10 @@
   // attempt to a particular remote site will be successful.
   static ConnectionType GetConnectionType();
 
+  // Retrieve the last read DnsConfig. This could be expensive if the system has
+  // a large HOSTS file.
+  static void GetDnsConfig(DnsConfig* config);
+
 #if defined(OS_LINUX)
   // Returns the AddressTrackerLinux if present.
   static const internal::AddressTrackerLinux* GetAddressTracker();
@@ -148,9 +134,6 @@
     return GetConnectionType() == CONNECTION_NONE;
   }
 
-  // Returns true if DNS watcher is operational.
-  static bool IsWatchingDNS();
-
   // Like Create(), but for use in tests.  The mock object doesn't monitor any
   // events, it merely rebroadcasts notifications when requested.
   static NetworkChangeNotifier* CreateMock();
@@ -190,12 +173,11 @@
   static void InitHistogramWatcher();
 
  protected:
-  friend class internal::DnsConfigWatcher;
-
   NetworkChangeNotifier();
 
 #if defined(OS_LINUX)
   // Returns the AddressTrackerLinux if present.
+  // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212
   virtual const internal::AddressTrackerLinux*
       GetAddressTrackerInternal() const;
 #endif
@@ -205,12 +187,18 @@
   // tests.
   static void NotifyObserversOfIPAddressChange();
   static void NotifyObserversOfConnectionTypeChange();
-  static void NotifyObserversOfDNSChange(unsigned detail);
+  static void NotifyObserversOfDNSChange();
+
+  // Stores |config| in NetworkState and notifies observers.
+  static void SetDnsConfig(const DnsConfig& config);
 
  private:
+  friend class HostResolverImplDnsTest;
   friend class NetworkChangeNotifierLinuxTest;
   friend class NetworkChangeNotifierWinTest;
 
+  class NetworkState;
+
   // Allows a second NetworkChangeNotifier to be created for unit testing, so
   // the test suite can create a MockNetworkChangeNotifier, but platform
   // specific NetworkChangeNotifiers can also be created for testing.  To use,
@@ -235,12 +223,8 @@
   const scoped_refptr<ObserverListThreadSafe<DNSObserver> >
       resolver_state_observer_list_;
 
-  // True iff DNS watchers are operational.
-  // Otherwise, OnDNSChanged might not be issued for future changes.
-  // TODO(szym): This is a temporary interface, consider restarting them.
-  //             http://crbug.com/116139
-  base::Lock watching_dns_lock_;
-  bool watching_dns_;
+  // The current network state. Hosts DnsConfig, exposed via GetDnsConfig.
+  scoped_ptr<NetworkState> network_state_;
 
   // A little-piggy-back observer that simply logs UMA histogram data.
   scoped_ptr<HistogramWatcher> histogram_watcher_;