- add sources.
[platform/framework/web/crosswalk.git] / src / base / win / windows_version.h
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
3 // found in the LICENSE file.
4
5 #ifndef BASE_WIN_WINDOWS_VERSION_H_
6 #define BASE_WIN_WINDOWS_VERSION_H_
7
8 #include <string>
9
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
12
13 typedef void* HANDLE;
14
15 namespace base {
16 namespace win {
17
18 // The running version of Windows.  This is declared outside OSInfo for
19 // syntactic sugar reasons; see the declaration of GetVersion() below.
20 // NOTE: Keep these in order so callers can do things like
21 // "if (base::win::GetVersion() >= base::win::VERSION_VISTA) ...".
22 enum Version {
23   VERSION_PRE_XP = 0,  // Not supported.
24   VERSION_XP,
25   VERSION_SERVER_2003, // Also includes XP Pro x64 and Server 2003 R2.
26   VERSION_VISTA,       // Also includes Windows Server 2008.
27   VERSION_WIN7,        // Also includes Windows Server 2008 R2.
28   VERSION_WIN8,        // Also includes Windows Server 2012.
29   VERSION_WIN8_1,      // Code named Windows Blue
30   VERSION_WIN_LAST,    // Indicates error condition.
31 };
32
33 // A singleton that can be used to query various pieces of information about the
34 // OS and process state. Note that this doesn't use the base Singleton class, so
35 // it can be used without an AtExitManager.
36 class BASE_EXPORT OSInfo {
37  public:
38   struct VersionNumber {
39     int major;
40     int minor;
41     int build;
42   };
43
44   struct ServicePack {
45     int major;
46     int minor;
47   };
48
49   // The processor architecture this copy of Windows natively uses.  For
50   // example, given an x64-capable processor, we have three possibilities:
51   //   32-bit Chrome running on 32-bit Windows:           X86_ARCHITECTURE
52   //   32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
53   //   64-bit Chrome running on 64-bit Windows:           X64_ARCHITECTURE
54   enum WindowsArchitecture {
55     X86_ARCHITECTURE,
56     X64_ARCHITECTURE,
57     IA64_ARCHITECTURE,
58     OTHER_ARCHITECTURE,
59   };
60
61   // Whether a process is running under WOW64 (the wrapper that allows 32-bit
62   // processes to run on 64-bit versions of Windows).  This will return
63   // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
64   // Chrome on 64-bit Windows".  WOW64_UNKNOWN means "an error occurred", e.g.
65   // the process does not have sufficient access rights to determine this.
66   enum WOW64Status {
67     WOW64_DISABLED,
68     WOW64_ENABLED,
69     WOW64_UNKNOWN,
70   };
71
72   static OSInfo* GetInstance();
73
74   Version version() const { return version_; }
75   // The next two functions return arrays of values, [major, minor(, build)].
76   VersionNumber version_number() const { return version_number_; }
77   ServicePack service_pack() const { return service_pack_; }
78   WindowsArchitecture architecture() const { return architecture_; }
79   int processors() const { return processors_; }
80   size_t allocation_granularity() const { return allocation_granularity_; }
81   WOW64Status wow64_status() const { return wow64_status_; }
82   std::string processor_model_name();
83
84   // Like wow64_status(), but for the supplied handle instead of the current
85   // process.  This doesn't touch member state, so you can bypass the singleton.
86   static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
87
88  private:
89   OSInfo();
90   ~OSInfo();
91
92   Version version_;
93   VersionNumber version_number_;
94   ServicePack service_pack_;
95   WindowsArchitecture architecture_;
96   int processors_;
97   size_t allocation_granularity_;
98   WOW64Status wow64_status_;
99   std::string processor_model_name_;
100
101   DISALLOW_COPY_AND_ASSIGN(OSInfo);
102 };
103
104 // Because this is by far the most commonly-requested value from the above
105 // singleton, we add a global-scope accessor here as syntactic sugar.
106 BASE_EXPORT Version GetVersion();
107
108 }  // namespace win
109 }  // namespace base
110
111 #endif  // BASE_WIN_WINDOWS_VERSION_H_