shill: KeyValueStore: Add string vector properties

Add a "Strings" map to the KeyValueStore so vectors of strings
can be stored.

BUG=chromium:249363
TEST=Unit tests

Change-Id: Ia9964da4a0905c5b44f9790549572c09d3428231
Reviewed-on: https://gerrit.chromium.org/gerrit/58541
Commit-Queue: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/key_value_store.cc b/key_value_store.cc
index e588958..44c90a8 100644
--- a/key_value_store.cc
+++ b/key_value_store.cc
@@ -10,6 +10,7 @@
 
 using std::map;
 using std::string;
+using std::vector;
 
 namespace shill {
 
@@ -41,6 +42,10 @@
   return ContainsKey(string_properties_, name);
 }
 
+bool KeyValueStore::ContainsStrings(const string &name) const {
+  return ContainsKey(strings_properties_, name);
+}
+
 bool KeyValueStore::ContainsUint(const string &name) const {
   return ContainsKey(uint_properties_, name);
 }
@@ -63,6 +68,12 @@
   return it->second;
 }
 
+const vector<string> &KeyValueStore::GetStrings(const string &name) const {
+  const auto it(strings_properties_.find(name));
+  CHECK(it != strings_properties_.end()) << "for strings property " << name;
+  return it->second;
+}
+
 uint32 KeyValueStore::GetUint(const string &name) const {
   map<string, uint32>::const_iterator it(uint_properties_.find(name));
   CHECK(it != uint_properties_.end()) << "for uint property " << name;
@@ -81,6 +92,11 @@
   string_properties_[name] = value;
 }
 
+void KeyValueStore::SetStrings(const string &name,
+                               const vector<string> &value) {
+  strings_properties_[name] = value;
+}
+
 void KeyValueStore::SetUint(const string &name, uint32 value) {
   uint_properties_[name] = value;
 }
@@ -89,6 +105,10 @@
   string_properties_.erase(name);
 }
 
+void KeyValueStore::RemoveStrings(const string &name) {
+  strings_properties_.erase(name);
+}
+
 void KeyValueStore::RemoveInt(const string &name) {
   int_properties_.erase(name);
 }
diff --git a/key_value_store.h b/key_value_store.h
index 12915fe..bde9a18 100644
--- a/key_value_store.h
+++ b/key_value_store.h
@@ -7,6 +7,7 @@
 
 #include <map>
 #include <string>
+#include <vector>
 
 #include <base/basictypes.h>
 
@@ -35,19 +36,24 @@
   bool ContainsBool(const std::string &name) const;
   bool ContainsInt(const std::string &name) const;
   bool ContainsString(const std::string &name) const;
+  bool ContainsStrings(const std::string &name) const;
   bool ContainsUint(const std::string &name) const;
 
   bool GetBool(const std::string &name) const;
   int32 GetInt(const std::string &name) const;
   const std::string &GetString(const std::string &name) const;
+  const std::vector<std::string> &GetStrings(const std::string &name) const;
   uint32 GetUint(const std::string &name) const;
 
   void SetBool(const std::string &name, bool value);
   void SetInt(const std::string &name, int32 value);
-  void SetString(const std::string& name, const std::string& value);
+  void SetString(const std::string &name, const std::string &value);
+  void SetStrings(const std::string &name,
+                  const std::vector<std::string> &value);
   void SetUint(const std::string &name, uint32 value);
 
   void RemoveString(const std::string &name);
+  void RemoveStrings(const std::string &name);
   void RemoveInt(const std::string &name);
 
   // If |name| is in this store returns its value, otherwise returns
@@ -65,6 +71,10 @@
   const std::map<std::string, std::string> &string_properties() const {
     return string_properties_;
   }
+  const std::map<std::string,
+                 std::vector<std::string>> &strings_properties() const {
+    return strings_properties_;
+  }
   const std::map<std::string, uint32> &uint_properties() const {
     return uint_properties_;
   }
@@ -73,6 +83,7 @@
   std::map<std::string, bool> bool_properties_;
   std::map<std::string, int32> int_properties_;
   std::map<std::string, std::string> string_properties_;
+  std::map<std::string, std::vector<std::string>> strings_properties_;
   std::map<std::string, uint32> uint_properties_;
 };
 
diff --git a/key_value_store_unittest.cc b/key_value_store_unittest.cc
index e82ae10..7dc846d 100644
--- a/key_value_store_unittest.cc
+++ b/key_value_store_unittest.cc
@@ -7,6 +7,7 @@
 #include <gtest/gtest.h>
 
 using std::string;
+using std::vector;
 using testing::Test;
 
 namespace shill {
@@ -62,6 +63,17 @@
   EXPECT_EQ(kDefaultValue, store_.LookupString(kKey, kDefaultValue));
 }
 
+TEST_F(KeyValueStoreTest, Strings) {
+  const string kKey("foo");
+  const vector<string> kValue{ "baz0", "baz1", "baz2" };
+  EXPECT_FALSE(store_.ContainsStrings(kKey));
+  store_.SetStrings(kKey, kValue);
+  EXPECT_TRUE(store_.ContainsStrings(kKey));
+  EXPECT_EQ(kValue, store_.GetStrings(kKey));
+  store_.RemoveStrings(kKey);
+  EXPECT_FALSE(store_.ContainsStrings(kKey));
+}
+
 TEST_F(KeyValueStoreTest, Uint) {
   const string kKey("foo");
   const uint32 kValue = 456;