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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process_util_unittest.cc ('k') | no next file » | 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.h" 5 #include "base/process.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/win/windows_version.h"
9 10
10 namespace base { 11 namespace base {
11 12
12 void Process::Close() { 13 void Process::Close() {
13 if (!process_) 14 if (!process_)
14 return; 15 return;
15 ::CloseHandle(process_); 16 // Don't call CloseHandle on a pseudo-handle.
17 if (process_ != ::GetCurrentProcess())
18 ::CloseHandle(process_);
16 process_ = NULL; 19 process_ = NULL;
17 } 20 }
18 21
19 void Process::Terminate(int result_code) { 22 void Process::Terminate(int result_code) {
20 if (!process_) 23 if (!process_)
21 return; 24 return;
22 ::TerminateProcess(process_, result_code); 25 ::TerminateProcess(process_, result_code);
23 } 26 }
24 27
25 bool Process::IsProcessBackgrounded() const { 28 bool Process::IsProcessBackgrounded() const {
26 if (!process_) 29 if (!process_)
27 return false; // Failure case. 30 return false; // Failure case.
28 DWORD priority = GetPriority(); 31 DWORD priority = GetPriority();
29 if (priority == 0) 32 if (priority == 0)
30 return false; // Failure case. 33 return false; // Failure case.
31 return priority == BELOW_NORMAL_PRIORITY_CLASS; 34 return ((priority == BELOW_NORMAL_PRIORITY_CLASS) ||
35 (priority == IDLE_PRIORITY_CLASS));
32 } 36 }
33 37
34 bool Process::SetProcessBackgrounded(bool value) { 38 bool Process::SetProcessBackgrounded(bool value) {
35 if (!process_) 39 if (!process_)
36 return false; 40 return false;
37 DWORD priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; 41 // Vista and above introduce a real background mode, which not only
38 return (SetPriorityClass(process_, priority) != 0); 42 // sets the priority class on the threads but also on the IO generated
43 // by it. Unfortunately it can only be set for the calling process.
44 DWORD priority;
45 if ((base::win::GetVersion() >= base::win::VERSION_VISTA) &&
46 (process_ == ::GetCurrentProcess())) {
47 priority = value ? PROCESS_MODE_BACKGROUND_BEGIN :
48 PROCESS_MODE_BACKGROUND_END;
49 } else {
50 priority = value ? BELOW_NORMAL_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS;
51 }
52
53 return (::SetPriorityClass(process_, priority) != 0);
39 } 54 }
40 55
41 ProcessId Process::pid() const { 56 ProcessId Process::pid() const {
42 if (process_ == 0) 57 if (process_ == 0)
43 return 0; 58 return 0;
44 59
45 return GetProcId(process_); 60 return GetProcId(process_);
46 } 61 }
47 62
48 bool Process::is_current() const { 63 bool Process::is_current() const {
49 return process_ == GetCurrentProcess(); 64 return process_ == GetCurrentProcess();
50 } 65 }
51 66
52 // static 67 // static
53 Process Process::Current() { 68 Process Process::Current() {
54 return Process(GetCurrentProcess()); 69 return Process(::GetCurrentProcess());
55 } 70 }
56 71
57 int Process::GetPriority() const { 72 int Process::GetPriority() const {
58 DCHECK(process_); 73 DCHECK(process_);
59 return GetPriorityClass(process_); 74 return ::GetPriorityClass(process_);
60 } 75 }
61 76
62 } // namespace base 77 } // namespace base
OLDNEW
« 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