Find device-dependent disk stats file, and skip disk stats if not available.

Change-Id: I03afb85e3357dd4c2cf5effd98b194c71d77c71d

BUG=12171
TEST=unit tested

Review URL: http://codereview.chromium.org/6541007
diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc
index 1e15e1d..4820590 100644
--- a/metrics/metrics_daemon.cc
+++ b/metrics/metrics_daemon.cc
@@ -146,8 +146,7 @@
       session_state_(kUnknownSessionState),
       user_active_(false),
       usemon_interval_(0),
-      usemon_source_(NULL),
-      diskstats_path_(NULL) {}
+      usemon_source_(NULL) {}
 
 MetricsDaemon::~MetricsDaemon() {
   DeleteFrequencyCounters();
@@ -215,7 +214,7 @@
 }
 
 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib,
-                         const char* diskstats_path) {
+                         string diskstats_path) {
   testing_ = testing;
   DCHECK(metrics_lib != NULL);
   metrics_lib_ = metrics_lib;
@@ -243,8 +242,11 @@
   ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName);
   ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName);
 
-  diskstats_path_ = diskstats_path;
-  DiskStatsReporterInit();
+  // Don't attempt to collect disk stats if there is no disk stats file.
+  if (!diskstats_path.empty()) {
+    diskstats_path_ = diskstats_path;
+    DiskStatsReporterInit();
+  }
 
   // Don't setup D-Bus and GLib in test mode.
   if (testing)
@@ -541,7 +543,7 @@
   int nchars;
   int nitems;
   char line[200];
-  int file = HANDLE_EINTR(open(diskstats_path_, O_RDONLY));
+  int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY));
   if (file < 0) {
     PLOG(WARNING) << "cannot open " << diskstats_path_;
     return;