From ca13fbf58d6c2bd5734bee3f66f779f45b83ec7f Mon Sep 17 00:00:00 2001 From: "yiyaoliu@chromium.org" Date: Mon, 10 Mar 2014 18:22:14 +0000 Subject: Make GetUserName() return more specific error code, so that we could know how the function failed. However, a lot user at under version 33 or lower, which means they don't auto-update Chrome? I'm not sure if this new piece of code will get to the affected users. BUG=334675 Review URL: https://codereview.chromium.org/177843009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255985 0039d316-1c4b-4281-b951-d872f2087c98 --- rlz/win/lib/process_info.cc | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/rlz/win/lib/process_info.cc b/rlz/win/lib/process_info.cc index 2511f54a..d17b4fe 100644 --- a/rlz/win/lib/process_info.cc +++ b/rlz/win/lib/process_info.cc @@ -33,8 +33,8 @@ HRESULT GetCurrentUser(std::wstring* name, // In which case, search for and use the process handle of a running // Explorer.exe.) HANDLE token; - if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) - return E_FAIL; + + CHECK(::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)); base::win::ScopedHandle scoped_process_token(token); @@ -49,13 +49,10 @@ HRESULT GetCurrentUser(std::wstring* name, CHECK(!result && err == ERROR_INSUFFICIENT_BUFFER); token_user_bytes.reset(new char[token_user_size]); - if (!token_user_bytes.get()) - return E_OUTOFMEMORY; + CHECK(token_user_bytes.get()); - if (!::GetTokenInformation(token, TokenUser, token_user_bytes.get(), - token_user_size, &token_user_size2)) { - return E_FAIL; - } + CHECK(::GetTokenInformation(token, TokenUser, token_user_bytes.get(), + token_user_size, &token_user_size2)); WCHAR user_name[UNLEN + 1]; // max username length WCHAR domain_name[UNLEN + 1]; @@ -64,13 +61,11 @@ HRESULT GetCurrentUser(std::wstring* name, SID_NAME_USE sid_type; TOKEN_USER* token_user = reinterpret_cast(token_user_bytes.get()); - if (!token_user) - return E_FAIL; + CHECK(token_user); + PSID user_sid = token_user->User.Sid; - if (!::LookupAccountSidW(NULL, user_sid, user_name, &user_name_size, - domain_name, &domain_name_size, &sid_type)) { - return E_FAIL; - } + CHECK(::LookupAccountSidW(NULL, user_sid, user_name, &user_name_size, + domain_name, &domain_name_size, &sid_type)); if (name != NULL) { *name = user_name; -- cgit v1.1