crash-reporter: Use chromeos::KeyValueStore.

Make the crash reporter use libchromeos's KeyValueStore
class to read its log-collection config file and
/etc/lsb-release instead of its own parsing code.

Also update the log-collection config file to split long
commands across multiple lines and to use '=' instead of ':'
to separate executable names from commands.

BUG=chromium:452520
TEST=updated tests; also triggered powerd and chrome crashes
     and checked that logs were attached

Change-Id: I4e2447712869608f32a4ae38f5d5cb9c6046af14
Reviewed-on: https://chromium-review.googlesource.com/244121
Reviewed-by: Dan Erat <derat@chromium.org>
Commit-Queue: Dan Erat <derat@chromium.org>
Tested-by: Dan Erat <derat@chromium.org>
diff --git a/crash_reporter/crash_collector_test.cc b/crash_reporter/crash_collector_test.cc
index 1548d70..0ca3792 100644
--- a/crash_reporter/crash_collector_test.cc
+++ b/crash_reporter/crash_collector_test.cc
@@ -220,59 +220,6 @@
   EXPECT_FALSE(CheckHasCapacity());
 }
 
-TEST_F(CrashCollectorTest, IsCommentLine) {
-  EXPECT_FALSE(CrashCollector::IsCommentLine(""));
-  EXPECT_TRUE(CrashCollector::IsCommentLine("#"));
-  EXPECT_TRUE(CrashCollector::IsCommentLine("#real comment"));
-  EXPECT_TRUE(CrashCollector::IsCommentLine(" # real comment"));
-  EXPECT_FALSE(CrashCollector::IsCommentLine("not comment"));
-  EXPECT_FALSE(CrashCollector::IsCommentLine(" not comment"));
-}
-
-TEST_F(CrashCollectorTest, ReadKeyValueFile) {
-  const char *contents = ("a=b\n"
-                          "\n"
-                          " c=d \n");
-  FilePath path(test_dir_.Append("keyval"));
-  std::map<std::string, std::string> dictionary;
-  std::map<std::string, std::string>::iterator i;
-
-  base::WriteFile(path, contents, strlen(contents));
-
-  EXPECT_TRUE(collector_.ReadKeyValueFile(path, '=', &dictionary));
-  i = dictionary.find("a");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "b");
-  i = dictionary.find("c");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "d");
-
-  dictionary.clear();
-
-  contents = ("a=b c d\n"
-              "e\n"
-              " f g = h\n"
-              "i=j\n"
-              "=k\n"
-              "#comment=0\n"
-              "l=\n");
-  base::WriteFile(path, contents, strlen(contents));
-
-  EXPECT_FALSE(collector_.ReadKeyValueFile(path, '=', &dictionary));
-  EXPECT_EQ(5, dictionary.size());
-
-  i = dictionary.find("a");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "b c d");
-  i = dictionary.find("e");
-  EXPECT_TRUE(i == dictionary.end());
-  i = dictionary.find("f g");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "h");
-  i = dictionary.find("i");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "j");
-  i = dictionary.find("");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "k");
-  i = dictionary.find("l");
-  EXPECT_TRUE(i != dictionary.end() && i->second == "");
-}
-
 TEST_F(CrashCollectorTest, MetaData) {
   const char kMetaFileBasename[] = "generated.meta";
   FilePath meta_file = test_dir_.Append(kMetaFileBasename);
@@ -280,7 +227,10 @@
   FilePath payload_file = test_dir_.Append("payload-file");
   std::string contents;
   collector_.lsb_release_ = lsb_release.value();
-  const char kLsbContents[] = "CHROMEOS_RELEASE_VERSION=version\n";
+  const char kLsbContents[] =
+      "CHROMEOS_RELEASE_BOARD=lumpy\n"
+      "CHROMEOS_RELEASE_VERSION=6727.0.2015_01_26_0853\n"
+      "CHROMEOS_RELEASE_NAME=Chromium OS\n";
   ASSERT_TRUE(base::WriteFile(lsb_release, kLsbContents, strlen(kLsbContents)));
   const char kPayload[] = "foo";
   ASSERT_TRUE(base::WriteFile(payload_file, kPayload, strlen(kPayload)));
@@ -290,7 +240,7 @@
   const char kExpectedMeta[] =
       "foo=bar\n"
       "exec_name=kernel\n"
-      "ver=version\n"
+      "ver=6727.0.2015_01_26_0853\n"
       "payload=test/payload-file\n"
       "payload_size=3\n"
       "done=1\n";
@@ -328,7 +278,7 @@
   FilePath config_file = test_dir_.Append("crash_config");
   FilePath output_file = test_dir_.Append("crash_log");
   const char kConfigContents[] =
-      "foobar:echo hello there | sed -e \"s/there/world/\"";
+      "foobar=echo hello there | \\\n  sed -e \"s/there/world/\"";
   ASSERT_TRUE(
       base::WriteFile(config_file, kConfigContents, strlen(kConfigContents)));
   base::DeleteFile(FilePath(output_file), false);