Rename Mdns interface into DnsServiceDiscoveryProvider

BUG: 24267885
Change-Id: I9e8d7da7c988ca5defa0a5f0d77a3e2b66895f7d
Reviewed-on: https://weave-review.googlesource.com/1156
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/libweave/examples/ubuntu/avahi_client.cc b/libweave/examples/ubuntu/avahi_client.cc
index 31e5741..58d11d0 100644
--- a/libweave/examples/ubuntu/avahi_client.cc
+++ b/libweave/examples/ubuntu/avahi_client.cc
@@ -23,7 +23,7 @@
 
 }  // namespace
 
-MdnsImpl::MdnsImpl() {
+AvahiClient::AvahiClient() {
   CHECK_EQ(0, std::system("service avahi-daemon status | grep running || "
                           "service avahi-daemon start"));
   thread_pool_.reset(avahi_threaded_poll_new());
@@ -41,14 +41,14 @@
                 << ". Check avahi-daemon configuration";
 }
 
-MdnsImpl::~MdnsImpl() {
+AvahiClient::~AvahiClient() {
   if (thread_pool_)
     avahi_threaded_poll_stop(thread_pool_.get());
 }
 
-void MdnsImpl::PublishService(const std::string& service_type,
-                              uint16_t port,
-                              const std::vector<std::string>& txt) {
+void AvahiClient::PublishService(const std::string& service_type,
+                                 uint16_t port,
+                                 const std::vector<std::string>& txt) {
   LOG(INFO) << "Publishing service";
   CHECK(group_);
 
@@ -86,12 +86,12 @@
   }
 }
 
-void MdnsImpl::StopPublishing(const std::string& service_name) {
+void AvahiClient::StopPublishing(const std::string& service_name) {
   CHECK(group_);
   avahi_entry_group_reset(group_.get());
 }
 
-std::string MdnsImpl::GetId() const {
+std::string AvahiClient::GetId() const {
   return "WEAVE" + std::to_string(gethostid());
 }
 
diff --git a/libweave/examples/ubuntu/avahi_client.h b/libweave/examples/ubuntu/avahi_client.h
index 90abd76..d3121a9 100644
--- a/libweave/examples/ubuntu/avahi_client.h
+++ b/libweave/examples/ubuntu/avahi_client.h
@@ -12,17 +12,17 @@
 #include <avahi-client/publish.h>
 #include <avahi-common/thread-watch.h>
 
-#include <weave/mdns.h>
+#include <weave/dns_service_discovery_provider.h>
 
 namespace weave {
 namespace examples {
 
-// Example of weave::Mdns implemented with avahi.
-class MdnsImpl : public Mdns {
+// Example of weave::DnsServiceDiscoveryProvider implemented with avahi.
+class AvahiClient : public DnsServiceDiscoveryProvider {
  public:
-  MdnsImpl();
+  AvahiClient();
 
-  ~MdnsImpl() override;
+  ~AvahiClient() override;
   void PublishService(const std::string& service_type,
                       uint16_t port,
                       const std::vector<std::string>& txt) override;
@@ -35,7 +35,7 @@
   std::unique_ptr<AvahiThreadedPoll, decltype(&avahi_threaded_poll_free)>
       thread_pool_{nullptr, &avahi_threaded_poll_free};
 
-  std::unique_ptr<AvahiClient, decltype(&avahi_client_free)> client_{
+  std::unique_ptr<::AvahiClient, decltype(&avahi_client_free)> client_{
       nullptr, &avahi_client_free};
 
   std::unique_ptr<AvahiEntryGroup, decltype(&avahi_entry_group_free)> group_{
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc
index ff936d7..4e7f07c 100644
--- a/libweave/examples/ubuntu/main.cc
+++ b/libweave/examples/ubuntu/main.cc
@@ -88,7 +88,7 @@
   weave::examples::EventTaskRunner task_runner;
   weave::examples::CurlHttpClient http_client{&task_runner};
   weave::examples::NetworkImpl network{&task_runner, force_bootstrapping};
-  weave::examples::MdnsImpl mdns;
+  weave::examples::AvahiClient dns_sd;
   weave::examples::HttpServerImpl http_server{&task_runner};
   weave::examples::BluetoothImpl bluetooth;
 
@@ -99,7 +99,7 @@
   opts.disable_security = disable_security;
   opts.enable_ping = true;
   device->Start(
-      opts, &config_store, &task_runner, &http_client, &network, &mdns,
+      opts, &config_store, &task_runner, &http_client, &network, &dns_sd,
       &http_server,
       weave::examples::NetworkImpl::HasWifiCapability() ? &network : nullptr,
       &bluetooth);
diff --git a/libweave/include/weave/device.h b/libweave/include/weave/device.h
index bf49609..c6b70ea 100644
--- a/libweave/include/weave/device.h
+++ b/libweave/include/weave/device.h
@@ -13,10 +13,10 @@
 #include <weave/cloud.h>
 #include <weave/commands.h>
 #include <weave/config_store.h>
+#include <weave/dns_service_discovery_provider.h>
 #include <weave/export.h>
 #include <weave/http_client.h>
 #include <weave/http_server.h>
-#include <weave/mdns.h>
 #include <weave/network_provider.h>
 #include <weave/privet.h>
 #include <weave/state.h>
@@ -42,7 +42,7 @@
                      TaskRunner* task_runner,
                      HttpClient* http_client,
                      NetworkProvider* network,
-                     Mdns* mdns,
+                     DnsServiceDiscoveryProvider* dns_sd,
                      HttpServer* http_server,
                      WifiProvider* wifi,
                      Bluetooth* bluetooth) = 0;
diff --git a/libweave/include/weave/mdns.h b/libweave/include/weave/dns_service_discovery_provider.h
similarity index 67%
rename from libweave/include/weave/mdns.h
rename to libweave/include/weave/dns_service_discovery_provider.h
index b149277..bdba69d 100644
--- a/libweave/include/weave/mdns.h
+++ b/libweave/include/weave/dns_service_discovery_provider.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef LIBWEAVE_INCLUDE_WEAVE_MDNS_H_
-#define LIBWEAVE_INCLUDE_WEAVE_MDNS_H_
+#ifndef LIBWEAVE_INCLUDE_WEAVE_DNS_SERVICE_DISCOVERY_PROVIDER_H_
+#define LIBWEAVE_INCLUDE_WEAVE_DNS_SERVICE_DISCOVERY_PROVIDER_H_
 
 #include <string>
 #include <vector>
@@ -12,9 +12,9 @@
 
 namespace weave {
 
-class Mdns {
+class DnsServiceDiscoveryProvider {
  public:
-  // Publishes new service on mDns or updates existing one.
+  // Publishes new service using DNS-SD or updates existing one.
   virtual void PublishService(const std::string& service_type,
                               uint16_t port,
                               const std::vector<std::string>& txt) = 0;
@@ -27,9 +27,9 @@
   virtual std::string GetId() const = 0;
 
  protected:
-  virtual ~Mdns() = default;
+  virtual ~DnsServiceDiscoveryProvider() = default;
 };
 
 }  // namespace weave
 
-#endif  // LIBWEAVE_INCLUDE_WEAVE_MDNS_H_
+#endif  // LIBWEAVE_INCLUDE_WEAVE_DNS_SERVICE_DISCOVERY_PROVIDER_H_
diff --git a/libweave/include/weave/test/mock_mdns.h b/libweave/include/weave/test/mock_dns_service_discovery_provider.h
similarity index 62%
rename from libweave/include/weave/test/mock_mdns.h
rename to libweave/include/weave/test/mock_dns_service_discovery_provider.h
index 40beeac..6d187f8 100644
--- a/libweave/include/weave/test/mock_mdns.h
+++ b/libweave/include/weave/test/mock_dns_service_discovery_provider.h
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_
-#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_
+#ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_DNS_SERVICE_DISCOVERY_PROVIDER_H_
+#define LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_DNS_SERVICE_DISCOVERY_PROVIDER_H_
 
-#include <weave/mdns.h>
+#include <weave/dns_service_discovery_provider.h>
 
 #include <string>
 #include <vector>
@@ -15,7 +15,7 @@
 namespace weave {
 namespace test {
 
-class MockMdns : public Mdns {
+class MockDnsServiceDiscovery : public DnsServiceDiscoveryProvider {
  public:
   MOCK_METHOD3(PublishService,
                void(const std::string&,
@@ -28,4 +28,4 @@
 }  // namespace test
 }  // namespace weave
 
-#endif  // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_MDNS_H_
+#endif  // LIBWEAVE_INCLUDE_WEAVE_TEST_MOCK_DNS_SERVICE_DISCOVERY_PROVIDER_H_
diff --git a/libweave/src/device_manager.cc b/libweave/src/device_manager.cc
index 50bfcbe..4e8479e 100644
--- a/libweave/src/device_manager.cc
+++ b/libweave/src/device_manager.cc
@@ -34,7 +34,7 @@
                           TaskRunner* task_runner,
                           HttpClient* http_client,
                           NetworkProvider* network,
-                          Mdns* mdns,
+                          DnsServiceDiscoveryProvider* dns_sd,
                           HttpServer* http_server,
                           WifiProvider* wifi,
                           Bluetooth* bluetooth) {
@@ -58,11 +58,11 @@
   device_info_->Start();
 
   if (!options.disable_privet) {
-    StartPrivet(options, task_runner, network, mdns, http_server, wifi,
+    StartPrivet(options, task_runner, network, dns_sd, http_server, wifi,
                 bluetooth);
   } else {
     CHECK(!http_server);
-    CHECK(!mdns);
+    CHECK(!dns_sd);
   }
 }
 
@@ -89,12 +89,12 @@
 void DeviceManager::StartPrivet(const Options& options,
                                 TaskRunner* task_runner,
                                 NetworkProvider* network,
-                                Mdns* mdns,
+                                DnsServiceDiscoveryProvider* dns_sd,
                                 HttpServer* http_server,
                                 WifiProvider* wifi,
                                 Bluetooth* bluetooth) {
   privet_.reset(new privet::Manager{});
-  privet_->Start(options, task_runner, network, mdns, http_server, wifi,
+  privet_->Start(options, task_runner, network, dns_sd, http_server, wifi,
                  device_info_.get(), command_manager_.get(),
                  state_manager_.get());
 
diff --git a/libweave/src/device_manager.h b/libweave/src/device_manager.h
index 00f2b5c..3441dde 100644
--- a/libweave/src/device_manager.h
+++ b/libweave/src/device_manager.h
@@ -31,7 +31,7 @@
              TaskRunner* task_runner,
              HttpClient* http_client,
              NetworkProvider* network,
-             Mdns* mdns,
+             DnsServiceDiscoveryProvider* dns_sd,
              HttpServer* http_server,
              WifiProvider* wifi,
              Bluetooth* bluetooth) override;
@@ -47,7 +47,7 @@
   void StartPrivet(const Options& options,
                    TaskRunner* task_runner,
                    NetworkProvider* network,
-                   Mdns* mdns,
+                   DnsServiceDiscoveryProvider* dns_sd,
                    HttpServer* http_server,
                    WifiProvider* wifi,
                    Bluetooth* bluetooth);
diff --git a/libweave/src/privet/cloud_delegate.h b/libweave/src/privet/cloud_delegate.h
index eb87e67..f96da19 100644
--- a/libweave/src/privet/cloud_delegate.h
+++ b/libweave/src/privet/cloud_delegate.h
@@ -74,7 +74,7 @@
   virtual std::string GetModelName() const = 0;
 
   // Returns the list of services supported by device.
-  // E.g. printer, scanner etc. Should match services published on mDNS.
+  // E.g. printer, scanner etc. Should match services published on DNS-SD.
   virtual std::set<std::string> GetServices() const = 0;
 
   // Returns max scope available for anonymous user.
diff --git a/libweave/src/privet/privet_manager.cc b/libweave/src/privet/privet_manager.cc
index cbf3bd3..cf25773 100644
--- a/libweave/src/privet/privet_manager.cc
+++ b/libweave/src/privet/privet_manager.cc
@@ -36,7 +36,7 @@
 void Manager::Start(const Device::Options& options,
                     TaskRunner* task_runner,
                     NetworkProvider* network,
-                    Mdns* mdns,
+                    DnsServiceDiscoveryProvider* dns_sd,
                     HttpServer* http_server,
                     WifiProvider* wifi,
                     DeviceRegistrationInfo* device,
@@ -64,7 +64,7 @@
   }
 
   publisher_.reset(new Publisher(device_.get(), cloud_.get(),
-                                 wifi_bootstrap_manager_.get(), mdns));
+                                 wifi_bootstrap_manager_.get(), dns_sd));
 
   privet_handler_.reset(
       new PrivetHandler(cloud_.get(), device_.get(), security_.get(),
diff --git a/libweave/src/privet/privet_manager.h b/libweave/src/privet/privet_manager.h
index 107a280..7fc90a2 100644
--- a/libweave/src/privet/privet_manager.h
+++ b/libweave/src/privet/privet_manager.h
@@ -29,7 +29,7 @@
 
 class CommandManager;
 class DeviceRegistrationInfo;
-class Mdns;
+class DnsServiceDiscoveryProvider;
 class NetworkProvider;
 class StateManager;
 
@@ -50,7 +50,7 @@
   void Start(const weave::Device::Options& options,
              TaskRunner* task_runner,
              NetworkProvider* network,
-             Mdns* mdns,
+             DnsServiceDiscoveryProvider* dns_sd,
              HttpServer* http_server,
              WifiProvider* wifi,
              DeviceRegistrationInfo* device,
diff --git a/libweave/src/privet/publisher.cc b/libweave/src/privet/publisher.cc
index a2595f5..6a5b8bb 100644
--- a/libweave/src/privet/publisher.cc
+++ b/libweave/src/privet/publisher.cc
@@ -6,8 +6,8 @@
 
 #include <map>
 
+#include <weave/dns_service_discovery_provider.h>
 #include <weave/error.h>
-#include <weave/mdns.h>
 
 #include "libweave/src/privet/cloud_delegate.h"
 #include "libweave/src/privet/device_delegate.h"
@@ -20,7 +20,7 @@
 
 namespace {
 
-// The service type we'll expose via mdns.
+// The service type we'll expose via DNS-SD.
 const char kPrivetServiceType[] = "_privet._tcp";
 
 }  // namespace
@@ -28,11 +28,11 @@
 Publisher::Publisher(const DeviceDelegate* device,
                      const CloudDelegate* cloud,
                      const WifiDelegate* wifi,
-                     Mdns* mdns)
-    : mdns_{mdns}, device_{device}, cloud_{cloud}, wifi_{wifi} {
+                     DnsServiceDiscoveryProvider* dns_sd)
+    : dns_sd_{dns_sd}, device_{device}, cloud_{cloud}, wifi_{wifi} {
   CHECK(device_);
   CHECK(cloud_);
-  CHECK(mdns_);
+  CHECK(dns_sd_);
 }
 
 Publisher::~Publisher() {
@@ -40,7 +40,7 @@
 }
 
 std::string Publisher::GetId() const {
-  return mdns_->GetId();
+  return dns_sd_->GetId();
 }
 
 void Publisher::Update() {
@@ -79,7 +79,7 @@
     txt_record.emplace_back("note=" + cloud_->GetDescription());
 
   is_publishing_ = true;
-  mdns_->PublishService(kPrivetServiceType, port, txt_record);
+  dns_sd_->PublishService(kPrivetServiceType, port, txt_record);
 }
 
 void Publisher::RemoveService() {
@@ -87,7 +87,7 @@
     return;
   is_publishing_ = false;
   VLOG(1) << "Stopping service publishing.";
-  mdns_->StopPublishing(kPrivetServiceType);
+  dns_sd_->StopPublishing(kPrivetServiceType);
 }
 
 }  // namespace privet
diff --git a/libweave/src/privet/publisher.h b/libweave/src/privet/publisher.h
index 71d38a8..b73ea2e 100644
--- a/libweave/src/privet/publisher.h
+++ b/libweave/src/privet/publisher.h
@@ -14,7 +14,7 @@
 
 namespace weave {
 
-class Mdns;
+class DnsServiceDiscoveryProvider;
 
 namespace privet {
 
@@ -22,13 +22,13 @@
 class DeviceDelegate;
 class WifiDelegate;
 
-// Publishes privet service on mDns.
+// Publishes privet service on DNS-SD.
 class Publisher : public IdentityDelegate {
  public:
   Publisher(const DeviceDelegate* device,
             const CloudDelegate* cloud,
             const WifiDelegate* wifi,
-            Mdns* mdns);
+            DnsServiceDiscoveryProvider* dns_sd);
   ~Publisher() override;
 
   // IdentityDelegate implementation.
@@ -42,7 +42,7 @@
   void RemoveService();
 
   bool is_publishing_{false};
-  Mdns* mdns_{nullptr};
+  DnsServiceDiscoveryProvider* dns_sd_{nullptr};
 
   const DeviceDelegate* device_{nullptr};
   const CloudDelegate* cloud_{nullptr};
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc
index 9bd7559..f5d7818 100644
--- a/libweave/src/weave_unittest.cc
+++ b/libweave/src/weave_unittest.cc
@@ -8,9 +8,9 @@
 #include <gtest/gtest.h>
 #include <weave/test/mock_bluetooth.h>
 #include <weave/test/mock_config_store.h>
+#include <weave/test/mock_dns_service_discovery_provider.h>
 #include <weave/test/mock_http_client.h>
 #include <weave/test/mock_http_server.h>
-#include <weave/test/mock_mdns.h>
 #include <weave/test/mock_network_provider.h>
 #include <weave/test/mock_task_runner.h>
 #include <weave/test/mock_wifi_provider.h>
@@ -231,18 +231,13 @@
         .WillRepeatedly(Return(NetworkState::kOffline));
   }
 
-  void IgnoreMdns() {
-    EXPECT_CALL(mdns_, GetId()).WillRepeatedly(Return("TEST_ID"));
-    EXPECT_CALL(mdns_, PublishService(_, _, _)).WillRepeatedly(Return());
-    EXPECT_CALL(mdns_, StopPublishing("_privet._tcp")).WillOnce(Return());
+  void InitDnsSd() {
+    EXPECT_CALL(dns_sd_, GetId()).WillRepeatedly(Return("TEST_ID"));
+    EXPECT_CALL(dns_sd_, PublishService(_, _, _)).WillRepeatedly(Return());
+    EXPECT_CALL(dns_sd_, StopPublishing("_privet._tcp")).WillOnce(Return());
   }
 
-  void InitMdns() {
-    EXPECT_CALL(mdns_, GetId()).WillRepeatedly(Return("TEST_ID"));
-    EXPECT_CALL(mdns_, StopPublishing("_privet._tcp")).WillOnce(Return());
-  }
-
-  void InitMdnsPublishing(bool registered, const std::string& flags) {
+  void InitDnsSdPublishing(bool registered, const std::string& flags) {
     std::vector<std::string> txt{{"id=TEST_ID"}, {"flags=" + flags},
                                  {"mmid=ABCDE"}, {"services=_base"},
                                  {"txtvers=3"},  {"ty=DEVICE_NAME"}};
@@ -252,14 +247,14 @@
       // During registration device may announce itself twice:
       // 1. with GCD ID but not connected (DB)
       // 2. with GCD ID and connected (BB)
-      EXPECT_CALL(mdns_, PublishService("_privet._tcp", 11, MatchTxt(txt)))
+      EXPECT_CALL(dns_sd_, PublishService("_privet._tcp", 11, MatchTxt(txt)))
           .Times(AtMost(1))
           .WillOnce(Return());
 
       txt[1] = "flags=BB";
     }
 
-    EXPECT_CALL(mdns_, PublishService("_privet._tcp", 11, MatchTxt(txt)))
+    EXPECT_CALL(dns_sd_, PublishService("_privet._tcp", 11, MatchTxt(txt)))
         .WillOnce(Return());
   }
 
@@ -286,7 +281,7 @@
     EXPECT_CALL(wifi_, StartAccessPoint(MatchesRegex("DEVICE_NAME.*prv")))
         .WillOnce(Return());
     InitHttpServer();
-    InitMdns();
+    InitDnsSd();
   }
 
   void StartDevice() {
@@ -294,7 +289,7 @@
     options.xmpp_enabled = false;
 
     device_->Start(options, &config_store_, &task_runner_, &http_client_,
-                   &network_, &mdns_, &http_server_, &wifi_, &bluetooth_);
+                   &network_, &dns_sd_, &http_server_, &wifi_, &bluetooth_);
 
     cloud_ = device_->GetCloud();
     ASSERT_TRUE(cloud_);
@@ -326,7 +321,7 @@
   StrictMock<test::MockTaskRunner> task_runner_;
   StrictMock<test::MockHttpClient> http_client_;
   StrictMock<test::MockNetworkProvider> network_;
-  StrictMock<test::MockMdns> mdns_;
+  StrictMock<test::MockDnsServiceDiscovery> dns_sd_;
   StrictMock<test::MockHttpServer> http_server_;
   StrictMock<test::MockWifiProvider> wifi_;
   StrictMock<test::MockBluetooth> bluetooth_;
@@ -357,12 +352,12 @@
   InitConfigStore();
   InitNetwork();
   InitHttpServer();
-  InitMdns();
-  InitMdnsPublishing(false, "CB");
+  InitDnsSd();
+  InitDnsSdPublishing(false, "CB");
 
   weave::Device::Options options;
   device_->Start(options, &config_store_, &task_runner_, &http_client_,
-                 &network_, &mdns_, &http_server_, nullptr, &bluetooth_);
+                 &network_, &dns_sd_, &http_server_, nullptr, &bluetooth_);
 
   for (const auto& cb : http_server_changed_cb_)
     cb.Run(http_server_);
@@ -376,7 +371,7 @@
     WeaveTest::SetUp();
 
     InitDefaultExpectations();
-    InitMdnsPublishing(false, "DB");
+    InitDnsSdPublishing(false, "DB");
   }
 };
 
@@ -407,7 +402,7 @@
   ExpectRequest("POST", "https://accounts.google.com/o/oauth2/token",
                 kAuthTokenResponse);
 
-  InitMdnsPublishing(true, "DB");
+  InitDnsSdPublishing(true, "DB");
 
   EXPECT_EQ("DEVICE_ID", cloud_->RegisterDevice("TEST_ID", nullptr));
 }
@@ -420,7 +415,7 @@
     InitConfigStore();
     InitHttpServer();
     InitNetwork();
-    IgnoreMdns();
+    InitDnsSd();
 
     EXPECT_CALL(network_, GetConnectionState())
         .WillRepeatedly(Return(NetworkState::kConnected));