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

Unified Diff: chrome_elf/chrome_elf_util.cc

Issue 1132473003: Cache IsNonBrowserProcess values, so we only take a loader-lock the first time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: chrome_elf/chrome_elf_util.cc
diff --git a/chrome_elf/chrome_elf_util.cc b/chrome_elf/chrome_elf_util.cc
index a547d0bda04730b73f6c50dd6bb5ed3118dda50b..b385dd0e154875f5794f0374a9156ff090f7ca8e 100644
--- a/chrome_elf/chrome_elf_util.cc
+++ b/chrome_elf/chrome_elf_util.cc
@@ -193,17 +193,23 @@ bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
}
bool IsNonBrowserProcess() {
- typedef bool (*IsSandboxedProcessFunc)();
- IsSandboxedProcessFunc is_sandboxed_process_func =
- reinterpret_cast<IsSandboxedProcessFunc>(
- GetProcAddress(GetModuleHandle(NULL), "IsSandboxedProcess"));
- bool is_sandboxed_process =
- is_sandboxed_process_func && is_sandboxed_process_func();
-
- // TODO(robertshield): Drop the command line check when we drop support for
- // enabling chrome_elf in unsandboxed processes.
- wchar_t* command_line = GetCommandLine();
- bool has_process_type_flag = command_line && wcsstr(command_line, L"--type");
-
+ static bool initialized = false;
+ // Assume a non-browser process until proven otherwise.
+ static bool is_sandboxed_process = true;
+ static bool has_process_type_flag = true;
+ if (!initialized) {
Sigurður Ásgeirsson 2015/05/08 14:36:33 This mode of initialization is not thread safe. It
grt (UTC plus 2) 2015/05/08 14:44:22 In practice, I think that the first call will be d
Sigurður Ásgeirsson 2015/05/08 16:59:42 If you can guarantee that this function is invoked
+ typedef bool (*IsSandboxedProcessFunc)();
+ IsSandboxedProcessFunc is_sandboxed_process_func =
+ reinterpret_cast<IsSandboxedProcessFunc>(
+ GetProcAddress(GetModuleHandle(NULL), "IsSandboxedProcess"));
+ is_sandboxed_process =
grt (UTC plus 2) 2015/05/08 04:44:34 if this is true, there's no need to check the comm
+ is_sandboxed_process_func && is_sandboxed_process_func();
+
+ // TODO(robertshield): Drop the command line check when we drop support for
+ // enabling chrome_elf in unsandboxed processes.
+ wchar_t* command_line = GetCommandLine();
+ has_process_type_flag = command_line && wcsstr(command_line, L"--type");
+ initialized = true;
+ }
return (has_process_type_flag || is_sandboxed_process);
}
« 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