Bug 1735945 - Split unload into unload and beforeunload for BFCACHE_COMBO telemetry probe r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D128625
This commit is contained in:
Sean Feng 2021-10-18 17:31:28 +00:00
Родитель a6a4f92ea0
Коммит 3416efe3f7
7 изменённых файлов: 51 добавлений и 12 удалений

Просмотреть файл

@ -2477,8 +2477,7 @@ static void LogBFCacheBlockingForDoc(BrowsingContext* aBrowsingContext,
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * suspended Window"));
}
if (aBFCacheCombo & BFCacheStatus::UNLOAD_LISTENER) {
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug,
(" * beforeunload or unload listener"));
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * unload listener"));
}
if (aBFCacheCombo & BFCacheStatus::REQUEST) {
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * requests in the loadgroup"));
@ -2501,6 +2500,9 @@ static void LogBFCacheBlockingForDoc(BrowsingContext* aBrowsingContext,
if (aBFCacheCombo & BFCacheStatus::HAS_USED_VR) {
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * used VR"));
}
if (aBFCacheCombo & BFCacheStatus::BEFOREUNLOAD_LISTENER) {
MOZ_LOG(gSHIPBFCacheLog, LogLevel::Debug, (" * beforeunload listener"));
}
}
bool CanonicalBrowsingContext::AllowedInBFCache(

Просмотреть файл

@ -6819,6 +6819,8 @@ void nsDocShell::ReportBFCacheComboTelemetry(uint16_t aCombo) {
enum BFCacheStatusCombo : uint16_t {
BFCACHE_SUCCESS,
NOT_ONLY_TOPLEVEL = mozilla::dom::BFCacheStatus::NOT_ONLY_TOPLEVEL_IN_BCG,
// If both unload and beforeunload listeners are presented, it'll be
// recorded as unload
UNLOAD = mozilla::dom::BFCacheStatus::UNLOAD_LISTENER,
UNLOAD_REQUEST = mozilla::dom::BFCacheStatus::UNLOAD_LISTENER |
mozilla::dom::BFCacheStatus::REQUEST,
@ -6839,9 +6841,15 @@ void nsDocShell::ReportBFCacheComboTelemetry(uint16_t aCombo) {
mozilla::dom::BFCacheStatus::UNLOAD_LISTENER |
mozilla::dom::BFCacheStatus::REQUEST |
mozilla::dom::BFCacheStatus::ACTIVE_PEER_CONNECTION,
REMOTE_SUBFRAMES = mozilla::dom::BFCacheStatus::CONTAINS_REMOTE_SUBFRAMES
REMOTE_SUBFRAMES = mozilla::dom::BFCacheStatus::CONTAINS_REMOTE_SUBFRAMES,
BEFOREUNLOAD = mozilla::dom::BFCacheStatus::BEFOREUNLOAD_LISTENER,
};
// Beforeunload is recorded as a blocker only if it is the only one to block
// bfcache.
if (aCombo != mozilla::dom::BFCacheStatus::BEFOREUNLOAD_LISTENER) {
aCombo &= ~mozilla::dom::BFCacheStatus::BEFOREUNLOAD_LISTENER;
}
switch (aCombo) {
case BFCACHE_SUCCESS:
Telemetry::AccumulateCategorical(
@ -6861,6 +6869,10 @@ void nsDocShell::ReportBFCacheComboTelemetry(uint16_t aCombo) {
case UNLOAD:
Telemetry::AccumulateCategorical(Telemetry::LABELS_BFCACHE_COMBO::Unload);
break;
case BEFOREUNLOAD:
Telemetry::AccumulateCategorical(
Telemetry::LABELS_BFCACHE_COMBO::Beforeunload);
break;
case UNLOAD_REQUEST:
Telemetry::AccumulateCategorical(
Telemetry::LABELS_BFCACHE_COMBO::Unload_Req);

Просмотреть файл

@ -11060,11 +11060,19 @@ bool Document::CanSavePresentation(nsIRequest* aNewRequest,
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject);
if (!allowUnloadListeners && piTarget) {
EventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasUnloadListeners()) {
MOZ_LOG(gPageCacheLog, mozilla::LogLevel::Verbose,
("Save of %s blocked due to unload handlers", uri.get()));
aBFCacheCombo |= BFCacheStatus::UNLOAD_LISTENER;
ret = false;
if (manager) {
if (manager->HasUnloadListeners()) {
MOZ_LOG(gPageCacheLog, mozilla::LogLevel::Verbose,
("Save of %s blocked due to unload handlers", uri.get()));
aBFCacheCombo |= BFCacheStatus::UNLOAD_LISTENER;
ret = false;
}
if (manager->HasBeforeUnloadListeners()) {
MOZ_LOG(gPageCacheLog, mozilla::LogLevel::Verbose,
("Save of %s blocked due to beforeUnload handlers", uri.get()));
aBFCacheCombo |= BFCacheStatus::BEFOREUNLOAD_LISTENER;
ret = false;
}
}
}

Просмотреть файл

@ -304,6 +304,7 @@ enum BFCacheStatus {
NOT_ONLY_TOPLEVEL_IN_BCG = 1 << 12, // Status 12
ABOUT_PAGE = 1 << 13, // Status 13
RESTORING = 1 << 14, // Status 14
BEFOREUNLOAD_LISTENER = 1 << 15, // Status 15
};
} // namespace dom

Просмотреть файл

@ -1674,8 +1674,18 @@ bool EventListenerManager::HasUnloadListeners() {
uint32_t count = mListeners.Length();
for (uint32_t i = 0; i < count; ++i) {
Listener* listener = &mListeners.ElementAt(i);
if (listener->mEventMessage == eUnload ||
listener->mEventMessage == eBeforeUnload) {
if (listener->mEventMessage == eUnload) {
return true;
}
}
return false;
}
bool EventListenerManager::HasBeforeUnloadListeners() {
uint32_t count = mListeners.Length();
for (uint32_t i = 0; i < count; ++i) {
Listener* listener = &mListeners.ElementAt(i);
if (listener->mEventMessage == eBeforeUnload) {
return true;
}
}

Просмотреть файл

@ -407,11 +407,16 @@ class EventListenerManager final : public EventListenerManagerBase {
bool HasMutationListeners();
/**
* Allows us to quickly determine whether we have unload or beforeunload
* listeners registered.
* Allows us to quickly determine whether we have unload listeners registered.
*/
bool HasUnloadListeners();
/**
* Allows us to quickly determine whether we have beforeunload listeners
* registered.
*/
bool HasBeforeUnloadListeners();
/**
* Returns the mutation bits depending on which mutation listeners are
* registered to this listener manager.

Просмотреть файл

@ -15886,6 +15886,7 @@
"Unload_Req_MSE",
"SPD_Unload_Req_Peer",
"Remote_Subframes",
"Beforeunload",
"Other"
],
"description": "The common combinations of BFCacheStatus when we determine whether the page can be BFCached or not; If it's BFCached, we record BFCache_Success; Success_Not_Toplevel represents the number of not the only top level document in BrowsingContextGroup's documents that are BFCached, and BFCache_Success includes Success_Not_Toplevel; If it's not and it falls under common failure reasons combinations, we record the corresponding combination; Otherwise, we record Other to indicate this is not a common failure"