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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const int kForegroundPriority = 0; | 22 const int kForegroundPriority = 0; |
22 | 23 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 113 } |
113 #endif | 114 #endif |
114 return GetPriority() == kBackgroundPriority; | 115 return GetPriority() == kBackgroundPriority; |
115 } | 116 } |
116 | 117 |
117 bool Process::SetProcessBackgrounded(bool background) { | 118 bool Process::SetProcessBackgrounded(bool background) { |
118 DCHECK(IsValid()); | 119 DCHECK(IsValid()); |
119 | 120 |
120 #if defined(OS_CHROMEOS) | 121 #if defined(OS_CHROMEOS) |
121 if (cgroups.Get().enabled) { | 122 if (cgroups.Get().enabled) { |
122 std::string pid = StringPrintf("%d", process_); | 123 std::string pid = IntToString(process_); |
123 const base::FilePath file = | 124 const base::FilePath file = |
124 background ? | 125 background ? |
125 cgroups.Get().background_file : cgroups.Get().foreground_file; | 126 cgroups.Get().background_file : cgroups.Get().foreground_file; |
126 return base::WriteFile(file, pid.c_str(), pid.size()) > 0; | 127 return base::WriteFile(file, pid.c_str(), pid.size()) > 0; |
127 } | 128 } |
128 #endif // OS_CHROMEOS | 129 #endif // OS_CHROMEOS |
129 | 130 |
130 if (!CanBackgroundProcesses()) | 131 if (!CanBackgroundProcesses()) |
131 return false; | 132 return false; |
132 | 133 |
133 int priority = background ? kBackgroundPriority : kForegroundPriority; | 134 int priority = background ? kBackgroundPriority : kForegroundPriority; |
134 int result = setpriority(PRIO_PROCESS, process_, priority); | 135 int result = setpriority(PRIO_PROCESS, process_, priority); |
135 DPCHECK(result == 0); | 136 DPCHECK(result == 0); |
136 return result == 0; | 137 return result == 0; |
137 } | 138 } |
138 | 139 |
139 } // namespace base | 140 } // namespace base |
OLD | NEW |