Replace services list with value generated from model device id

Now it's the list with single value equal to UI kind generated from
model id.

BUG:25085528
Change-Id: I3a29915b4c68726a956079435dfe030d553d5c11
Reviewed-on: https://weave-review.googlesource.com/1424
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/libweave/libweave.gypi b/libweave/libweave.gypi
index d481996..f65eda7 100644
--- a/libweave/libweave.gypi
+++ b/libweave/libweave.gypi
@@ -35,6 +35,7 @@
       'src/privet/cloud_delegate.cc',
       'src/privet/constants.cc',
       'src/privet/device_delegate.cc',
+      'src/privet/device_ui_kind.cc',
       'src/privet/openssl_utils.cc',
       'src/privet/privet_handler.cc',
       'src/privet/privet_manager.cc',
diff --git a/libweave/src/privet/cloud_delegate.cc b/libweave/src/privet/cloud_delegate.cc
index b4ab288..4c28141 100644
--- a/libweave/src/privet/cloud_delegate.cc
+++ b/libweave/src/privet/cloud_delegate.cc
@@ -99,15 +99,6 @@
     return device_->GetSettings().model_name;
   }
 
-  std::set<std::string> GetServices() const override {
-    std::set<std::string> result;
-    for (base::DictionaryValue::Iterator it{command_defs_}; !it.IsAtEnd();
-         it.Advance()) {
-      result.emplace(it.key());
-    }
-    return result;
-  }
-
   AuthScope GetAnonymousMaxScope() const override {
     return device_->GetSettings().local_anonymous_access_role;
   }
diff --git a/libweave/src/privet/cloud_delegate.h b/libweave/src/privet/cloud_delegate.h
index 3875580..8763fbe 100644
--- a/libweave/src/privet/cloud_delegate.h
+++ b/libweave/src/privet/cloud_delegate.h
@@ -78,10 +78,6 @@
   // Returns the model name of the device.
   virtual std::string GetModelName() const = 0;
 
-  // Returns the list of services supported by device.
-  // 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.
   virtual AuthScope GetAnonymousMaxScope() const = 0;
 
diff --git a/libweave/src/privet/device_ui_kind.cc b/libweave/src/privet/device_ui_kind.cc
new file mode 100644
index 0000000..08b9312
--- /dev/null
+++ b/libweave/src/privet/device_ui_kind.cc
@@ -0,0 +1,42 @@
+// Copyright 2015 The Weave Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/privet/device_ui_kind.h"
+
+#include <base/logging.h>
+
+namespace weave {
+namespace privet {
+
+std::string GetDeviceUiKind(const std::string& manifest_id) {
+  CHECK_EQ(5u, manifest_id.size());
+  std::string kind = manifest_id.substr(0, 2);
+  if (kind == "AC")
+    return "accessPoint";
+  if (kind == "AK")
+    return "aggregator";
+  if (kind == "AM")
+    return "camera";
+  if (kind == "AB")
+    return "developmentBoard";
+  if (kind == "AE")
+    return "printer";
+  if (kind == "AF")
+    return "scanner";
+  if (kind == "AD")
+    return "speaker";
+  if (kind == "AL")
+    return "storage";
+  if (kind == "AJ")
+    return "toy";
+  if (kind == "AA")
+    return "vendor";
+  if (kind == "AN")
+    return "video";
+  LOG(FATAL) << "Invalid model id: " << manifest_id;
+  return std::string();
+}
+
+}  // namespace privet
+}  // namespace weave
diff --git a/libweave/src/privet/device_ui_kind.h b/libweave/src/privet/device_ui_kind.h
new file mode 100644
index 0000000..cd05f0e
--- /dev/null
+++ b/libweave/src/privet/device_ui_kind.h
@@ -0,0 +1,18 @@
+// Copyright 2015 The Weave Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef LIBWEAVE_SRC_PRIVET_DEVICE_UI_KIND_H_
+#define LIBWEAVE_SRC_PRIVET_DEVICE_UI_KIND_H_
+
+#include <string>
+
+namespace weave {
+namespace privet {
+
+std::string GetDeviceUiKind(const std::string& manifest_id);
+
+}  // namespace privet
+}  // namespace weave
+
+#endif  // LIBWEAVE_SRC_PRIVET_DEVICE_UI_KIND_H_
diff --git a/libweave/src/privet/mock_delegates.h b/libweave/src/privet/mock_delegates.h
index 159fa09..755110e 100644
--- a/libweave/src/privet/mock_delegates.h
+++ b/libweave/src/privet/mock_delegates.h
@@ -146,7 +146,6 @@
                     const std::string&));
   MOCK_CONST_METHOD0(GetOemName, std::string());
   MOCK_CONST_METHOD0(GetModelName, std::string());
-  MOCK_CONST_METHOD0(GetServices, std::set<std::string>());
   MOCK_CONST_METHOD0(GetAnonymousMaxScope, AuthScope());
   MOCK_CONST_METHOD0(GetConnectionState, const ConnectionState&());
   MOCK_CONST_METHOD0(GetSetupState, const SetupState&());
@@ -177,8 +176,6 @@
     EXPECT_CALL(*this, UpdateDeviceInfo(_, _, _)).WillRepeatedly(Return());
     EXPECT_CALL(*this, GetOemName()).WillRepeatedly(Return("Chromium"));
     EXPECT_CALL(*this, GetModelName()).WillRepeatedly(Return("Brillo"));
-    EXPECT_CALL(*this, GetServices())
-        .WillRepeatedly(Return(std::set<std::string>{}));
     EXPECT_CALL(*this, GetAnonymousMaxScope())
         .WillRepeatedly(Return(AuthScope::kUser));
     EXPECT_CALL(*this, GetConnectionState())
diff --git a/libweave/src/privet/privet_handler.cc b/libweave/src/privet/privet_handler.cc
index fc344ab..d959f66 100644
--- a/libweave/src/privet/privet_handler.cc
+++ b/libweave/src/privet/privet_handler.cc
@@ -20,6 +20,7 @@
 #include "src/privet/cloud_delegate.h"
 #include "src/privet/constants.h"
 #include "src/privet/device_delegate.h"
+#include "src/privet/device_ui_kind.h"
 #include "src/privet/security_delegate.h"
 #include "src/privet/wifi_delegate.h"
 #include "src/string_utils.h"
@@ -216,40 +217,11 @@
   return ReturnError(*error, callback);
 }
 
-std::string GetDeviceKind(const std::string& manifest_id) {
-  CHECK_EQ(5u, manifest_id.size());
-  std::string kind = manifest_id.substr(0, 2);
-  if (kind == "AC")
-    return "accessPoint";
-  if (kind == "AK")
-    return "aggregator";
-  if (kind == "AM")
-    return "camera";
-  if (kind == "AB")
-    return "developmentBoard";
-  if (kind == "AE")
-    return "printer";
-  if (kind == "AF")
-    return "scanner";
-  if (kind == "AD")
-    return "speaker";
-  if (kind == "AL")
-    return "storage";
-  if (kind == "AJ")
-    return "toy";
-  if (kind == "AA")
-    return "vendor";
-  if (kind == "AN")
-    return "video";
-  LOG(FATAL) << "Invalid model id: " << manifest_id;
-  return std::string();
-}
-
 std::unique_ptr<base::DictionaryValue> CreateManifestSection(
-    const std::string& model_id,
     const CloudDelegate& cloud) {
   std::unique_ptr<base::DictionaryValue> manifest(new base::DictionaryValue());
-  manifest->SetString(kInfoManifestUiDeviceKind, GetDeviceKind(model_id));
+  manifest->SetString(kInfoManifestUiDeviceKind,
+                      GetDeviceUiKind(cloud.GetModelId()));
   manifest->SetString(kInfoManifestOemName, cloud.GetOemName());
   manifest->SetString(kInfoManifestModelName, cloud.GetModelName());
   return manifest;
@@ -487,9 +459,11 @@
     output.SetString(kLocationKey, location);
 
   output.SetString(kInfoModelIdKey, model_id);
-  output.Set(kInfoModelManifestKey,
-             CreateManifestSection(model_id, *cloud_).release());
-  output.Set(kInfoServicesKey, ToValue(cloud_->GetServices()).release());
+  output.Set(kInfoModelManifestKey, CreateManifestSection(*cloud_).release());
+  output.Set(
+      kInfoServicesKey,
+      ToValue(std::vector<std::string>{GetDeviceUiKind(cloud_->GetModelId())})
+          .release());
 
   output.Set(
       kInfoAuthenticationKey,
diff --git a/libweave/src/privet/privet_handler_unittest.cc b/libweave/src/privet/privet_handler_unittest.cc
index 6f123e2..d430935 100644
--- a/libweave/src/privet/privet_handler_unittest.cc
+++ b/libweave/src/privet/privet_handler_unittest.cc
@@ -238,7 +238,7 @@
     'version': '3.0',
     'id': 'TestId',
     'name': 'TestDevice',
-    'services': [],
+    'services': [ "developmentBoard" ],
     'modelManifestId': "ABMID",
     'basicModelManifest': {
       'uiDeviceKind': 'developmentBoard',
@@ -275,8 +275,6 @@
   EXPECT_CALL(cloud_, GetDescription())
       .WillRepeatedly(Return("TestDescription"));
   EXPECT_CALL(cloud_, GetLocation()).WillRepeatedly(Return("TestLocation"));
-  EXPECT_CALL(cloud_, GetServices())
-      .WillRepeatedly(Return(std::set<std::string>{"service1", "service2"}));
   EXPECT_CALL(device_, GetHttpEnpoint())
       .WillRepeatedly(Return(std::make_pair(80, 10080)));
   EXPECT_CALL(device_, GetHttpsEnpoint())
@@ -290,10 +288,7 @@
     'name': 'TestDevice',
     'description': 'TestDescription',
     'location': 'TestLocation',
-    'services': [
-      "service1",
-      "service2"
-    ],
+    'services': [ "developmentBoard" ],
     'modelManifestId': "ABMID",
     'basicModelManifest': {
       'uiDeviceKind': 'developmentBoard',
diff --git a/libweave/src/privet/publisher.cc b/libweave/src/privet/publisher.cc
index f323dac..62e980e 100644
--- a/libweave/src/privet/publisher.cc
+++ b/libweave/src/privet/publisher.cc
@@ -11,6 +11,7 @@
 
 #include "src/privet/cloud_delegate.h"
 #include "src/privet/device_delegate.h"
+#include "src/privet/device_ui_kind.h"
 #include "src/privet/wifi_bootstrap_manager.h"
 #include "src/privet/wifi_ssid_generator.h"
 #include "src/string_utils.h"
@@ -54,15 +55,10 @@
   const uint16_t port = device_->GetHttpEnpoint().first;
   DCHECK_NE(port, 0);
 
-  std::string services;
-  if (!cloud_->GetServices().empty())
-    services += "_";
-  services += Join(",_", cloud_->GetServices());
-
   std::vector<std::string> txt_record{
       {"txtvers=3"},
       {"ty=" + name},
-      {"services=" + services},
+      {"services=" + GetDeviceUiKind(model_id)},
       {"id=" + cloud_->GetDeviceId()},
       {"mmid=" + model_id},
       {"flags=" + WifiSsidGenerator{cloud_, wifi_}.GenerateFlags()},
diff --git a/libweave/src/weave_unittest.cc b/libweave/src/weave_unittest.cc
index eb41294..6ff3f6d 100644
--- a/libweave/src/weave_unittest.cc
+++ b/libweave/src/weave_unittest.cc
@@ -190,9 +190,9 @@
   }
 
   void InitDnsSdPublishing(bool registered, const std::string& flags) {
-    std::vector<std::string> txt{{"id=TEST_DEVICE_ID"}, {"flags=" + flags},
-                                 {"mmid=ABCDE"},        {"services=_base"},
-                                 {"txtvers=3"},         {"ty=TEST_NAME"}};
+    std::vector<std::string> txt{
+        {"id=TEST_DEVICE_ID"},         {"flags=" + flags}, {"mmid=ABCDE"},
+        {"services=developmentBoard"}, {"txtvers=3"},      {"ty=TEST_NAME"}};
     if (registered) {
       txt.push_back("gcd_id=CLOUD_ID");