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

Unified Diff: base/process_win.cc

Issue 6880265: Add a more comprehensive background mode for a process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_win.cc
===================================================================
--- base/process_win.cc (revision 83074)
+++ base/process_win.cc (working copy)
@@ -6,13 +6,16 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/process_util.h"
+#include "base/win/windows_version.h"
namespace base {
void Process::Close() {
if (!process_)
return;
- ::CloseHandle(process_);
+ // Don't call CloseHandle on a pseudo-handle.
+ if (process_ != ::GetCurrentProcess())
+ ::CloseHandle(process_);
process_ = NULL;
}
@@ -28,14 +31,26 @@
DWORD priority = GetPriority();
if (priority == 0)
return false; // Failure case.
- return priority == BELOW_NORMAL_PRIORITY_CLASS;
+ return ((priority == BELOW_NORMAL_PRIORITY_CLASS) ||
+ (priority == IDLE_PRIORITY_CLASS));
}
bool Process::SetProcessBackgrounded(bool value) {
if (!process_)
return false;
- DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS;
- return (SetPriorityClass(process_, priority) != 0);
+ // Vista and above introduce a real background mode, which not only
+ // sets the priority class on the threads but also on the IO generated
+ // by it. Unfortunately it can only be set for the calling process.
+ DWORD priority;
+ if ((base::win::GetVersion() >= base::win::VERSION_VISTA) &&
+ (process_ == ::GetCurrentProcess())) {
+ priority = value ? PROCESS_MODE_BACKGROUND_BEGIN :
+ PROCESS_MODE_BACKGROUND_END;
+ } else {
+ priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS;
+ }
+
+ return (::SetPriorityClass(process_, priority) != 0);
}
ProcessId Process::pid() const {
@@ -51,12 +66,12 @@
// static
Process Process::Current() {
- return Process(GetCurrentProcess());
+ return Process(::GetCurrentProcess());
}
int Process::GetPriority() const {
DCHECK(process_);
- return GetPriorityClass(process_);
+ return ::GetPriorityClass(process_);
}
} // namespace base
« no previous file with comments | « base/process_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698