Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [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 | |
| 5 | #include "components/performance_manager/public/freezing/freezing.h" |
| 6 | |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 7 | #include "base/check_deref.h" |
| 8 | #include "components/performance_manager/freezing/freezing_policy.h" |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [diff] [blame] | 9 | #include "components/performance_manager/public/performance_manager.h" |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [diff] [blame] | 10 | |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 11 | namespace performance_manager::freezing { |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [diff] [blame] | 12 | |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 13 | FreezingVote::FreezingVote(content::WebContents* web_contents) |
| 14 | : page_node_( |
| 15 | PerformanceManager::GetPrimaryPageNodeForWebContents(web_contents)) { |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [diff] [blame] | 16 | PerformanceManager::CallOnGraph( |
| 17 | FROM_HERE, |
| 18 | base::BindOnce( |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 19 | [](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 Marchand | d7de057 | 2021-03-09 17:10:55 | [diff] [blame] | 24 | }, |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 25 | page_node_)); |
Sebastien Marchand | 1a8a708c | 2020-12-17 16:00:18 | [diff] [blame] | 26 | } |
| 27 | |
François Doray | f0c7e07 | 2024-04-03 20:41:45 | [diff] [blame^] | 28 | FreezingVote::~FreezingVote() { |
Sebastien Marchand | d7de057 | 2021-03-09 17:10:55 | [diff] [blame] | 29 | PerformanceManager::CallOnGraph( |
|
|