Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: base/sys_info_chromeos.cc

Issue 6771012: Read ChromeOS version numbers from file before sandboxing and cache them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/app/chrome_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
11 #include "base/string_tokenizer.h" 12 #include "base/string_tokenizer.h"
12 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
13 14
15 #include <execinfo.h>
16
14 namespace base { 17 namespace base {
15 18
16 #if defined(GOOGLE_CHROME_BUILD) 19 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.
17 static const char kLinuxStandardBaseVersionKey[] = "GOOGLE_RELEASE"; 20 const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release";
18 #else
19 static const char kLinuxStandardBaseVersionKey[] = "DISTRIB_RELEASE";
20 #endif
21 21
22 const char kLinuxStandardBaseReleaseFile[] = "/etc/lsb-release"; 22 struct ChromeOSVersionNumbers {
23 ChromeOSVersionNumbers()
24 : major_version(0),
25 minor_version(0),
26 bugfix_version(0),
27 parsed(false) {
28 }
29
30 int32 major_version;
31 int32 minor_version;
32 int32 bugfix_version;
33 bool parsed;
34 };
35
36 static base::LazyInstance<ChromeOSVersionNumbers>
37 g_chrome_os_version_numbers(base::LINKER_INITIALIZED);
23 38
24 // static 39 // static
25 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version, 40 void SysInfo::OperatingSystemVersionNumbers(int32 *major_version,
26 int32 *minor_version, 41 int32 *minor_version,
27 int32 *bugfix_version) { 42 int32 *bugfix_version) {
28 // The other implementations of SysInfo don't block on the disk. 43 if (!g_chrome_os_version_numbers.Get().parsed) {
29 // See http://code.google.com/p/chromium/issues/detail?id=60394 44 // The other implementations of SysInfo don't block on the disk.
30 // Perhaps the caller ought to cache this? 45 // See http://code.google.com/p/chromium/issues/detail?id=60394
31 // Temporary allowing while we work the bug out. 46 // Perhaps the caller ought to cache this?
32 base::ThreadRestrictions::ScopedAllowIO allow_io; 47 // Temporary allowing while we work the bug out.
48 base::ThreadRestrictions::ScopedAllowIO allow_io;
33 49
34 // TODO(cmasone): If this gets called a lot, it may kill performance. 50 FilePath path(kLinuxStandardBaseReleaseFile);
35 // consider using static variables to cache these values? 51 std::string contents;
36 FilePath path(kLinuxStandardBaseReleaseFile); 52 if (file_util::ReadFileToString(path, &contents)) {
37 std::string contents; 53 g_chrome_os_version_numbers.Get().parsed = true;
38 if (file_util::ReadFileToString(path, &contents)) { 54 ParseLsbRelease(contents,
39 ParseLsbRelease(contents, major_version, minor_version, bugfix_version); 55 &(g_chrome_os_version_numbers.Get().major_version),
56 &(g_chrome_os_version_numbers.Get().minor_version),
57 &(g_chrome_os_version_numbers.Get().bugfix_version));
58 }
40 } 59 }
60 *major_version = g_chrome_os_version_numbers.Get().major_version;
61 *minor_version = g_chrome_os_version_numbers.Get().minor_version;
62 *bugfix_version = g_chrome_os_version_numbers.Get().bugfix_version;
41 } 63 }
42 64
43 // static 65 // static
44 std::string SysInfo::GetLinuxStandardBaseVersionKey() { 66 std::string SysInfo::GetLinuxStandardBaseVersionKey() {
45 return std::string(kLinuxStandardBaseVersionKey); 67 return std::string(kLinuxStandardBaseVersionKey);
46 } 68 }
47 69
48 // static 70 // static
49 void SysInfo::ParseLsbRelease(const std::string& lsb_release, 71 void SysInfo::ParseLsbRelease(const std::string& lsb_release,
50 int32 *major_version, 72 int32 *major_version,
(...skipping 20 matching lines...) Expand all
71 minor_version); 93 minor_version);
72 } else { // 2 == i 94 } else { // 2 == i
73 StringToInt(tokenizer.token_begin(), 95 StringToInt(tokenizer.token_begin(),
74 tokenizer.token_end(), 96 tokenizer.token_end(),
75 bugfix_version); 97 bugfix_version);
76 } 98 }
77 } 99 }
78 } 100 }
79 101
80 } // namespace base 102 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/app/chrome_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698