OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <errno.h> | 7 #include <errno.h> |
8 #include <sys/resource.h> | 8 #include <sys/resource.h> |
9 | 9 |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 base::FileSystemType foreground_type; | 55 base::FileSystemType foreground_type; |
56 base::FileSystemType background_type; | 56 base::FileSystemType background_type; |
57 enabled = | 57 enabled = |
58 base::GetFileSystemType(foreground_file, &foreground_type) && | 58 base::GetFileSystemType(foreground_file, &foreground_type) && |
59 base::GetFileSystemType(background_file, &background_type) && | 59 base::GetFileSystemType(background_file, &background_type) && |
60 foreground_type == FILE_SYSTEM_CGROUP && | 60 foreground_type == FILE_SYSTEM_CGROUP && |
61 background_type == FILE_SYSTEM_CGROUP; | 61 background_type == FILE_SYSTEM_CGROUP; |
62 } | 62 } |
63 }; | 63 }; |
64 | 64 |
65 base::LazyInstance<CGroups> g_cgroups = LAZY_INSTANCE_INITIALIZER; | 65 base::LazyInstance<CGroups>::DestructorAtExit g_cgroups = |
| 66 LAZY_INSTANCE_INITIALIZER; |
66 #else | 67 #else |
67 const int kBackgroundPriority = 5; | 68 const int kBackgroundPriority = 5; |
68 #endif // defined(OS_CHROMEOS) | 69 #endif // defined(OS_CHROMEOS) |
69 | 70 |
70 struct CheckForNicePermission { | 71 struct CheckForNicePermission { |
71 CheckForNicePermission() : can_reraise_priority(false) { | 72 CheckForNicePermission() : can_reraise_priority(false) { |
72 // We won't be able to raise the priority if we don't have the right rlimit. | 73 // We won't be able to raise the priority if we don't have the right rlimit. |
73 // The limit may be adjusted in /etc/security/limits.conf for PAM systems. | 74 // The limit may be adjusted in /etc/security/limits.conf for PAM systems. |
74 struct rlimit rlim; | 75 struct rlimit rlim; |
75 if ((getrlimit(RLIMIT_NICE, &rlim) == 0) && | 76 if ((getrlimit(RLIMIT_NICE, &rlim) == 0) && |
76 (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) { | 77 (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) { |
77 can_reraise_priority = true; | 78 can_reraise_priority = true; |
78 } | 79 } |
79 }; | 80 }; |
80 | 81 |
81 bool can_reraise_priority; | 82 bool can_reraise_priority; |
82 }; | 83 }; |
83 | 84 |
84 } // namespace | 85 } // namespace |
85 | 86 |
86 // static | 87 // static |
87 bool Process::CanBackgroundProcesses() { | 88 bool Process::CanBackgroundProcesses() { |
88 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
89 if (g_cgroups.Get().enabled) | 90 if (g_cgroups.Get().enabled) |
90 return true; | 91 return true; |
91 #endif // defined(OS_CHROMEOS) | 92 #endif // defined(OS_CHROMEOS) |
92 | 93 |
93 static LazyInstance<CheckForNicePermission> check_for_nice_permission = | 94 static LazyInstance<CheckForNicePermission>::DestructorAtExit |
94 LAZY_INSTANCE_INITIALIZER; | 95 check_for_nice_permission = LAZY_INSTANCE_INITIALIZER; |
95 return check_for_nice_permission.Get().can_reraise_priority; | 96 return check_for_nice_permission.Get().can_reraise_priority; |
96 } | 97 } |
97 | 98 |
98 bool Process::IsProcessBackgrounded() const { | 99 bool Process::IsProcessBackgrounded() const { |
99 DCHECK(IsValid()); | 100 DCHECK(IsValid()); |
100 | 101 |
101 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
102 if (g_cgroups.Get().enabled) { | 103 if (g_cgroups.Get().enabled) { |
103 // Used to allow reading the process priority from proc on thread launch. | 104 // Used to allow reading the process priority from proc on thread launch. |
104 base::ThreadRestrictions::ScopedAllowIO allow_io; | 105 base::ThreadRestrictions::ScopedAllowIO allow_io; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return kNullProcessId; | 194 return kNullProcessId; |
194 } | 195 } |
195 return value; | 196 return value; |
196 } | 197 } |
197 } | 198 } |
198 return kNullProcessId; | 199 return kNullProcessId; |
199 } | 200 } |
200 #endif // defined(OS_CHROMEOS) | 201 #endif // defined(OS_CHROMEOS) |
201 | 202 |
202 } // namespace base | 203 } // namespace base |
OLD | NEW |