summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 01:59:15 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 01:59:15 +0000
commit935aa54d9a5e2e617c61c9f8dcea398768413443 (patch)
tree3df9ec9316cd4d5b7171e5c6c869a01d823cc507 /base
parent7d1f3348c26eda2d1656860c821d335bf94d4cda (diff)
downloadchromium_src-935aa54d9a5e2e617c61c9f8dcea398768413443.zip
chromium_src-935aa54d9a5e2e617c61c9f8dcea398768413443.tar.gz
chromium_src-935aa54d9a5e2e617c61c9f8dcea398768413443.tar.bz2
Move windows version-related stuff out of base/win_util and into base/win/windows_version. Many files now only need to include this instead of all of win_util.
Remove a bunch of unused code from base/win_util. There was a surprising amount. Replace the AppUserModel property key with the one from the SDK now that we use the Win7 SDK. Move GetLogonSessionOnlyDACL from win_util to ipc since it's only used in that one place. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3823002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62694 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi32
-rw-r--r--base/base_paths_win.cc6
-rw-r--r--base/file_util_win.cc13
-rw-r--r--base/path_service_unittest.cc6
-rw-r--r--base/pe_image_unittest.cc6
-rw-r--r--base/platform_thread_win.cc6
-rw-r--r--base/process_util_win.cc4
-rw-r--r--base/trace_event_win_unittest.cc7
-rw-r--r--base/win/windows_version.cc72
-rw-r--r--base/win/windows_version.h34
-rw-r--r--base/win_util.cc235
-rw-r--r--base/win_util.h66
-rw-r--r--base/win_util_unittest.cc5
13 files changed, 177 insertions, 315 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 180a1f9..20223bb 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -301,6 +301,8 @@
'watchdog.h',
'weak_ptr.cc',
'weak_ptr.h',
+ 'win/windows_version.cc',
+ 'win/windows_version.h',
'win_util.cc',
'win_util.h',
'windows_message_list.h',
@@ -362,19 +364,23 @@
},
],
[ 'OS == "win"', {
- 'include_dirs': [
- '<(DEPTH)/third_party/wtl/include',
- ],
- 'sources!': [
- 'event_recorder_stubs.cc',
- 'file_descriptor_shuffle.cc',
- 'message_pump_libevent.cc',
- # Not using sha1_win.cc because it may have caused a
- # regression to page cycler moz.
- 'sha1_win.cc',
- 'string16.cc',
- 'trace_event.cc',
- ],
+ 'include_dirs': [
+ '<(DEPTH)/third_party/wtl/include',
+ ],
+ 'sources!': [
+ 'event_recorder_stubs.cc',
+ 'file_descriptor_shuffle.cc',
+ 'message_pump_libevent.cc',
+ # Not using sha1_win.cc because it may have caused a
+ # regression to page cycler moz.
+ 'sha1_win.cc',
+ 'string16.cc',
+ 'trace_event.cc',
+ ],
+ }, { # OS != "win"
+ 'sources/': [
+ ['exclude', '/win/*'],
+ ],
},],
],
}],
diff --git a/base/base_paths_win.cc b/base/base_paths_win.cc
index 9b5c150..25271e4 100644
--- a/base/base_paths_win.cc
+++ b/base/base_paths_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -86,7 +86,7 @@ bool PathProviderWin(int key, FilePath* result) {
cur = FilePath(system_buffer);
break;
case base::DIR_LOCAL_APP_DATA_LOW:
- if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
+ if (win::GetVersion() < win::VERSION_VISTA) {
return false;
}
// TODO(nsylvain): We should use SHGetKnownFolderPath instead. Bug 1281128
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index c601f46..d750749 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -23,6 +23,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/win_util.h"
+#include "base/win/windows_version.h"
namespace file_util {
@@ -261,7 +262,7 @@ bool CopyDirectory(const FilePath& from_path, const FilePath& to_path,
if (!PathExists(to_path)) {
// Except that Vista fails to do that, and instead do a recursive copy if
// the target directory doesn't exist.
- if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA)
+ if (base::win::GetVersion() >= base::win::VERSION_VISTA)
CreateDirectory(to_path);
else
ShellCopy(from_path, to_path, false);
@@ -402,7 +403,7 @@ bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination,
if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index)))
return false;
- if (app_id && (win_util::GetWinVersion() >= win_util::WINVERSION_WIN7)) {
+ if (app_id && (base::win::GetVersion() >= base::win::VERSION_WIN7)) {
ScopedComPtr<IPropertyStore> property_store;
if (FAILED(property_store.QueryFrom(i_shell_link)))
return false;
@@ -452,7 +453,7 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination,
if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index)))
return false;
- if (app_id && win_util::GetWinVersion() >= win_util::WINVERSION_WIN7) {
+ if (app_id && base::win::GetVersion() >= base::win::VERSION_WIN7) {
ScopedComPtr<IPropertyStore> property_store;
if (FAILED(property_store.QueryFrom(i_shell_link)))
return false;
@@ -467,7 +468,7 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination,
bool TaskbarPinShortcutLink(const wchar_t* shortcut) {
// "Pin to taskbar" is only supported after Win7.
- if (win_util::GetWinVersion() < win_util::WINVERSION_WIN7)
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
return false;
int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarpin", shortcut,
@@ -477,7 +478,7 @@ bool TaskbarPinShortcutLink(const wchar_t* shortcut) {
bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) {
// "Unpin from taskbar" is only supported after Win7.
- if (win_util::GetWinVersion() < win_util::WINVERSION_WIN7)
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
return false;
int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin",
@@ -1007,7 +1008,7 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) {
bool PreReadImage(const wchar_t* file_path, size_t size_to_read,
size_t step_size) {
- if (win_util::GetWinVersion() > win_util::WINVERSION_XP) {
+ if (base::win::GetVersion() > base::win::VERSION_XP) {
// Vista+ branch. On these OSes, the forced reads through the DLL actually
// slows warm starts. The solution is to sequentially read file contents
// with an optional cap on total amount to read.
diff --git a/base/path_service_unittest.cc b/base/path_service_unittest.cc
index cc86be0..4c41aed 100644
--- a/base/path_service_unittest.cc
+++ b/base/path_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,7 +8,7 @@
#include "base/file_util.h"
#include "base/file_path.h"
#if defined(OS_WIN)
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
#endif
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
@@ -50,7 +50,7 @@ TEST_F(PathServiceTest, Get) {
#if defined(OS_WIN)
for (int key = base::PATH_WIN_START + 1; key < base::PATH_WIN_END; ++key) {
if (key == base::DIR_LOCAL_APP_DATA_LOW &&
- win_util::GetWinVersion() < win_util::WINVERSION_VISTA) {
+ base::win::GetVersion() < base::win::VERSION_VISTA) {
// DIR_LOCAL_APP_DATA_LOW is not supported prior Vista and is expected to
// fail.
EXPECT_TRUE(ReturnsInvalidPath(key)) << key;
diff --git a/base/pe_image_unittest.cc b/base/pe_image_unittest.cc
index 1621843..6d8875e 100644
--- a/base/pe_image_unittest.cc
+++ b/base/pe_image_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "base/pe_image.h"
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
// Just counts the number of invocations.
bool ExportsCallback(const PEImage &image,
@@ -147,7 +147,7 @@ int GetExpectedValue(Value value, DWORD os) {
// the actual number of items found is within the expected range.
TEST(PEImageTest, EnumeratesPE) {
// Windows Server 2003 is not supported as a test environment for this test.
- if (win_util::GetWinVersion() == win_util::WINVERSION_SERVER_2003)
+ if (base::win::GetVersion() == base::win::VERSION_SERVER_2003)
return;
HMODULE module = LoadLibrary(L"advapi32.dll");
ASSERT_TRUE(NULL != module);
diff --git a/base/platform_thread_win.cc b/base/platform_thread_win.cc
index 2dd325e..a4a1b52 100644
--- a/base/platform_thread_win.cc
+++ b/base/platform_thread_win.cc
@@ -1,11 +1,11 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/platform_thread.h"
#include "base/logging.h"
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
namespace {
@@ -68,7 +68,7 @@ void PlatformThread::SetName(const char* name) {
bool PlatformThread::Create(size_t stack_size, Delegate* delegate,
PlatformThreadHandle* thread_handle) {
unsigned int flags = 0;
- if (stack_size > 0 && win_util::GetWinVersion() >= win_util::WINVERSION_XP) {
+ if (stack_size > 0 && base::win::GetVersion() >= base::win::VERSION_XP) {
flags = STACK_SIZE_PARAM_IS_A_RESERVATION;
} else {
stack_size = 0;
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index 4b701e9..7a835d7 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -18,7 +18,7 @@
#include "base/metrics/histogram.h"
#include "base/scoped_handle_win.h"
#include "base/scoped_ptr.h"
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
// userenv.dll is required for CreateEnvironmentBlock().
#pragma comment(lib, "userenv.lib")
@@ -155,7 +155,7 @@ bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) {
if (!level)
return false;
- if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA)
+ if (base::win::GetVersion() < base::win::VERSION_VISTA)
return false;
HANDLE process_token;
diff --git a/base/trace_event_win_unittest.cc b/base/trace_event_win_unittest.cc
index 7222d95..a142af1 100644
--- a/base/trace_event_win_unittest.cc
+++ b/base/trace_event_win_unittest.cc
@@ -1,13 +1,16 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+
#include "base/trace_event.h"
+
#include <strstream>
+
#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/event_trace_consumer_win.h"
#include "base/event_trace_controller_win.h"
-#include "base/win_util.h"
+#include "base/win/windows_version.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <initguid.h> // NOLINT - must be last include.
@@ -74,7 +77,7 @@ TestEventConsumer* TestEventConsumer::current_ = NULL;
class TraceEventTest: public testing::Test {
public:
void SetUp() {
- bool is_xp = win_util::GetWinVersion() < win_util::WINVERSION_VISTA;
+ bool is_xp = base::win::GetVersion() < base::win::VERSION_VISTA;
// Resurrect and initialize the TraceLog singleton instance.
// On Vista and better, we need the provider registered before we
diff --git a/base/win/windows_version.cc b/base/win/windows_version.cc
new file mode 100644
index 0000000..a80688c
--- /dev/null
+++ b/base/win/windows_version.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/win/windows_version.h"
+
+#include <windows.h>
+
+#include "base/logging.h"
+
+namespace base {
+namespace win {
+
+Version GetVersion() {
+ static bool checked_version = false;
+ static Version win_version = VERSION_PRE_2000;
+ if (!checked_version) {
+ OSVERSIONINFOEX version_info;
+ version_info.dwOSVersionInfoSize = sizeof version_info;
+ GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
+ if (version_info.dwMajorVersion == 5) {
+ switch (version_info.dwMinorVersion) {
+ case 0:
+ win_version = VERSION_2000;
+ break;
+ case 1:
+ win_version = VERSION_XP;
+ break;
+ case 2:
+ default:
+ win_version = VERSION_SERVER_2003;
+ break;
+ }
+ } else if (version_info.dwMajorVersion == 6) {
+ if (version_info.wProductType != VER_NT_WORKSTATION) {
+ // 2008 is 6.0, and 2008 R2 is 6.1.
+ win_version = VERSION_2008;
+ } else {
+ if (version_info.dwMinorVersion == 0) {
+ win_version = VERSION_VISTA;
+ } else {
+ win_version = VERSION_WIN7;
+ }
+ }
+ } else if (version_info.dwMajorVersion > 6) {
+ win_version = VERSION_WIN7;
+ }
+ checked_version = true;
+ }
+ return win_version;
+}
+
+void GetServicePackLevel(int* major, int* minor) {
+ DCHECK(major && minor);
+ static bool checked_version = false;
+ static int service_pack_major = -1;
+ static int service_pack_minor = -1;
+ if (!checked_version) {
+ OSVERSIONINFOEX version_info = {0};
+ version_info.dwOSVersionInfoSize = sizeof(version_info);
+ GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info));
+ service_pack_major = version_info.wServicePackMajor;
+ service_pack_minor = version_info.wServicePackMinor;
+ checked_version = true;
+ }
+
+ *major = service_pack_major;
+ *minor = service_pack_minor;
+}
+
+} // namespace win
+} // namespace base
diff --git a/base/win/windows_version.h b/base/win/windows_version.h
new file mode 100644
index 0000000..7e281a6
--- /dev/null
+++ b/base/win/windows_version.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_WIN_WINDOWS_VERSION_H_
+#define BASE_WIN_WINDOWS_VERSION_H_
+#pragma once
+
+namespace base {
+namespace win {
+
+// NOTE: Keep these in order so callers can do things like
+// "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values,
+// though.
+enum Version {
+ VERSION_PRE_2000 = 0, // Not supported
+ VERSION_2000 = 1, // Not supported
+ VERSION_XP = 2,
+ VERSION_SERVER_2003 = 3,
+ VERSION_VISTA = 4,
+ VERSION_2008 = 5,
+ VERSION_WIN7 = 6,
+};
+
+// Returns the running version of Windows.
+Version GetVersion();
+
+// Returns the major and minor version of the service pack installed.
+void GetServicePackLevel(int* major, int* minor);
+
+} // namespace win
+} // namespace base
+
+#endif // BASE_WIN_WINDOWS_VERSION_H_
diff --git a/base/win_util.cc b/base/win_util.cc
index b87e441..70d2829 100644
--- a/base/win_util.cc
+++ b/base/win_util.cc
@@ -5,6 +5,8 @@
#include "base/win_util.h"
#include <aclapi.h>
+#include <shobjidl.h> // Must be before propkey.
+#include <propkey.h>
#include <propvarutil.h>
#include <sddl.h>
#include <shlobj.h>
@@ -15,6 +17,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
+#include "base/win/windows_version.h"
namespace win_util {
@@ -24,15 +27,11 @@ namespace win_util {
#define NONCLIENTMETRICS_SIZE_PRE_VISTA \
SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
-const PROPERTYKEY kPKEYAppUserModelID =
- { { 0x9F4C2855, 0x9F79, 0x4B39,
- { 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, } }, 5 };
-
void GetNonClientMetrics(NONCLIENTMETRICS* metrics) {
DCHECK(metrics);
static const UINT SIZEOF_NONCLIENTMETRICS =
- (GetWinVersion() >= WINVERSION_VISTA) ?
+ (base::win::GetVersion() >= base::win::VERSION_VISTA) ?
sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
metrics->cbSize = SIZEOF_NONCLIENTMETRICS;
const bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
@@ -41,134 +40,6 @@ void GetNonClientMetrics(NONCLIENTMETRICS* metrics) {
DCHECK(success);
}
-WinVersion GetWinVersion() {
- static bool checked_version = false;
- static WinVersion win_version = WINVERSION_PRE_2000;
- if (!checked_version) {
- OSVERSIONINFOEX version_info;
- version_info.dwOSVersionInfoSize = sizeof version_info;
- GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
- if (version_info.dwMajorVersion == 5) {
- switch (version_info.dwMinorVersion) {
- case 0:
- win_version = WINVERSION_2000;
- break;
- case 1:
- win_version = WINVERSION_XP;
- break;
- case 2:
- default:
- win_version = WINVERSION_SERVER_2003;
- break;
- }
- } else if (version_info.dwMajorVersion == 6) {
- if (version_info.wProductType != VER_NT_WORKSTATION) {
- // 2008 is 6.0, and 2008 R2 is 6.1.
- win_version = WINVERSION_2008;
- } else {
- if (version_info.dwMinorVersion == 0) {
- win_version = WINVERSION_VISTA;
- } else {
- win_version = WINVERSION_WIN7;
- }
- }
- } else if (version_info.dwMajorVersion > 6) {
- win_version = WINVERSION_WIN7;
- }
- checked_version = true;
- }
- return win_version;
-}
-
-void GetServicePackLevel(int* major, int* minor) {
- DCHECK(major && minor);
- static bool checked_version = false;
- static int service_pack_major = -1;
- static int service_pack_minor = -1;
- if (!checked_version) {
- OSVERSIONINFOEX version_info = {0};
- version_info.dwOSVersionInfoSize = sizeof(version_info);
- GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info));
- service_pack_major = version_info.wServicePackMajor;
- service_pack_minor = version_info.wServicePackMinor;
- checked_version = true;
- }
-
- *major = service_pack_major;
- *minor = service_pack_minor;
-}
-
-bool AddAccessToKernelObject(HANDLE handle, WELL_KNOWN_SID_TYPE known_sid,
- ACCESS_MASK access) {
- PSECURITY_DESCRIPTOR descriptor = NULL;
- PACL old_dacl = NULL;
- PACL new_dacl = NULL;
-
- if (ERROR_SUCCESS != GetSecurityInfo(handle, SE_KERNEL_OBJECT,
- DACL_SECURITY_INFORMATION, NULL, NULL, &old_dacl, NULL,
- &descriptor))
- return false;
-
- BYTE sid[SECURITY_MAX_SID_SIZE] = {0};
- DWORD size_sid = SECURITY_MAX_SID_SIZE;
-
- if (known_sid == WinSelfSid) {
- // We hijack WinSelfSid when we want to add the current user instead of
- // a known sid.
- HANDLE token = NULL;
- if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)) {
- LocalFree(descriptor);
- return false;
- }
-
- DWORD size = sizeof(TOKEN_USER) + size_sid;
- scoped_array<BYTE> token_user_bytes(new BYTE[size]);
- TOKEN_USER* token_user =
- reinterpret_cast<TOKEN_USER*>(token_user_bytes.get());
- BOOL ret = GetTokenInformation(token, TokenUser, token_user, size, &size);
-
- CloseHandle(token);
-
- if (!ret) {
- LocalFree(descriptor);
- return false;
- }
- memcpy(sid, token_user->User.Sid, size_sid);
- } else {
- if (!CreateWellKnownSid(known_sid , NULL, sid, &size_sid)) {
- LocalFree(descriptor);
- return false;
- }
- }
-
- EXPLICIT_ACCESS new_access = {0};
- new_access.grfAccessMode = GRANT_ACCESS;
- new_access.grfAccessPermissions = access;
- new_access.grfInheritance = NO_INHERITANCE;
-
- new_access.Trustee.pMultipleTrustee = NULL;
- new_access.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
- new_access.Trustee.TrusteeForm = TRUSTEE_IS_SID;
- new_access.Trustee.ptstrName = reinterpret_cast<LPWSTR>(&sid);
-
- if (ERROR_SUCCESS != SetEntriesInAcl(1, &new_access, old_dacl, &new_dacl)) {
- LocalFree(descriptor);
- return false;
- }
-
- DWORD result = SetSecurityInfo(handle, SE_KERNEL_OBJECT,
- DACL_SECURITY_INFORMATION, NULL, NULL,
- new_dacl, NULL);
-
- LocalFree(new_dacl);
- LocalFree(descriptor);
-
- if (ERROR_SUCCESS != result)
- return false;
-
- return true;
-}
-
bool GetUserSidString(std::wstring* user_sid) {
// Get the current token.
HANDLE token = NULL;
@@ -198,62 +69,6 @@ bool GetUserSidString(std::wstring* user_sid) {
return true;
}
-bool GetLogonSessionOnlyDACL(SECURITY_DESCRIPTOR** security_descriptor) {
- // Get the current token.
- HANDLE token = NULL;
- if (!OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token))
- return false;
- ScopedHandle token_scoped(token);
-
- // Get the size of the TokenGroups structure.
- DWORD size = 0;
- BOOL result = GetTokenInformation(token, TokenGroups, NULL, 0, &size);
- if (result != FALSE && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- return false;
-
- // Get the data.
- scoped_array<char> token_groups_chars(new char[size]);
- TOKEN_GROUPS* token_groups =
- reinterpret_cast<TOKEN_GROUPS*>(token_groups_chars.get());
-
- if (!GetTokenInformation(token, TokenGroups, token_groups, size, &size))
- return false;
-
- // Look for the logon sid.
- SID* logon_sid = NULL;
- for (unsigned int i = 0; i < token_groups->GroupCount ; ++i) {
- if ((token_groups->Groups[i].Attributes & SE_GROUP_LOGON_ID) != 0) {
- logon_sid = static_cast<SID*>(token_groups->Groups[i].Sid);
- break;
- }
- }
-
- if (!logon_sid)
- return false;
-
- // Convert the data to a string.
- wchar_t* sid_string;
- if (!ConvertSidToStringSid(logon_sid, &sid_string))
- return false;
-
- static const wchar_t dacl_format[] = L"D:(A;OICI;GA;;;%ls)";
- wchar_t dacl[SECURITY_MAX_SID_SIZE + arraysize(dacl_format) + 1] = {0};
- wsprintf(dacl, dacl_format, sid_string);
-
- LocalFree(sid_string);
-
- // Convert the string to a security descriptor
- if (!ConvertStringSecurityDescriptorToSecurityDescriptor(
- dacl,
- SDDL_REVISION_1,
- reinterpret_cast<PSECURITY_DESCRIPTOR*>(security_descriptor),
- NULL)) {
- return false;
- }
-
- return true;
-}
-
#pragma warning(push)
#pragma warning(disable:4312 4244)
WNDPROC SetWindowProc(HWND hwnd, WNDPROC proc) {
@@ -276,46 +91,6 @@ void* GetWindowUserData(HWND hwnd) {
return reinterpret_cast<void*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
}
-// Maps to the WNDPROC for a window that was active before the subclass was
-// installed.
-static const wchar_t* const kHandlerKey = L"__ORIGINAL_MESSAGE_HANDLER__";
-
-bool IsSubclassed(HWND window, WNDPROC subclass_proc) {
- WNDPROC original_handler =
- reinterpret_cast<WNDPROC>(GetWindowLongPtr(window, GWLP_WNDPROC));
- return original_handler == subclass_proc;
-}
-
-bool Subclass(HWND window, WNDPROC subclass_proc) {
- WNDPROC original_handler =
- reinterpret_cast<WNDPROC>(GetWindowLongPtr(window, GWLP_WNDPROC));
- if (original_handler != subclass_proc) {
- win_util::SetWindowProc(window, subclass_proc);
- SetProp(window, kHandlerKey, original_handler);
- return true;
- }
- return false;
-}
-
-bool Unsubclass(HWND window, WNDPROC subclass_proc) {
- WNDPROC current_handler =
- reinterpret_cast<WNDPROC>(GetWindowLongPtr(window, GWLP_WNDPROC));
- if (current_handler == subclass_proc) {
- HANDLE original_handler = GetProp(window, kHandlerKey);
- if (original_handler) {
- RemoveProp(window, kHandlerKey);
- win_util::SetWindowProc(window,
- reinterpret_cast<WNDPROC>(original_handler));
- return true;
- }
- }
- return false;
-}
-
-WNDPROC GetSuperclassWNDPROC(HWND window) {
- return reinterpret_cast<WNDPROC>(GetProp(window, kHandlerKey));
-}
-
#pragma warning(pop)
bool IsShiftPressed() {
@@ -398,7 +173,7 @@ bool SetAppIdForPropertyStore(IPropertyStore* property_store,
if (FAILED(InitPropVariantFromString(app_id, &property_value)))
return false;
- HRESULT result = property_store->SetValue(kPKEYAppUserModelID,
+ HRESULT result = property_store->SetValue(PKEY_AppUserModel_ID,
property_value);
if (S_OK == result)
result = property_store->Commit();
diff --git a/base/win_util.h b/base/win_util.h
index 01372bd..18400f2 100644
--- a/base/win_util.h
+++ b/base/win_util.h
@@ -16,11 +16,22 @@ struct IPropertyStore;
struct _tagpropertykey;
typedef _tagpropertykey PROPERTYKEY;
+// TODO(brettw) remove this once RLZ is updated to use the new version in
+// base/win/windows_version.h.
+#if defined(RLZ_WIN_LIB_LIB_MUTEX_H_) || defined(RLZ_WIN_LIB_USER_KEY_H_) \
+ || defined(RLZ_WIN_LIB_PROCESS_INFO_H_)
+#include "base/win/windows_version.h"
+#endif
+
namespace win_util {
-// NOTE: Keep these in order so callers can do things like
-// "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values,
-// though.
+void GetNonClientMetrics(NONCLIENTMETRICS* metrics);
+
+// TODO(brettw) remove this once RLZ is updated to use the new version in
+// base/win/windows_version.h.
+#if defined(RLZ_WIN_LIB_LIB_MUTEX_H_) || defined(RLZ_WIN_LIB_USER_KEY_H_) \
+ || defined(RLZ_WIN_LIB_PROCESS_INFO_H_)
+// These must match the values in base::win!
enum WinVersion {
WINVERSION_PRE_2000 = 0, // Not supported
WINVERSION_2000 = 1, // Not supported
@@ -30,58 +41,17 @@ enum WinVersion {
WINVERSION_2008 = 5,
WINVERSION_WIN7 = 6,
};
-
-// Property key for System.AppUserModel.ID.
-// <http://msdn.microsoft.com/en-us/library/dd391569(VS.85).aspx>
-// TODO(xiyuan): Remove this once we compile with Win7 SDK.
-extern const PROPERTYKEY kPKEYAppUserModelID;
-
-void GetNonClientMetrics(NONCLIENTMETRICS* metrics);
-
-// Returns the running version of Windows.
-WinVersion GetWinVersion();
-
-// Returns the major and minor version of the service pack installed.
-void GetServicePackLevel(int* major, int* minor);
-
-// Adds an ACE in the DACL of the object referenced by handle. The ACE is
-// granting |access| to the user |known_sid|.
-// If |known_sid| is WinSelfSid, the sid of the current user will be added to
-// the DACL.
-bool AddAccessToKernelObject(HANDLE handle, WELL_KNOWN_SID_TYPE known_sid,
- ACCESS_MASK access);
+inline WinVersion GetWinVersion() {
+ return static_cast<WinVersion>(base::win::GetVersion());
+}
+#endif // RLZ_*
// Returns the string representing the current user sid.
bool GetUserSidString(std::wstring* user_sid);
-// Creates a security descriptor with a DACL that has one ace giving full
-// access to the current logon session.
-// The security descriptor returned must be freed using LocalFree.
-// The function returns true if it succeeds, false otherwise.
-bool GetLogonSessionOnlyDACL(SECURITY_DESCRIPTOR** security_descriptor);
-
// Useful for subclassing a HWND. Returns the previous window procedure.
WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc);
-// Returns true if the existing window procedure is the same as |subclass_proc|.
-bool IsSubclassed(HWND window, WNDPROC subclass_proc);
-
-// Subclasses a window, replacing its existing window procedure with the
-// specified one. Returns true if the current window procedure was replaced,
-// false if the window has already been subclassed with the specified
-// subclass procedure.
-bool Subclass(HWND window, WNDPROC subclass_proc);
-
-// Unsubclasses a window subclassed using Subclass. Returns true if
-// the window was subclassed with the specified |subclass_proc| and the window
-// was successfully unsubclassed, false if the window's window procedure is not
-// |subclass_proc|.
-bool Unsubclass(HWND window, WNDPROC subclass_proc);
-
-// Retrieves the original WNDPROC of a window subclassed using
-// SubclassWindow.
-WNDPROC GetSuperclassWNDPROC(HWND window);
-
// Pointer-friendly wrappers around Get/SetWindowLong(..., GWLP_USERDATA, ...)
// Returns the previously set value.
void* SetWindowUserData(HWND hwnd, void* user_data);
diff --git a/base/win_util_unittest.cc b/base/win_util_unittest.cc
index 0ff1eca..673bc84 100644
--- a/base/win_util_unittest.cc
+++ b/base/win_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,12 +7,13 @@
#include "base/basictypes.h"
#include "base/string_util.h"
#include "base/win_util.h"
+#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h"
// The test is somewhat silly, because the Vista bots some have UAC enabled
// and some have it disabled. At least we check that it does not crash.
TEST(BaseWinUtilTest, TestIsUACEnabled) {
- if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) {
+ if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
win_util::UserAccountControlIsEnabled();
} else {
EXPECT_TRUE(win_util::UserAccountControlIsEnabled());