| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/field_trial.h" | |
| 10 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
| 14 | 12 |
| 15 namespace { | 13 namespace { |
| 16 | 14 |
| 17 DWORD kBasicProcessAccess = | 15 DWORD kBasicProcessAccess = |
| 18 PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE; | 16 PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION | SYNCHRONIZE; |
| 19 | 17 |
| 20 } // namespace | 18 } // namespace |
| 21 | 19 |
| 22 namespace base { | 20 namespace base { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 bool Process::SetProcessBackgrounded(bool value) { | 170 bool Process::SetProcessBackgrounded(bool value) { |
| 173 DCHECK(IsValid()); | 171 DCHECK(IsValid()); |
| 174 // Vista and above introduce a real background mode, which not only | 172 // Vista and above introduce a real background mode, which not only |
| 175 // sets the priority class on the threads but also on the IO generated | 173 // sets the priority class on the threads but also on the IO generated |
| 176 // by it. Unfortunately it can only be set for the calling process. | 174 // by it. Unfortunately it can only be set for the calling process. |
| 177 DWORD priority; | 175 DWORD priority; |
| 178 if ((base::win::GetVersion() >= base::win::VERSION_VISTA) && (is_current())) { | 176 if ((base::win::GetVersion() >= base::win::VERSION_VISTA) && (is_current())) { |
| 179 priority = value ? PROCESS_MODE_BACKGROUND_BEGIN : | 177 priority = value ? PROCESS_MODE_BACKGROUND_BEGIN : |
| 180 PROCESS_MODE_BACKGROUND_END; | 178 PROCESS_MODE_BACKGROUND_END; |
| 181 } else { | 179 } else { |
| 182 // Experiment (http://crbug.com/458594) with using IDLE_PRIORITY_CLASS as a | 180 priority = value ? IDLE_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; |
| 183 // background priority for background renderers (this code path is | |
| 184 // technically for more than just the renderers but they're the only use | |
| 185 // case in practice and experimenting here direclty is thus easier -- plus | |
| 186 // it doesn't really hurt as above we already state our intent of using | |
| 187 // PROCESS_MODE_BACKGROUND_BEGIN if available which is essentially | |
| 188 // IDLE_PRIORITY_CLASS plus lowered IO priority). Enabled by default in the | |
| 189 // asbence of field trials to get coverage on the perf waterfall. | |
| 190 DWORD background_priority = IDLE_PRIORITY_CLASS; | |
| 191 base::FieldTrial* trial = | |
| 192 base::FieldTrialList::Find("BackgroundRendererProcesses"); | |
| 193 if (trial && StartsWith(trial->group_name(), "AllowBelowNormalFromBrowser", | |
| 194 CompareCase::SENSITIVE)) { | |
| 195 background_priority = BELOW_NORMAL_PRIORITY_CLASS; | |
| 196 } | |
| 197 | |
| 198 priority = value ? background_priority : NORMAL_PRIORITY_CLASS; | |
| 199 } | 181 } |
| 200 | 182 |
| 201 return (::SetPriorityClass(Handle(), priority) != 0); | 183 return (::SetPriorityClass(Handle(), priority) != 0); |
| 202 } | 184 } |
| 203 | 185 |
| 204 int Process::GetPriority() const { | 186 int Process::GetPriority() const { |
| 205 DCHECK(IsValid()); | 187 DCHECK(IsValid()); |
| 206 return ::GetPriorityClass(Handle()); | 188 return ::GetPriorityClass(Handle()); |
| 207 } | 189 } |
| 208 | 190 |
| 209 } // namespace base | 191 } // namespace base |
| OLD | NEW |