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

Unified Diff: chrome_elf/chrome_elf_util.cc

Issue 154653002: Breakpad coverage for chrome_elf start up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use Environment Vars to get program dir 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
Index: chrome_elf/chrome_elf_util.cc
diff --git a/chrome_elf/chrome_elf_util.cc b/chrome_elf/chrome_elf_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cba0f09171976a6d5140412541eff20dfc5406a5
--- /dev/null
+++ b/chrome_elf/chrome_elf_util.cc
@@ -0,0 +1,135 @@
+// Copyright 2014 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 "chrome_elf/chrome_elf_util.h"
+
+#include "base/strings/string16.h"
+
+namespace {
+
+const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
+const wchar_t kRegPathClientStateMedium[] =
+ L"Software\\Google\\Update\\ClientStateMedium";
+const wchar_t kRegValueUsageStats[] = L"usagestats";
+const wchar_t kUninstallArgumentsField[] = L"UninstallArguments";
+
+
grt (UTC plus 2) 2014/02/13 03:58:26 nit: remove extra newline
Cait (Slow) 2014/02/14 01:17:02 Done.
+const wchar_t kAppGuidCanary[] =
+ L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}";
+const wchar_t kAppGuidGoogleChrome[] =
+ L"{8A69D345-D564-463c-AFF1-A69D9E530F96}";
+const wchar_t kAppGuidGoogleBinaries[] =
+ L"{4DC8B4CA-1BDA-483e-B5FA-D3C12E15B62D}";
+
+bool ReadKeyValueString(bool system_install, const wchar_t* key_path,
+ const wchar_t* guid, const wchar_t* value_to_read,
+ base::string16* value_out) {
+ HKEY h_key = NULL;
+ *value_out = base::string16();
grt (UTC plus 2) 2014/02/13 03:58:26 value_out->clear();
Cait (Slow) 2014/02/14 01:17:02 Done.
+
+ base::string16 full_key_path(key_path);
+ full_key_path.append(1, L'\\');
+ full_key_path.append(guid);
+
+ if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/13 03:58:26 nit: space before ?
Cait (Slow) 2014/02/14 01:17:02 Done.
+ full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) {
grt (UTC plus 2) 2014/02/13 03:58:26 use the KEY_WOW64_32KEY flag here and on line 64 (
Cait (Slow) 2014/02/14 01:17:02 Done.
+ return false;
+ }
+
+ const size_t kMaxStringLength = 1024;
+ wchar_t raw_value[kMaxStringLength] = {};
+ DWORD size = sizeof(raw_value);
+ DWORD type = REG_SZ;
+ LONG result = ::RegQueryValueEx(h_key, value_to_read, 0, &type,
grt (UTC plus 2) 2014/02/13 03:58:26 this isn't guaranteed to return a null-terminated
Cait (Slow) 2014/02/14 01:17:02 Done.
+ reinterpret_cast<LPBYTE>(raw_value), &size);
+ *value_out = raw_value;
+
+ ::RegCloseKey(h_key);
+
+ return ERROR_SUCCESS == result;
grt (UTC plus 2) 2014/02/13 03:58:26 chromium style puts the constant after the variabl
Cait (Slow) 2014/02/14 01:17:02 Done.
grt (UTC plus 2) 2014/02/14 16:37:31 Really? ;-)
+}
+
+bool ReadKeyValueDW(bool system_install, const wchar_t* key_path,
+ base::string16 guid, const wchar_t* value_to_read,
+ DWORD* value_out) {
+ HKEY h_key = NULL;;
grt (UTC plus 2) 2014/02/13 03:58:26 nit: remove extra ;
Cait (Slow) 2014/02/14 01:17:02 Done.
+ *value_out = 0;
+
+ base::string16 full_key_path(key_path);
+ full_key_path.append(1, L'\\');
+ full_key_path.append(guid.c_str());
grt (UTC plus 2) 2014/02/13 03:58:26 remove .c_str()
Cait (Slow) 2014/02/14 01:17:02 Done.
+
+ if (::RegOpenKeyEx(system_install? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
grt (UTC plus 2) 2014/02/13 03:58:26 nit: space before ?
Cait (Slow) 2014/02/14 01:17:02 Done.
+ full_key_path.c_str(), 0, KEY_QUERY_VALUE, &h_key) != ERROR_SUCCESS) {
+ return false;
+ }
+
+ DWORD size = sizeof(DWORD);
+ DWORD type = REG_DWORD;
+ LONG result = ::RegQueryValueEx(h_key, value_to_read, 0, &type,
+ reinterpret_cast<BYTE*>(value_out), &size);
+
+ ::RegCloseKey(h_key);
+
+ return ERROR_SUCCESS == result;
grt (UTC plus 2) 2014/02/13 03:58:26 see above
Cait (Slow) 2014/02/14 01:17:02 Done.
grt (UTC plus 2) 2014/02/14 16:37:31 More doing?
+}
+
+} // namespace
+
+bool IsCanary(wchar_t* exe_path) {
+ return wcsstr(exe_path, L"Google\\Chrome SxS") != NULL;
grt (UTC plus 2) 2014/02/13 03:58:26 i think chrome looks for "Chrome SxS\\Application"
Cait (Slow) 2014/02/14 01:17:02 Done.
+}
+
+bool IsSystemInstall(wchar_t* exe_path) {
+ wchar_t program_dir[MAX_PATH] = {};
+ DWORD ret = ::GetEnvironmentVariable(L"PROGRAMFILES", program_dir, MAX_PATH);
grt (UTC plus 2) 2014/02/13 03:58:26 MAX_PATH -> arraysize(program_dir) here and below
Cait (Slow) 2014/02/14 01:17:02 Done.
+ if (ret!=0 && ret<=MAX_PATH && wcsncmp(exe_path, program_dir, ret) == 0)
grt (UTC plus 2) 2014/02/13 03:58:26 whitespace around operators simplify zero tests re
Cait (Slow) 2014/02/14 01:17:02 Done.
+ return true;
+
+ ret = ::GetEnvironmentVariable(L"PROGRAMFILES(X86)", program_dir, MAX_PATH);
+ if (ret!=0 && ret<=MAX_PATH && wcsncmp(exe_path, program_dir, ret) == 0)
+ return true;
+
+ return false;
+}
+
+bool IsMultiInstall(wchar_t* exe_path) {
+ base::string16 args;
+ if (ERROR_SUCCESS != ReadKeyValueString(IsSystemInstall(exe_path),
grt (UTC plus 2) 2014/02/13 03:58:26 ReadKeyValueString returns bool: if (!ReadKeyVal
Cait (Slow) 2014/02/14 01:17:02 Done.
+ kRegPathClientState, kAppGuidGoogleChrome, kUninstallArgumentsField,
+ &args)) {
+ return false;
+ }
+ return wcsstr(args.c_str(), L"--multi-install") != NULL;
grt (UTC plus 2) 2014/02/13 03:58:26 return args.find(L"--multi-install") != base::stri
Cait (Slow) 2014/02/14 01:17:02 Done.
+}
+
+bool AreUsageStatsEnabled() {
+#if !defined(GOOGLE_CHROME_BUILD)
+ return false;
+#else
+ wchar_t exe_path[MAX_PATH] = {};
+ if (!GetModuleFileNameW(NULL, exe_path, MAX_PATH))
grt (UTC plus 2) 2014/02/13 03:58:26 MAX_PATH -> arraysize(exe_path)
Cait (Slow) 2014/02/14 01:17:02 Done.
+ return false;
+
+ bool system_install = IsSystemInstall(exe_path);
+ base::string16 app_guid;
+
+ if (IsCanary(exe_path)) {
+ app_guid = kAppGuidCanary;
+ } else {
+ app_guid = IsMultiInstall(exe_path)? kAppGuidGoogleBinaries :
grt (UTC plus 2) 2014/02/13 03:58:26 nit: space before ?
Cait (Slow) 2014/02/14 01:17:02 Done.
+ kAppGuidGoogleChrome;
+ }
+
+ DWORD out_value = 0;
+ if (system_install && ReadKeyValueDW(system_install,
+ kRegPathClientStateMedium, app_guid, kRegValueUsageStats,
+ &out_value)) {
+ return out_value == 1;
+ }
+
+ return ReadKeyValueDW(system_install, kRegPathClientState,
+ app_guid, kRegValueUsageStats, &out_value) && out_value == 1;
+#endif // defined(GOOGLE_CHROME_BUILD)
+}

Powered by Google App Engine
This is Rietveld 408576698