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

Unified Diff: rlz/win/lib/process_info.cc

Issue 177843009: Make GetUserName() return more specific error code, so that we could know how the function failed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz/win/lib/process_info.cc
diff --git a/rlz/win/lib/process_info.cc b/rlz/win/lib/process_info.cc
index 2511f54ab76ab3cefb12035ba5893e8a92ee1816..d17b4feb63483f584dce664f762670633884f300 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*>(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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698