Skip to content

Commit

Permalink
Cache IsNonBrowserProcess values, so we only take a loader-lock the f…
Browse files Browse the repository at this point in the history
…irst time.

BUG=485656,477137

Review URL: https://codereview.chromium.org/1132473003

Cr-Commit-Position: refs/heads/master@{#329246}
  • Loading branch information
caitkp authored and Commit bot committed May 11, 2015
1 parent 1912f4a commit 78d41b5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
2 changes: 2 additions & 0 deletions chrome_elf/blacklist/test/blacklist_test_main_dll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include <windows.h>

#include "chrome_elf/blacklist/blacklist.h"
#include "chrome_elf/chrome_elf_util.h"

extern "C" void InitBlacklistTestDll() {}

BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
if (reason == DLL_PROCESS_ATTACH) {
InitializeProcessType();
blacklist::Initialize(true); // force always on, no beacon
}

Expand Down
2 changes: 2 additions & 0 deletions chrome_elf/chrome_elf_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "chrome_elf/blacklist/blacklist.h"
#include "chrome_elf/breakpad.h"
#include "chrome_elf/chrome_elf_util.h"
#include "chrome_elf/ntdll_cache.h"

void SignalChromeElf() {
Expand All @@ -19,6 +20,7 @@ BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
InitializeCrashReporting();

__try {
InitializeProcessType();
InitCache();
blacklist::Initialize(false); // Don't force, abort if beacon is present.
} __except(GenerateCrashDump(GetExceptionInformation())) {
Expand Down
28 changes: 20 additions & 8 deletions chrome_elf/chrome_elf_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

#include "chrome_elf/chrome_elf_util.h"

#include <assert.h>
#include <windows.h>

#include "base/macros.h"
#include "base/strings/string16.h"

ProcessType g_process_type = ProcessType::UNINITIALIZED;

namespace {

const wchar_t kRegPathClientState[] = L"Software\\Google\\Update\\ClientState";
Expand Down Expand Up @@ -192,18 +195,27 @@ bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
return false;
}

bool IsNonBrowserProcess() {
void InitializeProcessType() {
assert(g_process_type == UNINITIALIZED);
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();
if (is_sandboxed_process_func && is_sandboxed_process_func()) {
g_process_type = NON_BROWSER_PROCESS;
return;
}

// 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");
const wchar_t* command_line = GetCommandLine();
if (command_line && wcsstr(command_line, L"--type")) {
g_process_type = NON_BROWSER_PROCESS;
return;
}

return (has_process_type_flag || is_sandboxed_process);
g_process_type = BROWSER_PROCESS;
}

bool IsNonBrowserProcess() {
assert(g_process_type != UNINITIALIZED);
return g_process_type == NON_BROWSER_PROCESS;
}
12 changes: 12 additions & 0 deletions chrome_elf/chrome_elf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

#include "base/strings/string16.h"

enum ProcessType {
UNINITIALIZED,
NON_BROWSER_PROCESS,
BROWSER_PROCESS,
};

// Returns true if |exe_path| points to a Chrome installed in an SxS
// installation.
bool IsCanary(const wchar_t* exe_path);
Expand All @@ -24,8 +30,14 @@ bool AreUsageStatsEnabled(const wchar_t* exe_path);
// if stats collecting is permitted by this policy and false if not.
bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);

// Initializes |g_process_type| which stores whether or not the current process
// is the main browser process.
void InitializeProcessType();

// Returns true if invoked in a Chrome process other than the main browser
// process. False otherwise.
bool IsNonBrowserProcess();

extern ProcessType g_process_type;

#endif // CHROME_ELF_CHROME_ELF_UTIL_H_
6 changes: 6 additions & 0 deletions chrome_elf/chrome_elf_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ TEST(ChromeElfUtilTest, SystemInstallTest) {
EXPECT_FALSE(IsSystemInstall(kChromeUserExePath));
}

TEST(ChromeElfUtilTest, BrowserProcessTest) {
EXPECT_TRUE(g_process_type == ProcessType::UNINITIALIZED);
InitializeProcessType();
EXPECT_FALSE(IsNonBrowserProcess());
}

// Parameterized test with paramters:
// 1: product: "canary" or "google"
// 2: install level: "user" or "system"
Expand Down

0 comments on commit 78d41b5

Please sign in to comment.