| 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.h" | 5 #include "base/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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // priority than 0. But rlimit's are in the range from 0 to 39 where | 106 // priority than 0. But rlimit's are in the range from 0 to 39 where |
| 107 // 1 is higher than 0. | 107 // 1 is higher than 0. |
| 108 if ((20 - current_priority) > static_cast<int>(rlim.rlim_cur)) { | 108 if ((20 - current_priority) > static_cast<int>(rlim.rlim_cur)) { |
| 109 // User is not allowed to raise the priority back to where it is now. | 109 // User is not allowed to raise the priority back to where it is now. |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 int result = | 112 int result = |
| 113 setpriority( | 113 setpriority( |
| 114 PRIO_PROCESS, process_, current_priority + kPriorityAdjustment); | 114 PRIO_PROCESS, process_, current_priority + kPriorityAdjustment); |
| 115 if (result == -1) { | 115 if (result == -1) { |
| 116 LOG(ERROR) << "Failed to lower priority, errno: " << errno; | 116 DLOG(ERROR) << "Failed to lower priority, errno: " << errno; |
| 117 return false; | 117 return false; |
| 118 } | 118 } |
| 119 saved_priority_ = current_priority; | 119 saved_priority_ = current_priority; |
| 120 return true; | 120 return true; |
| 121 } else { | 121 } else { |
| 122 if (saved_priority_ == kUnsetProcessPriority) { | 122 if (saved_priority_ == kUnsetProcessPriority) { |
| 123 // Can't restore if we were never backgrounded. | 123 // Can't restore if we were never backgrounded. |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); | 126 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); |
| 127 // If we can't restore something has gone terribly wrong. | 127 // If we can't restore something has gone terribly wrong. |
| 128 DPCHECK(result == 0); | 128 DPCHECK(result == 0); |
| 129 saved_priority_ = kUnsetProcessPriority; | 129 saved_priority_ = kUnsetProcessPriority; |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace base | 134 } // namespace base |
| OLD | NEW |