Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chromeos / system / statistics_provider.cc
index 93557b9..7fc6327 100644 (file)
@@ -11,6 +11,7 @@
 #include "base/logging.h"
 #include "base/memory/singleton.h"
 #include "base/path_service.h"
+#include "base/strings/string_number_conversions.h"
 #include "base/synchronization/cancellation_flag.h"
 #include "base/synchronization/waitable_event.h"
 #include "base/sys_info.h"
@@ -37,6 +38,7 @@ const char kCrosSystemUnknownValue[] = "(error)";
 
 const char kHardwareClassCrosSystemKey[] = "hwid";
 const char kUnknownHardwareClass[] = "unknown";
+const char kSerialNumber[] = "sn";
 
 // File to get machine hardware info from, and key/value delimiters of
 // the file.
@@ -269,6 +271,17 @@ void StatisticsProviderImpl::LoadMachineStatistics(bool load_oem_manifest) {
     oem_manifest_loaded_ = true;
   }
 
+  if (!base::SysInfo::IsRunningOnChromeOS() &&
+      machine_info_.find(kSerialNumber) == machine_info_.end()) {
+    // Set stub value for testing. A time value is appended to avoid clashes of
+    // the same serial for the same domain, which would invalidate earlier
+    // enrollments. A fake /tmp/machine-info file should be used instead if
+    // a stable serial is needed, e.g. to test re-enrollment.
+    base::TimeDelta time = base::Time::Now() - base::Time::UnixEpoch();
+    machine_info_[kSerialNumber] =
+        "stub_serial_number_" + base::Int64ToString(time.InSeconds());
+  }
+
   // Finished loading the statistics.
   on_statistics_loaded_.Signal();
   VLOG(1) << "Finished loading statistics.";