Skip to content

Commit

Permalink
Simplify WebScopedPagePauser
Browse files Browse the repository at this point in the history
Probably we can go further eliminating WebScopedPagePauser, but
let's make small changes.

Bug: 1475531
Change-Id: I5d846596c60412b10a7d0768268826a8f7ee9eb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4812768
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1188555}
  • Loading branch information
bashi authored and Chromium LUCI CQ committed Aug 25, 2023
1 parent 68e3707 commit 0541c15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
9 changes: 6 additions & 3 deletions third_party/blink/public/platform/web_scoped_page_pauser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace blink {

class ScopedBrowsingContextGroupPauser;
class ScopedPagePauser;
class WebLocalFrameImpl;

// WebScopedPagePauser implements the concept of 'pause' in HTML standard.
Expand All @@ -19,15 +21,16 @@ class WebLocalFrameImpl;
// exists.
class WebScopedPagePauser {
public:
BLINK_EXPORT static std::unique_ptr<WebScopedPagePauser> Create(
WebLocalFrameImpl&);
explicit WebScopedPagePauser(WebLocalFrameImpl&);

WebScopedPagePauser(const WebScopedPagePauser&) = delete;
WebScopedPagePauser& operator=(const WebScopedPagePauser&) = delete;
BLINK_EXPORT ~WebScopedPagePauser();

private:
explicit WebScopedPagePauser(WebLocalFrameImpl&);
std::unique_ptr<ScopedPagePauser> page_pauser_;
std::unique_ptr<ScopedBrowsingContextGroupPauser>
browsing_context_group_pauser_;
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class ClientMessageLoopAdapter : public MainThreadDebugger::ClientMessageLoop {
view->GetChromeClient().NotifyPopupOpeningObservers();

// 2. Disable active objects
page_pauser_ = WebScopedPagePauser::Create(*frame);
page_pauser_ = std::make_unique<WebScopedPagePauser>(*frame);

// 3. Process messages until quitNow is called.
message_loop_->Run();
Expand Down
43 changes: 4 additions & 39 deletions third_party/blink/renderer/core/exported/web_scoped_page_pauser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,18 @@

namespace blink {

namespace {

// Used to defer all page activity in cases where the embedder wishes to run
// a nested event loop. Using a stack enables nesting of message loop
// invocations.
Vector<std::unique_ptr<ScopedPagePauser>>& PagePauserStack() {
DEFINE_STATIC_LOCAL(Vector<std::unique_ptr<ScopedPagePauser>>, pauser_stack,
());
return pauser_stack;
}

Vector<std::unique_ptr<ScopedBrowsingContextGroupPauser>>&
BrowsingContextGroupPauserStack() {
DEFINE_STATIC_LOCAL(Vector<std::unique_ptr<ScopedBrowsingContextGroupPauser>>,
pauser_stack, ());
return pauser_stack;
}

} // namespace

// static
std::unique_ptr<WebScopedPagePauser> WebScopedPagePauser::Create(
WebLocalFrameImpl& frame) {
return std::unique_ptr<WebScopedPagePauser>(new WebScopedPagePauser(frame));
}

WebScopedPagePauser::WebScopedPagePauser(WebLocalFrameImpl& frame) {
if (base::FeatureList::IsEnabled(
features::kPausePagesPerBrowsingContextGroup)) {
Page* page = WebFrame::ToCoreFrame(frame)->GetPage();
CHECK(page);
BrowsingContextGroupPauserStack().push_back(
std::make_unique<ScopedBrowsingContextGroupPauser>(*page));
browsing_context_group_pauser_ =
std::make_unique<ScopedBrowsingContextGroupPauser>(*page);
} else {
PagePauserStack().push_back(std::make_unique<ScopedPagePauser>());
page_pauser_ = std::make_unique<ScopedPagePauser>();
}
}

WebScopedPagePauser::~WebScopedPagePauser() {
if (base::FeatureList::IsEnabled(
features::kPausePagesPerBrowsingContextGroup)) {
CHECK_NE(BrowsingContextGroupPauserStack().size(), 0u);
BrowsingContextGroupPauserStack().pop_back();
} else {
CHECK_NE(PagePauserStack().size(), 0u);
PagePauserStack().pop_back();
}
}
WebScopedPagePauser::~WebScopedPagePauser() = default;

} // namespace blink

0 comments on commit 0541c15

Please sign in to comment.