Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 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 "chrome/browser/performance_manager/mechanisms/page_freezer.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "base/task/task_traits.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
| 10 | #include "components/content_settings/core/common/content_settings_types.h" |
| 11 | #include "components/performance_manager/public/graph/page_node.h" |
| 12 | #include "components/performance_manager/public/web_contents_proxy.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 13 | #include "content/public/browser/browser_task_traits.h" |
| 14 | #include "content/public/browser/browser_thread.h" |
Illia Klimov | 57d65b8a | 2022-03-25 20:27:43 | [diff] [blame] | 15 | #include "content/public/browser/permission_controller.h" |
Charlene Yan | 753d746 | 2021-01-26 23:39:52 | [diff] [blame] | 16 | #include "content/public/browser/visibility.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 17 | #include "content/public/browser/web_contents.h" |
Andy Paicu | a6d6d85 | 2022-04-28 18:08:36 | [diff] [blame] | 18 | #include "third_party/blink/public/common/permissions/permission_utils.h" |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 19 | |
| 20 | namespace performance_manager { |
| 21 | namespace mechanism { |
| 22 | namespace { |
| 23 | |
| 24 | // Try to freeze a page on the UI thread. |
Sebastien Marchand | bed434c | 2021-03-25 19:37:24 | [diff] [blame] | 25 | void MaybeFreezePageOnUIThread(const WebContentsProxy& contents_proxy) { |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 26 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 27 | content::WebContents* const contents = contents_proxy.Get(); |
| 28 | if (!contents) |
Sebastien Marchand | bed434c | 2021-03-25 19:37:24 | [diff] [blame] | 29 | return; |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 30 | |
Illia Klimov | 57d65b8a | 2022-03-25 20:27:43 | [diff] [blame] | 31 | content::PermissionController* permission_controller = |
| 32 | contents->GetBrowserContext()->GetPermissionController(); |
Illia Klimov | 7709f0c | 2021-07-05 09:42:39 | [diff] [blame] | 33 | |
Sebastien Marchand | 578251d | 2020-12-11 03:44:43 | [diff] [blame] | 34 | // Page with the notification permission shouldn't be frozen as this is a |
| 35 | // strong signal that the user wants to receive updates from this page while |
| 36 | // it's in background. This information isn't available in the PM graph, this |
| 37 | // has to be checked on the UI thread. |
Illia Klimov | 57d65b8a | 2022-03-25 20:27:43 | [diff] [blame] | 38 | if (permission_controller->GetPermissionStatusForCurrentDocument( |
Dave Tapuska | 6aea6e2 | 2022-06-06 21:21:51 | [diff] [blame^] | 39 | blink::PermissionType::NOTIFICATIONS, |
| 40 | contents->GetPrimaryMainFrame()) == |
Illia Klimov | 57d65b8a | 2022-03-25 20:27:43 | [diff] [blame] | 41 | blink::mojom::PermissionStatus::GRANTED) { |
Sebastien Marchand | bed434c | 2021-03-25 19:37:24 | [diff] [blame] | 42 | return; |
Illia Klimov | 57d65b8a | 2022-03-25 20:27:43 | [
|