-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce per browsing context group page pauser
Existing ScopedPagePauser pauses all pages. This behavior can be problematic when a renderer process hosts two same origin tabs with different browsing context groups: If one tab pauses pages, the pages belong to the other tab are also paused unexpectedly. To avoid such situation, this CL introduces a page pauser that only pauses pages that belong to the given browsing context group. The new pauser is behind a flag and the flag is disabled by default, as we also need to update other components such as scheduler so that these are aware of per browsing context group pauser. Bug: 1475531 Change-Id: I6a7b8935bb66ccde577e856e3bdcb05e613afced Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4803088 Reviewed-by: Kentaro Hara <haraken@chromium.org> Commit-Queue: Kenichi Ishibashi <bashi@chromium.org> Cr-Commit-Position: refs/heads/main@{#1188137}
- Loading branch information
Showing
11 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
third_party/blink/renderer/core/page/scoped_browsing_context_group_pauser.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/core/page/scoped_browsing_context_group_pauser.h" | ||
|
||
#include <limits> | ||
#include <map> | ||
|
||
#include "third_party/blink/renderer/core/page/page.h" | ||
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" | ||
|
||
namespace blink { | ||
|
||
namespace { | ||
|
||
uint64_t& PausedCountPerBrowsingContextGroup( | ||
const base::UnguessableToken& token) { | ||
using BrowsingContextGroupMap = std::map<base::UnguessableToken, uint64_t>; | ||
DEFINE_STATIC_LOCAL(BrowsingContextGroupMap, counts, ()); | ||
return counts[token]; | ||
} | ||
|
||
} // namespace | ||
|
||
// static | ||
bool ScopedBrowsingContextGroupPauser::IsActive(Page& page) { | ||
return PausedCountPerBrowsingContextGroup(page.BrowsingContextGroupToken()) > | ||
0; | ||
} | ||
|
||
ScopedBrowsingContextGroupPauser::ScopedBrowsingContextGroupPauser(Page& page) | ||
: browsing_context_group_token_(page.BrowsingContextGroupToken()) { | ||
CHECK_LT(PausedCount(), std::numeric_limits<uint64_t>::max()); | ||
if (++PausedCount() > 1) { | ||
return; | ||
} | ||
|
||
SetPaused(true); | ||
} | ||
|
||
ScopedBrowsingContextGroupPauser::~ScopedBrowsingContextGroupPauser() { | ||
CHECK_GE(PausedCount(), 1u); | ||
if (--PausedCount() > 0) { | ||
return; | ||
} | ||
|
||
SetPaused(false); | ||
} | ||
|
||
uint64_t& ScopedBrowsingContextGroupPauser::PausedCount() { | ||
return PausedCountPerBrowsingContextGroup(browsing_context_group_token_); | ||
} | ||
|
||
void ScopedBrowsingContextGroupPauser::SetPaused(bool paused) { | ||
HeapVector<Member<Page>> pages(Page::OrdinaryPages()); | ||
for (const auto& page : pages) { | ||
if (page->BrowsingContextGroupToken() == browsing_context_group_token_) { | ||
page->SetPaused(paused); | ||
} | ||
} | ||
} | ||
|
||
} // namespace blink |
Oops, something went wrong.