Commit 615a9567 authored by dpapad's avatar dpapad Committed by Commit bot

Moving Windows Breakpad restart logic to lower layer.

Currently this logic needs to be copied and called every time
chrome::AttemptRestart() is called. Moving it within chrome::AttemptRestart()
allows it to be reused. Moreover, it seems that calling
chrome::AttemptRestart() without the said logic (there are such occurrences),
is not correct.

This is in preparation of reducing the number of "Restart" codepaths in MD
Settings.

BUG=617830

Review-Url: https://codereview.chromium.org/2033173002
Cr-Commit-Position: refs/heads/master@{#398195}
parent e3343a30
......@@ -6,6 +6,10 @@
#include <memory>
#if defined(OS_WIN)
#include <windows.h>
#endif
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
......@@ -47,6 +51,8 @@
#if defined(OS_WIN)
#include "base/win/win_util.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/common/chrome_constants.h"
#endif
namespace chrome {
......@@ -188,6 +194,23 @@ void AttemptUserExit() {
// The Android implementation is in application_lifetime_android.cc
#if !defined(OS_ANDROID)
void AttemptRestart() {
#if defined(OS_WIN)
// On Windows, Breakpad will upload crash reports if the breakpad pipe name
// environment variable is defined. So we undefine this environment variable
// before restarting, as the restarted processes will inherit their
// environment variables from ours, thus suppressing crash uploads.
if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) {
HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
if (exe_module) {
typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
if (clear)
clear();
}
}
#endif // defined(OS_WIN)
// TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead?
for (auto* browser : *BrowserList::GetInstance())
content::BrowserContext::SaveSessionState(browser->profile());
......@@ -210,7 +233,7 @@ void AttemptRestart() {
AttemptExit();
#endif
}
#endif
#endif // !defined(OS_ANDROID)
void AttemptExit() {
#if defined(OS_CHROMEOS)
......
......@@ -21,6 +21,10 @@ class CrashesDOMHandler;
class FlashDOMHandler;
}
namespace chrome {
void AttemptRestart();
}
namespace chrome_browser {
void SetupPreReadFieldTrial();
}
......@@ -55,10 +59,6 @@ class SafeBrowsingUIManager;
class SRTFetcher;
}
namespace settings {
class SystemHandler;
}
namespace speech {
class ChromeSpeechRecognitionManagerDelegate;
}
......@@ -76,6 +76,7 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
friend class ::FlashDOMHandler;
friend class ArcSupportHost;
friend class BrowserProcessImpl;
friend void chrome::AttemptRestart();
friend void chrome_browser::SetupPreReadFieldTrial();
friend class ChromeMetricsServicesManagerClient;
friend class ChromeRenderMessageFilter;
......@@ -97,7 +98,6 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
friend class safe_browsing::DownloadSBClient;
friend class safe_browsing::SafeBrowsingService;
friend class safe_browsing::SafeBrowsingUIManager;
friend class settings::SystemHandler;
friend void SyzyASANRegisterExperiment(const char*, const char*);
FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
......
......@@ -22,6 +22,10 @@
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#if defined(OS_WIN)
#include "components/metrics/metrics_pref_names.h"
#endif
typedef BrowserWithTestWindowTest BrowserListTest;
namespace {
......@@ -171,8 +175,11 @@ TEST_F(BrowserListTest, MAYBE_AttemptRestart) {
testing_pref_service.registry()->RegisterBooleanPref(
prefs::kWasRestarted, false);
testing_pref_service.registry()->RegisterBooleanPref(
prefs::kRestartLastSessionOnShutdown,
false);
prefs::kRestartLastSessionOnShutdown, false);
#if defined(OS_WIN)
testing_pref_service.registry()->RegisterBooleanPref(
metrics::prefs::kMetricsReportingEnabled, false);
#endif
testing_pref_service.registry()->RegisterListPref(
prefs::kProfilesLastActive);
......
......@@ -1658,23 +1658,6 @@ void BrowserOptionsHandler::HandleDefaultZoomFactor(
}
void BrowserOptionsHandler::HandleRestartBrowser(const base::ListValue* args) {
#if defined(OS_WIN)
// On Windows Breakpad will upload crash reports if the breakpad pipe name
// environment variable is defined. So we undefine this environment variable
// before restarting, as the restarted processes will inherit their
// environment variables from ours, thus suppressing crash uploads.
if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) {
HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
if (exe_module) {
typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
if (clear)
clear();
}
}
#endif
chrome::AttemptRestart();
}
......
......@@ -4,10 +4,6 @@
#include "chrome/browser/ui/webui/settings/system_handler.h"
#if defined(OS_WIN)
#include <windows.h>
#endif
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/metrics/user_metrics.h"
......@@ -19,11 +15,6 @@
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#if defined(OS_WIN)
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/common/chrome_constants.h"
#endif
namespace settings {
SystemHandler::SystemHandler() {}
......@@ -51,23 +42,6 @@ void SystemHandler::HandleChangeProxySettings(const base::ListValue* /*args*/) {
}
void SystemHandler::HandleRestartBrowser(const base::ListValue* /*args*/) {
#if defined(OS_WIN)
// On Windows Breakpad will upload crash reports if the breakpad pipe name
// environment variable is defined. So we undefine this environment variable
// before restarting, as the restarted processes will inherit their
// environment variables from ours, thus suppressing crash uploads.
if (!ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) {
HMODULE exe_module = GetModuleHandle(chrome::kBrowserProcessExecutableName);
if (exe_module) {
typedef void (__cdecl *ClearBreakpadPipeEnvVar)();
ClearBreakpadPipeEnvVar clear = reinterpret_cast<ClearBreakpadPipeEnvVar>(
GetProcAddress(exe_module, "ClearBreakpadPipeEnvironmentVariable"));
if (clear)
clear();
}
}
#endif
chrome::AttemptRestart();
}
......
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