DefaultOfflineWebContentsObserver trips IsErrorPage() CHECK before the offline page commits

#575489700 CL 8746501 New / P3 / S3 / DCHECK-to-CHECK

What

When Chrome fails a primary-main-frame load with net::ERR_INTERNET_DISCONNECTED for an installed web app, ChromeContentBrowserClient::GetAlternativeErrorPageOverrideInfo registers a DefaultOfflineWebContentsObserver that is supposed to log how long the offline error page is visible. The observer is attached before the alternative error-page navigation commits in the renderer. If the WebContents is torn down, or the navigation is aborted, between registration and commit, DidFinishNavigation fires for a navigation whose IsErrorPage() is false, tripping CHECK(navigation_handle->IsErrorPage()) at chrome/browser/webapps/web_app_offline.cc:78. WebContentsDestroyed hits the same window and logs an uninitialized duration metric on the way out.

Lifecycle

The observer tracks exactly one error-page navigation, but DidFinishNavigation runs for every finished primary-main-frame navigation on the WebContents, including the aborted ones.

beforeCHECK fires on abort
load fails ERR_INTERNET_DISCONNECTED observer attached TrackOfflinePageVisibility WebContents destroyed before commit DidFinishNavigation !IsErrorPage() CHECK trips
aftermatched by navigation id
load fails ERR_INTERNET_DISCONNECTED observer attached + navigation id WebContents destroyed before commit tracked id, not committed delete this no metric, no CHECK

The fix

TrackOfflinePageVisibility now takes the NavigationHandle& and stashes its GetNavigationId() on the observer. The new DidFinishNavigation contract:

WebContentsDestroyed mirrors the same rule: if the error page never committed, delete silently instead of logging a bogus duration from an uninitialized timer_start_.

Red / green

phasebuildtestresult
red fix cherry-picked, pre-commit guard removed WebContentsDestroyedBeforeOfflinePageCommitsDoesNotCrashOrLog/0 CRASHED
green full fix applied All/WebAppOfflinePageTest.* (18 cases) 18 / 18 PASS
cq patchset 3 (BUILD.gn dep added) chromium CQ dry run 32 / 32 PASS

Crashing line

// chrome/browser/webapps/web_app_offline.cc  (pre-fix)
if (!error_page_url_.is_empty()) {
  // ... first navigation has already committed, log + exit
}

// TODO(crbug.com/575489700): CHECK-exclusion: Convert to a CHECK once we
// are confident it won't be triggered.
DCHECK(navigation_handle->IsErrorPage());   // <-- trips when aborted
CHECK(error_page_url_.is_empty(), base::NotFatalUntil::M162);
error_page_url_ = navigation_handle->GetURL();
timer_start_ = base::TimeTicks::Now();

Links

CL 8746501 · Issue 575489700 · Parent revert #575489604 · web_app_offline.cc · Prior WIP CL 8710314