Commit ce899b33 authored by Yusuf Sengul's avatar Yusuf Sengul Committed by Commit Bot

Move crash reporting initialization into DllGetClassObject

Bug: 1036084
Change-Id: If87438015293fcdcfa22eb1d1ccc2c2563884bcd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1981118Reviewed-by: default avatarTien Mai <tienmai@chromium.org>
Commit-Queue: Yusuf Sengul <yusufsn@google.com>
Cr-Commit-Position: refs/heads/master@{#728254}
parent 51802238
......@@ -74,6 +74,8 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
return E_NOTIMPL;
}
_AtlModule.InitializeCrashReporting();
HRESULT hr = _AtlModule.DllGetClassObject(rclsid, riid, ppv);
// Start refreshing token handle validity as soon as possible so that when
......@@ -154,6 +156,9 @@ void CALLBACK SaveAccountInfoW(HWND /*hwnd*/,
wchar_t* /*pszCmdLine*/,
int /*show*/) {
LOGFN(INFO);
_AtlModule.InitializeCrashReporting();
HANDLE hStdin = ::GetStdHandle(STD_INPUT_HANDLE); // No need to close.
if (hStdin == INVALID_HANDLE_VALUE) {
LOGFN(INFO) << "No stdin";
......
......@@ -20,6 +20,8 @@
#include "chrome/credential_provider/gaiacp/gcp_crash_reporting.h"
#include "chrome/credential_provider/gaiacp/grit/gaia_static_resources.h"
#include "chrome/credential_provider/gaiacp/logging.h"
#include "chrome/credential_provider/gaiacp/mdm_utils.h"
#include "chrome/credential_provider/gaiacp/reg_utils.h"
#include "components/crash/content/app/crash_switches.h"
#include "content/public/common/content_switches.h"
......@@ -83,6 +85,25 @@ void CGaiaCredentialProviderModule::RefreshTokenHandleValidity() {
}
}
void CGaiaCredentialProviderModule::InitializeCrashReporting() {
// Perform a thread unsafe check to see whether crash reporting is
// initialized. Thread safe check is performed right before initializing crash
// reporting.
if (GetGlobalFlagOrDefault(kRegInitializeCrashReporting, 1) &&
!crashpad_initialized_) {
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (!base::EndsWith(cmd_line->GetProgram().value(), L"gcp_unittests.exe",
base::CompareCase::INSENSITIVE_ASCII) &&
cmd_line->GetSwitchValueASCII(switches::kProcessType) !=
crash_reporter::switches::kCrashpadHandler &&
::InterlockedCompareExchange(&crashpad_initialized_, 1, 0) == 0) {
ConfigureGcpCrashReporting(*cmd_line);
LOGFN(INFO) << "Crash reporting was initialized.";
}
}
}
BOOL CGaiaCredentialProviderModule::DllMain(HINSTANCE /*hinstance*/,
DWORD reason,
LPVOID reserved) {
......@@ -105,18 +126,6 @@ BOOL CGaiaCredentialProviderModule::DllMain(HINSTANCE /*hinstance*/,
false); // Enable tickcount.
logging::SetEventSource("GCPW", GCPW_CATEGORY, MSG_LOG_MESSAGE);
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
// Don't start the crash handler if the DLL is being loaded in unit
// tests. It is possible that the DLL will be loaded by other executables
// including gcp_setup.exe, LogonUI.exe, rundll32.exe.
if (!base::EndsWith(cmd_line->GetProgram().value(), L"gcp_unittests.exe",
base::CompareCase::INSENSITIVE_ASCII) &&
cmd_line->GetSwitchValueASCII(switches::kProcessType) !=
crash_reporter::switches::kCrashpadHandler) {
credential_provider::ConfigureGcpCrashReporting(*cmd_line);
}
LOGFN(INFO) << "DllMain(DLL_PROCESS_ATTACH) Build: "
<< base::win::OSInfo::GetInstance()->Kernel32BaseVersion()
<< " Version:" << GetWindowsVersion();
......
......@@ -43,10 +43,15 @@ class CGaiaCredentialProviderModule
// validity is up to date.
void RefreshTokenHandleValidity();
// Initializes the crash reporting for the module. Initialization happens only
// once even if the function is called multiple times.
void InitializeCrashReporting();
private:
std::unique_ptr<base::AtExitManager> exit_manager_;
bool is_testing_ = false;
bool token_handle_validity_refreshed_ = false;
volatile long crashpad_initialized_ = 0;
};
} // namespace credential_provider
......
......@@ -30,6 +30,7 @@
namespace credential_provider {
constexpr wchar_t kRegInitializeCrashReporting[] = L"init_crash_reporting";
constexpr wchar_t kRegMdmUrl[] = L"mdm";
constexpr wchar_t kRegMdmEnableForcePasswordReset[] =
L"mdm_enable_force_password";
......
......@@ -17,6 +17,9 @@ namespace credential_provider {
// Mdm registry value key name.
// Determines if crash reporting is initialized for credential provider DLL.
extern const wchar_t kRegInitializeCrashReporting[];
// The url used to register the machine to MDM. If specified and non-empty
// additional user access restrictions will be applied to users associated
// to GCPW that have invalid token handles.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment