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

Side by Side Diff: base/process/process_linux.cc

Issue 2733283002: Require explicit selection of traits for LazyInstance (Closed)
Patch Set: l10n again Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « base/metrics/user_metrics.cc ('k') | base/test/launcher/test_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/metrics/user_metrics.cc ('k') | base/test/launcher/test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698