blob: 14d785b302bbb5f8a09441b6e55869421ba4d446 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Sebastien Marchand578251d2020-12-11 03:44:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
François Doray9a27b01b2024-03-12 22:23:215#include "components/performance_manager/freezing/freezer.h"
Sebastien Marchand578251d2020-12-11 03:44:436
Avi Drissman9269d4ed2023-01-07 01:38:067#include "base/functional/bind.h"
Joe Mason6bd357612024-06-04 22:05:558#include "base/memory/weak_ptr.h"
Sebastien Marchand578251d2020-12-11 03:44:439#include "base/task/task_traits.h"
Sebastien Marchand578251d2020-12-11 03:44:4310#include "components/performance_manager/public/graph/page_node.h"
Charlene Yan753d7462021-01-26 23:39:5211#include "content/public/browser/visibility.h"
Sebastien Marchand578251d2020-12-11 03:44:4312#include "content/public/browser/web_contents.h"
13
14namespace performance_manager {
Sebastien Marchand578251d2020-12-11 03:44:4315
Patrick Monette48df504712025-02-21 14:47:2316void Freezer::MaybeFreezePageNode(const PageNode* page_node) {
17 DCHECK(page_node);
18
19 base::WeakPtr<content::WebContents> contents = page_node->GetWebContents();
20 CHECK(contents);
Sebastien Marchand578251d2020-12-11 03:44:4321
Dave Tapuska7e8c023b2023-11-09 02:09:0822 // A visible page should not be frozen.
23 if (contents->GetVisibility() == content::Visibility::VISIBLE) {
24 return;
25 }
26
Sebastien Marchand578251d2020-12-11 03:44:4327 contents->SetPageFrozen(true);
28}
29
Patrick Monette48df504712025-02-21 14:47:2330void Freezer::UnfreezePageNode(const PageNode* page_node) {
31 DCHECK(page_node);
32
33 base::WeakPtr<content::WebContents> contents = page_node->GetWebContents();
34 CHECK(contents);
Sebastien Marchand578251d2020-12-11 03:44:4335
Charlene Yan753d7462021-01-26 23:39:5236 // A visible page is automatically unfrozen.
Joe Mason6bd357612024-06-04 22:05:5537 if (contents->GetVisibility() == content::Visibility::VISIBLE) {
Charlene Yan753d7462021-01-26 23:39:5238 return;
François Doraydaea98c2024-02-22 17:09:2939 }
Charlene Yan753d7462021-01-26 23:39:5240
Joe Mason6bd357612024-06-04 22:05:5541 contents->SetPageFrozen(false);
Sebastien Marchand578251d2020-12-11 03:44:4342}
43
Sebastien Marchand578251d2020-12-11 03:44:4344} // namespace performance_manager