OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/process/process.h" | 5 #include "base/process/process.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 | 8 |
9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
10 #include "base/mac/mach_logging.h" | 10 #include "base/mac/mach_logging.h" |
| 11 #include "base/metrics/field_trial_params.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
| 15 namespace { |
| 16 const char kAppNapFeatureParamName[] = "app_nap"; |
| 17 } |
| 18 |
14 // Enables backgrounding hidden renderers on Mac. | 19 // Enables backgrounding hidden renderers on Mac. |
15 const Feature kMacAllowBackgroundingProcesses{"MacAllowBackgroundingProcesses", | 20 const Feature kMacAllowBackgroundingProcesses{"MacAllowBackgroundingProcesses", |
16 FEATURE_DISABLED_BY_DEFAULT}; | 21 FEATURE_DISABLED_BY_DEFAULT}; |
17 | 22 |
| 23 bool Process::IsAppNapEnabled() { |
| 24 return !base::GetFieldTrialParamValueByFeature( |
| 25 kMacAllowBackgroundingProcesses, kAppNapFeatureParamName) |
| 26 .empty(); |
| 27 } |
| 28 |
18 bool Process::CanBackgroundProcesses() { | 29 bool Process::CanBackgroundProcesses() { |
19 return FeatureList::IsEnabled(kMacAllowBackgroundingProcesses); | 30 return FeatureList::IsEnabled(kMacAllowBackgroundingProcesses) && |
| 31 !IsAppNapEnabled(); |
20 } | 32 } |
21 | 33 |
22 bool Process::IsProcessBackgrounded(PortProvider* port_provider) const { | 34 bool Process::IsProcessBackgrounded(PortProvider* port_provider) const { |
23 DCHECK(IsValid()); | 35 DCHECK(IsValid()); |
24 if (port_provider == nullptr || !CanBackgroundProcesses()) | 36 if (port_provider == nullptr || !CanBackgroundProcesses()) |
25 return false; | 37 return false; |
26 | 38 |
27 mach_port_t task_port = port_provider->TaskForPid(Pid()); | 39 mach_port_t task_port = port_provider->TaskForPid(Pid()); |
28 if (task_port == TASK_NULL) | 40 if (task_port == TASK_NULL) |
29 return false; | 41 return false; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 TASK_QOS_POLICY_COUNT); | 93 TASK_QOS_POLICY_COUNT); |
82 if (result != KERN_SUCCESS) { | 94 if (result != KERN_SUCCESS) { |
83 MACH_LOG(ERROR, result) << "task_policy_set TASK_OVERRIDE_QOS_POLICY"; | 95 MACH_LOG(ERROR, result) << "task_policy_set TASK_OVERRIDE_QOS_POLICY"; |
84 return false; | 96 return false; |
85 } | 97 } |
86 | 98 |
87 return true; | 99 return true; |
88 } | 100 } |
89 | 101 |
90 } // namespace base | 102 } // namespace base |
OLD | NEW |