Include output of "lsb_release -d" in crash reports.

/etc/lsb-release does not exist on all distros, and sometimes it does
not provide any useful info. Whereas all LSB complaint distros return
useful data with the lsb_release command.
Review URL: http://codereview.chromium.org/155653

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20936 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 912c64520e0e9f22bd49e43c7ee102e3b9de66a7
diff --git a/base/linux_util.cc b/base/linux_util.cc
index a58ee99..604980b 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -2,10 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "linux_util.h"
+#include "base/linux_util.h"
 
 #include <stdlib.h>
 
+#include <vector>
+
+#include "base/command_line.h"
+#include "base/process_util.h"
+
 namespace base {
 
 uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
@@ -28,4 +33,30 @@
   return new_pixels;
 }
 
+// We use this static string to hold the Linux distro info. If we
+// crash, the crash handler code will send this in the crash dump.
+std::string linux_distro = "Unknown";
+
+std::string GetLinuxDistro() {
+  static bool checked_distro = false;
+  if (!checked_distro) {
+    std::vector<std::string> argv;
+    argv.push_back("lsb_release");
+    argv.push_back("-d");
+    std::string output;
+    base::GetAppOutput(CommandLine(argv), &output);
+    if (output.length() > 0) {
+      // lsb_release -d should return: Description:<tab>Distro Info
+      static const std::string field = "Description:\t";
+      if (output.compare(0, field.length(), field) == 0)
+        linux_distro = output.substr(field.length());
+    }
+    // We do this check only once per process. If it fails, there's
+    // little reason to believe it will work if we attempt to run
+    // lsb_release again.
+    checked_distro = true;
+  }
+  return linux_distro;
+}
+
 }  // namespace base