| Index: base/process/process_linux.cc
|
| diff --git a/base/process/process_linux.cc b/base/process/process_linux.cc
|
| index 2c22d26484294024453b607b689309079b46999a..0560186ecf3129f5b437d5d392445103da33dd28 100644
|
| --- a/base/process/process_linux.cc
|
| +++ b/base/process/process_linux.cc
|
| @@ -134,4 +134,63 @@ bool Process::CanBackgroundProcesses() {
|
| return check_for_nice_permission.Get().can_reraise_priority;
|
| }
|
|
|
| +// TODO(rvargas) crbug.com/417532: Remove Process::*
|
| +// -----------------------------------------------------------------------------
|
| +
|
| +// static
|
| +bool ProcessObject::CanBackgroundProcesses() {
|
| +#if defined(OS_CHROMEOS)
|
| + if (cgroups.Get().enabled)
|
| + return true;
|
| +#endif
|
| +
|
| + static LazyInstance<CheckForNicePermission> check_for_nice_permission =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| + return check_for_nice_permission.Get().can_reraise_priority;
|
| +}
|
| +
|
| +bool ProcessObject::IsProcessBackgrounded() const {
|
| + DCHECK(IsValid());
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + if (cgroups.Get().enabled) {
|
| + std::string proc;
|
| + if (base::ReadFileToString(
|
| + base::FilePath(StringPrintf(kProcPath, process_)),
|
| + &proc)) {
|
| + std::vector<std::string> proc_parts;
|
| + base::SplitString(proc, ':', &proc_parts);
|
| + DCHECK(proc_parts.size() == 3);
|
| + bool ret = proc_parts[2] == std::string(kBackground);
|
| + return ret;
|
| + } else {
|
| + return false;
|
| + }
|
| + }
|
| +#endif
|
| + return GetPriority() == kBackgroundPriority;
|
| +}
|
| +
|
| +bool ProcessObject::SetProcessBackgrounded(bool background) {
|
| + DCHECK(IsValid());
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + if (cgroups.Get().enabled) {
|
| + std::string pid = StringPrintf("%d", process_);
|
| + const base::FilePath file =
|
| + background ?
|
| + cgroups.Get().background_file : cgroups.Get().foreground_file;
|
| + return base::WriteFile(file, pid.c_str(), pid.size()) > 0;
|
| + }
|
| +#endif // OS_CHROMEOS
|
| +
|
| + if (!CanBackgroundProcesses())
|
| + return false;
|
| +
|
| + int priority = background ? kBackgroundPriority : kForegroundPriority;
|
| + int result = setpriority(PRIO_PROCESS, process_, priority);
|
| + DPCHECK(result == 0);
|
| + return result == 0;
|
| +}
|
| +
|
| } // namespace base
|
|
|