Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(968)

Unified Diff: base/process/process_linux.cc

Issue 651253002: Enforce handle ownership in base::Process (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add empty line Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/process.h ('k') | base/process/process_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_linux.cc
diff --git a/base/process/process_linux.cc b/base/process/process_linux.cc
index 2c22d26484294024453b607b689309079b46999a..59ee288f880135bc66d77f47d88478dd2a2aa993 100644
--- a/base/process/process_linux.cc
+++ b/base/process/process_linux.cc
@@ -17,6 +17,7 @@
namespace base {
namespace {
+
const int kForegroundPriority = 0;
#if defined(OS_CHROMEOS)
@@ -62,10 +63,37 @@ base::LazyInstance<CGroups> cgroups = LAZY_INSTANCE_INITIALIZER;
#else
const int kBackgroundPriority = 5;
#endif
+
+struct CheckForNicePermission {
+ CheckForNicePermission() : can_reraise_priority(false) {
+ // We won't be able to raise the priority if we don't have the right rlimit.
+ // The limit may be adjusted in /etc/security/limits.conf for PAM systems.
+ struct rlimit rlim;
+ if ((getrlimit(RLIMIT_NICE, &rlim) == 0) &&
+ (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) {
+ can_reraise_priority = true;
+ }
+ };
+
+ bool can_reraise_priority;
+};
+
+} // namespace
+
+// static
+bool Process::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 Process::IsProcessBackgrounded() const {
- DCHECK(process_);
+ DCHECK(IsValid());
#if defined(OS_CHROMEOS)
if (cgroups.Get().enabled) {
@@ -87,7 +115,7 @@ bool Process::IsProcessBackgrounded() const {
}
bool Process::SetProcessBackgrounded(bool background) {
- DCHECK(process_);
+ DCHECK(IsValid());
#if defined(OS_CHROMEOS)
if (cgroups.Get().enabled) {
@@ -108,30 +136,4 @@ bool Process::SetProcessBackgrounded(bool background) {
return result == 0;
}
-struct CheckForNicePermission {
- CheckForNicePermission() : can_reraise_priority(false) {
- // We won't be able to raise the priority if we don't have the right rlimit.
- // The limit may be adjusted in /etc/security/limits.conf for PAM systems.
- struct rlimit rlim;
- if ((getrlimit(RLIMIT_NICE, &rlim) == 0) &&
- (20 - kForegroundPriority) <= static_cast<int>(rlim.rlim_cur)) {
- can_reraise_priority = true;
- }
- };
-
- bool can_reraise_priority;
-};
-
-// static
-bool Process::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;
-}
-
} // namespace base
« no previous file with comments | « base/process/process.h ('k') | base/process/process_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698