blob: ee17cad26a34fd45dec5dbe648d2c1358f84f8a1 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2020 The Chromium Authors
Sebastien Marchand1a8a708c2020-12-17 16:00:182// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "components/performance_manager/public/freezing/freezing.h"
6
François Dorayf0c7e072024-04-03 20:41:457#include "base/check_deref.h"
8#include "components/performance_manager/freezing/freezing_policy.h"
Sebastien Marchand1a8a708c2020-12-17 16:00:189#include "components/performance_manager/public/performance_manager.h"
Sebastien Marchand1a8a708c2020-12-17 16:00:1810
François Dorayf0c7e072024-04-03 20:41:4511namespace performance_manager::freezing {
Sebastien Marchand1a8a708c2020-12-17 16:00:1812
François Dorayf0c7e072024-04-03 20:41:4513FreezingVote::FreezingVote(content::WebContents* web_contents)
14 : page_node_(
15 PerformanceManager::GetPrimaryPageNodeForWebContents(web_contents)) {
Sebastien Marchand1a8a708c2020-12-17 16:00:1816 PerformanceManager::CallOnGraph(
17 FROM_HERE,
18 base::BindOnce(
François Dorayf0c7e072024-04-03 20:41:4519 [](base::WeakPtr<PageNode> page_node, Graph* graph) {
20 CHECK(page_node);
21 // Balanced with `RemoveFreezeVote()` in destructor.
22 CHECK_DEREF(graph->GetRegisteredObjectAs<FreezingPolicy>())
23 .AddFreezeVote(page_node.get());
Sebastien Marchandd7de0572021-03-09 17:10:5524 },
François Dorayf0c7e072024-04-03 20:41:4525 page_node_));
Sebastien Marchand1a8a708c2020-12-17 16:00:1826}
27
François Dorayf0c7e072024-04-03 20:41:4528FreezingVote::~FreezingVote() {
Sebastien Marchandd7de0572021-03-09 17:10:5529 PerformanceManager::CallOnGraph(