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

Side by Side Diff: base/win/windows_version.h

Issue 6713107: Make the windows_version.h functions threadsafe by using a singleton. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef BASE_WIN_WINDOWS_VERSION_H_ 5 #ifndef BASE_WIN_WINDOWS_VERSION_H_
6 #define BASE_WIN_WINDOWS_VERSION_H_ 6 #define BASE_WIN_WINDOWS_VERSION_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/base_api.h" 9 #include "base/base_api.h"
10 #include "base/memory/singleton.h"
10 11
11 typedef void* HANDLE; 12 typedef void* HANDLE;
12 13
13 namespace base { 14 namespace base {
14 namespace win { 15 namespace win {
15 16
17 // The running version of Windows. This is declared outside OSInfo for
18 // syntactic sugar reasons; see the declaration of GetVersion() below.
16 // NOTE: Keep these in order so callers can do things like 19 // NOTE: Keep these in order so callers can do things like
17 // "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values, 20 // "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...".
18 // though.
19 enum Version { 21 enum Version {
20 VERSION_PRE_2000 = 0, // Not supported 22 VERSION_PRE_XP = 0, // Not supported.
21 VERSION_2000 = 1, // Not supported 23 VERSION_XP,
22 VERSION_XP = 2, 24 VERSION_SERVER_2003, // Also includes Windows XP Professional x64.
23 VERSION_SERVER_2003 = 3, // Also includes Windows XP Professional x64 edition 25 VERSION_VISTA,
24 VERSION_VISTA = 4, 26 VERSION_SERVER_2008,
25 VERSION_2008 = 5, 27 VERSION_WIN7,
26 VERSION_WIN7 = 6,
27 }; 28 };
28 29
29 // Returns the running version of Windows. 30 // A Singleton that can be used to query various pieces of information about the
30 BASE_API Version GetVersion(); 31 // OS and process state.
32 class BASE_API OSInfo {
33 public:
34 // The processor architecture this copy of Windows natively uses, which may
35 // not be the same as the processor's "native architecture". For example,
rvargas (doing something else) 2011/04/06 23:28:05 nit: could you remove the part about the "processo
Peter Kasting 2011/04/07 00:29:19 Done.
36 // given an x64-capable processor, we have three possibilities:
37 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE
38 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
39 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE
40 enum WindowsArchitecture {
41 X86_ARCHITECTURE,
42 X64_ARCHITECTURE,
43 IA64_ARCHITECTURE,
44 OTHER_ARCHITECTURE,
45 };
31 46
32 // Returns the major and minor version of the service pack installed. 47 // Whether a process is running under WOW64 (the wrapper that allows 32-bit
33 BASE_API void GetServicePackLevel(int* major, int* minor); 48 // processes to run on 64-bit versions of Windows). This will return
49 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
50 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g.
51 // the process does not have sufficient access rights to determine this.
52 enum WOW64Status {
53 WOW64_DISABLED,
54 WOW64_ENABLED,
55 WOW64_UNKNOWN,
56 };
34 57
35 enum WindowsArchitecture { 58 static OSInfo* GetInstance();
36 X86_ARCHITECTURE, 59
37 X64_ARCHITECTURE, 60 Version version() const { return version_; }
38 IA64_ARCHITECTURE, 61 // The next two functions return arrays of values, [major, minor(, build)].
rvargas (doing something else) 2011/04/06 23:28:05 Have you considered defining a couple of structs h
Peter Kasting 2011/04/07 00:29:19 Good idea! Done.
39 OTHER_ARCHITECTURE, 62 const int* version_number() const { return version_number_; }
63 const int* service_pack() const { return service_pack_; }
64 WindowsArchitecture architecture() const { return architecture_; }
65 int processors() const { return processors_; }
66 size_t allocation_granularity() const { return allocation_granularity_; }
67 WOW64Status wow64_status() const { return wow64_status_; }
68
69 // Like wow64_status(), but for the supplied handle instead of the current
70 // process. This doesn't touch member state, so you can bypass the singleton.
71 static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
72
73 private:
74 OSInfo();
75 ~OSInfo();
76
77 Version version_;
78 int version_number_[3];
79 int service_pack_[2];
80 WindowsArchitecture architecture_;
81 int processors_;
82 size_t allocation_granularity_;
83 WOW64Status wow64_status_;
84
85 friend struct DefaultSingletonTraits<OSInfo>;
86 DISALLOW_COPY_AND_ASSIGN(OSInfo);
40 }; 87 };
41 88
42 // Returns the processor architecture this copy of Windows natively uses. 89 // Because this is by far the most commonly-requested value from the above
43 // For example, given an x64-capable processor, we have three possibilities: 90 // singleton, we add a global-scope accessor here as syntactic sugar.
44 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE 91 BASE_API Version GetVersion();
45 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
46 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE
47 BASE_API WindowsArchitecture GetWindowsArchitecture();
48
49 enum WOW64Status {
50 WOW64_DISABLED,
51 WOW64_ENABLED,
52 WOW64_UNKNOWN,
53 };
54
55 // Returns whether this process is running under WOW64 (the wrapper that allows
56 // 32-bit processes to run on 64-bit versions of Windows). This will return
57 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit Chrome
58 // on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. the
59 // process does not have sufficient access rights to determine this.
60 BASE_API WOW64Status GetWOW64Status();
61
62 // Like GetWOW64Status(), but for the supplied handle instead of the current
63 // process.
64 BASE_API WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
65 92
66 } // namespace win 93 } // namespace win
67 } // namespace base 94 } // namespace base
68 95
69 #endif // BASE_WIN_WINDOWS_VERSION_H_ 96 #endif // BASE_WIN_WINDOWS_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698