Chromium Code Reviews| Index: base/sys_info_chromeos.cc |
| =================================================================== |
| --- base/sys_info_chromeos.cc (revision 79674) |
| +++ base/sys_info_chromeos.cc (working copy) |
| @@ -7,37 +7,59 @@ |
| #include "base/basictypes.h" |
| #include "base/file_path.h" |
| #include "base/file_util.h" |
| +#include "base/lazy_instance.h" |
| #include "base/string_number_conversions.h" |
| #include "base/string_tokenizer.h" |
| #include "base/threading/thread_restrictions.h" |
| +#include <execinfo.h> |
| + |
| namespace base { |
| -#if defined(GOOGLE_CHROME_BUILD) |
| -static const char kLinuxStandardBaseVersionKey[] = "GOOGLE_RELEASE"; |
| -#else |
| -static const char kLinuxStandardBaseVersionKey[] = "DISTRIB_RELEASE"; |
| -#endif |
| - |
| +static const char kLinuxStandardBaseVersionKey[] = "CHROMEOS_RELEASE_VERSION"; |
|
Chris Masone
2011/03/29 15:43:25
What will happen when this is run on a non-chrome-
dgozman
2011/03/30 12:30:17
I think, when you run this on a non-chrome-os, you
Chris Masone
2011/03/30 14:38:02
I know, but that was deemed to better than returni
dgozman
2011/04/01 15:28:31
I added checking for multiple keys.
|
| const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release"; |
| +struct ChromeOSVersionNumbers { |
| + ChromeOSVersionNumbers() |
| + : major_version(0), |
| + minor_version(0), |
| + bugfix_version(0), |
| + parsed(false) { |
| + } |
| + |
| + int32 major_version; |
| + int32 minor_version; |
| + int32 bugfix_version; |
| + bool parsed; |
| +}; |
| + |
| +static base::LazyInstance<ChromeOSVersionNumbers> |
| + g_chrome_os_version_numbers(base::LINKER_INITIALIZED); |
| + |
| // static |
| void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, |
| int32 *minor_version, |
| int32 *bugfix_version) { |
| - // The other implementations of SysInfo don't block on the disk. |
| - // See http://code.google.com/p/chromium/issues/detail?id=60394 |
| - // Perhaps the caller ought to cache this? |
| - // Temporary allowing while we work the bug out. |
| - base::ThreadRestrictions::ScopedAllowIO allow_io; |
| + if (!g_chrome_os_version_numbers.Get().parsed) { |
| + // The other implementations of SysInfo don't block on the disk. |
| + // See http://code.google.com/p/chromium/issues/detail?id=60394 |
| + // Perhaps the caller ought to cache this? |
| + // Temporary allowing while we work the bug out. |
| + base::ThreadRestrictions::ScopedAllowIO allow_io; |
| - // TODO(cmasone): If this gets called a lot, it may kill performance. |
| - // consider using static variables to cache these values? |
| - FilePath path(kLinuxStandardBaseReleaseFile); |
| - std::string contents; |
| - if (file_util::ReadFileToString(path, &contents)) { |
| - ParseLsbRelease(contents, major_version, minor_version, bugfix_version); |
| + FilePath path(kLinuxStandardBaseReleaseFile); |
| + std::string contents; |
| + if (file_util::ReadFileToString(path, &contents)) { |
| + g_chrome_os_version_numbers.Get().parsed = true; |
| + ParseLsbRelease(contents, |
| + &(g_chrome_os_version_numbers.Get().major_version), |
| + &(g_chrome_os_version_numbers.Get().minor_version), |
| + &(g_chrome_os_version_numbers.Get().bugfix_version)); |
| + } |
| } |
| + *major_version = g_chrome_os_version_numbers.Get().major_version; |
| + *minor_version = g_chrome_os_version_numbers.Get().minor_version; |
| + *bugfix_version = g_chrome_os_version_numbers.Get().bugfix_version; |
| } |
| // static |