Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
François Doray | 9a27b01b | 2024-03-12 22:23:21 | [diff] [blame] | 5 | #include "components/performance_manager/freezing/freezer.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 6 | |
Avi Drissman | 9269d4ed | 2023-01-07 01:38:06 | [diff] [blame] | 7 | #include "base/functional/bind.h" |
Joe Mason | 6bd35761 | 2024-06-04 22:05:55 | [diff] [blame] | 8 | #include "base/memory/weak_ptr.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 9 | #include "base/task/task_traits.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 10 | #include "components/performance_manager/public/graph/page_node.h" |
Charlene Yan | 753d746 | 2021-01-26 23:39:52 | [diff] [blame] | 11 | #include "content/public/browser/visibility.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 12 | #include "content/public/browser/web_contents.h" |
| 13 | |
| 14 | namespace performance_manager { |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 15 | |
Patrick Monette | 48df50471 | 2025-02-21 14:47:23 | [diff] [blame] | 16 | void Freezer::MaybeFreezePageNode(const PageNode* page_node) { |
| 17 | DCHECK(page_node); |
| 18 | |
| 19 | base::WeakPtr<content::WebContents> contents = page_node->GetWebContents(); |
| 20 | CHECK(contents); |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 21 | |
Dave Tapuska | 7e8c023b | 2023-11-09 02:09:08 | [diff] [blame] | 22 | // A visible page should not be frozen. |
| 23 | if (contents->GetVisibility() == content::Visibility::VISIBLE) { |
| 24 | return; |
| 25 | } |
| 26 | |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 27 | contents->SetPageFrozen(true); |
| 28 | } |
| 29 | |
Patrick Monette | 48df50471 | 2025-02-21 14:47:23 | [diff] [blame] | 30 | void Freezer::UnfreezePageNode(const PageNode* page_node) { |
| 31 | DCHECK(page_node); |
| 32 | |
| 33 | base::WeakPtr<content::WebContents> contents = page_node->GetWebContents(); |
| 34 | CHECK(contents); |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 35 | |
Charlene Yan | 753d746 | 2021-01-26 23:39:52 | [diff] [blame] | 36 | // A visible page is automatically unfrozen. |
Joe Mason | 6bd35761 | 2024-06-04 22:05:55 | [diff] [blame] | 37 | if (contents->GetVisibility() == content::Visibility::VISIBLE) { |
Charlene Yan | 753d746 | 2021-01-26 23:39:52 | [diff] [blame] | 38 | return; |
François Doray | daea98c | 2024-02-22 17:09:29 | [diff] [blame] | 39 | } |
Charlene Yan | 753d746 | 2021-01-26 23:39:52 | [diff] [blame] | 40 | |
Joe Mason | 6bd35761 | 2024-06-04 22:05:55 | [diff] [blame] | 41 | contents->SetPageFrozen(false); |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 42 | } |
| 43 | |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 44 | } // namespace performance_manager |