0

[Mac Window Occlusion] Check for occlusion code outside main process

The occlusion checker should only run in the main browser process.
This cl adds some checks to make sure that's true. These checks will
eventually be removed.

Bug: 1276322

LOW_COVERAGE_REASON=Adding diagnostics that will be removed in the near future.

Change-Id: I4f28c3e265d6d1cc8ad055beab3291ef74ce3085
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3905713
Commit-Queue: Jayson Adams <shrike@chromium.org>
Reviewed-by: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1050333}
This commit is contained in:
Jayson Adams
2022-09-22 19:35:19 +00:00
committed by Chromium LUCI CQ
parent 2326e8f0fa
commit 516efd7a90

@ -7,6 +7,8 @@
#include <memory>
#include "base/auto_reset.h"
#include "base/debug/crash_logging.h"
#include "base/debug/dump_without_crashing.h"
#include "base/feature_list.h"
#import "base/mac/foundation_util.h"
#import "base/mac/scoped_nsobject.h"
@ -31,6 +33,12 @@ NSString* const kWindowDidChangePositionInWindowList =
@"ChromeWindowDidChangePositionInWindowList";
NSString* const kWindowIsOccludedKey = @"ChromeWindowIsOccludedKey";
bool IsBrowserProcess() {
return base::CommandLine::ForCurrentProcess()
->GetSwitchValueASCII("type")
.empty();
}
} // namespace
@interface WebContentsOcclusionCheckerMac () {
@ -65,6 +73,11 @@ NSString* const kWindowIsOccludedKey = @"ChromeWindowIsOccludedKey";
[self sharedOcclusionChecker];
if (sharedInstance->get() == nil) {
sharedInstance->reset([[self alloc] init]);
// Checking if occlusion tracking is the cause of crashes in utility
// processes (and how that's possible). See https://crbug.com/1276322 .
if (!IsBrowserProcess())
base::debug::DumpWithoutCrashing();
}
return sharedInstance->get();
}
@ -77,6 +90,13 @@ NSString* const kWindowIsOccludedKey = @"ChromeWindowIsOccludedKey";
self = [super init];
DCHECK(base::FeatureList::IsEnabled(kMacWebContentsOcclusion));
DCHECK(IsBrowserProcess());
if (!IsBrowserProcess()) {
static auto* const crash_key = base::debug::AllocateCrashKeyString(
"MacWebContentsOcclusionChecker", base::debug::CrashKeySize::Size32);
base::debug::SetCrashKeyString(crash_key, "initialized");
}
[self setUpNotifications];
// There's no notification for NSWindows changing their order in the window