OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_info.h" | 5 #include "base/sys_info.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
13 #include "base/string_tokenizer.h" | 13 #include "base/strings/string_tokenizer.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 | 15 |
16 #include <execinfo.h> | 16 #include <execinfo.h> |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 | 19 |
20 static const char* kLinuxStandardBaseVersionKeys[] = { | 20 static const char* kLinuxStandardBaseVersionKeys[] = { |
21 "CHROMEOS_RELEASE_VERSION", | 21 "CHROMEOS_RELEASE_VERSION", |
22 "GOOGLE_RELEASE", | 22 "GOOGLE_RELEASE", |
23 "DISTRIB_RELEASE", | 23 "DISTRIB_RELEASE", |
24 NULL | 24 NULL |
25 }; | 25 }; |
26 | 26 |
27 const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release"; | 27 const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release"; |
28 | 28 |
29 struct ChromeOSVersionNumbers { | 29 struct ChromeOSVersionNumbers { |
30 ChromeOSVersionNumbers() | 30 ChromeOSVersionNumbers() |
31 : major_version(0), | 31 : major_version(0), |
32 minor_version(0), | 32 minor_version(0), |
33 bugfix_version(0), | 33 bugfix_version(0), |
34 parsed(false) { | 34 parsed(false) { |
35 } | 35 } |
36 | 36 |
37 int32 major_version; | 37 int32 major_version; |
38 int32 minor_version; | 38 int32 minor_version; |
39 int32 bugfix_version; | 39 int32 bugfix_version; |
40 bool parsed; | 40 bool parsed; |
41 }; | 41 }; |
42 | 42 |
43 static base::LazyInstance<ChromeOSVersionNumbers> | 43 static LazyInstance<ChromeOSVersionNumbers> |
44 g_chrome_os_version_numbers = LAZY_INSTANCE_INITIALIZER; | 44 g_chrome_os_version_numbers = LAZY_INSTANCE_INITIALIZER; |
45 | 45 |
46 // static | 46 // static |
47 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, | 47 void SysInfo::OperatingSystemVersionNumbers(int32* major_version, |
48 int32* minor_version, | 48 int32* minor_version, |
49 int32* bugfix_version) { | 49 int32* bugfix_version) { |
50 if (!g_chrome_os_version_numbers.Get().parsed) { | 50 if (!g_chrome_os_version_numbers.Get().parsed) { |
51 // The other implementations of SysInfo don't block on the disk. | 51 // The other implementations of SysInfo don't block on the disk. |
52 // See http://code.google.com/p/chromium/issues/detail?id=60394 | 52 // See http://code.google.com/p/chromium/issues/detail?id=60394 |
53 // Perhaps the caller ought to cache this? | 53 // Perhaps the caller ought to cache this? |
54 // Temporary allowing while we work the bug out. | 54 // Temporary allowing while we work the bug out. |
55 base::ThreadRestrictions::ScopedAllowIO allow_io; | 55 ThreadRestrictions::ScopedAllowIO allow_io; |
56 | 56 |
57 FilePath path(kLinuxStandardBaseReleaseFile); | 57 FilePath path(kLinuxStandardBaseReleaseFile); |
58 std::string contents; | 58 std::string contents; |
59 if (file_util::ReadFileToString(path, &contents)) { | 59 if (file_util::ReadFileToString(path, &contents)) { |
60 g_chrome_os_version_numbers.Get().parsed = true; | 60 g_chrome_os_version_numbers.Get().parsed = true; |
61 ParseLsbRelease(contents, | 61 ParseLsbRelease(contents, |
62 &(g_chrome_os_version_numbers.Get().major_version), | 62 &(g_chrome_os_version_numbers.Get().major_version), |
63 &(g_chrome_os_version_numbers.Get().minor_version), | 63 &(g_chrome_os_version_numbers.Get().minor_version), |
64 &(g_chrome_os_version_numbers.Get().bugfix_version)); | 64 &(g_chrome_os_version_numbers.Get().bugfix_version)); |
65 } | 65 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 FilePath SysInfo::GetLsbReleaseFilePath() { | 117 FilePath SysInfo::GetLsbReleaseFilePath() { |
118 return FilePath(kLinuxStandardBaseReleaseFile); | 118 return FilePath(kLinuxStandardBaseReleaseFile); |
119 } | 119 } |
120 | 120 |
121 } // namespace base | 121 } // namespace base |
OLD | NEW |