summaryrefslogtreecommitdiffstats
path: root/base/process.h
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 21:49:38 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 21:49:38 +0000
commitd7cae12696b96500c05dd2d430f6238922c20c96 (patch)
treeecff27b367735535b2a66477f8cd89d3c462a6c0 /base/process.h
parentee2815e28d408216cf94e874825b6bcf76c69083 (diff)
downloadchromium_src-d7cae12696b96500c05dd2d430f6238922c20c96.zip
chromium_src-d7cae12696b96500c05dd2d430f6238922c20c96.tar.gz
chromium_src-d7cae12696b96500c05dd2d430f6238922c20c96.tar.bz2
Add base to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process.h')
-rw-r--r--base/process.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/base/process.h b/base/process.h
new file mode 100644
index 0000000..b8ea94f
--- /dev/null
+++ b/base/process.h
@@ -0,0 +1,106 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef BASE_PROCESS_H__
+#define BASE_PROCESS_H__
+
+#include <windows.h>
+#include "base/basictypes.h"
+
+// ProcessHandle is a platform specific type which represents the underlying OS
+// handle to a process.
+#ifdef WIN32
+typedef HANDLE ProcessHandle;
+#else
+typedef int ProcessHandle;
+#endif
+
+// A Process
+// TODO(mbelshe): Replace existing code which uses the ProcessHandle w/ the
+// Process object where relevant.
+class Process {
+ public:
+ Process() : process_(0), last_working_set_size_(0) {}
+ explicit Process(ProcessHandle handle) :
+ process_(handle), last_working_set_size_(0) {}
+
+ // A handle to the current process.
+ static Process Current();
+
+ // Get/Set the handle for this process.
+ ProcessHandle handle() { return process_; }
+ void set_handle(ProcessHandle handle) { process_ = handle; }
+
+ // Get the PID for this process.
+ int32 pid() const;
+
+ // Is the this process the current process.
+ bool is_current() const;
+
+ // Close the Process Handle.
+ void Close() {
+ CloseHandle(process_);
+ process_ = 0;
+ }
+
+ // A process is backgrounded when it's priority is lower than normal.
+ // Return true if this process is backgrounded, false otherwise.
+ bool IsProcessBackgrounded();
+
+ // Set a prcess as backgrounded. If value is true, the priority
+ // of the process will be lowered. If value is false, the priority
+ // of the process will be made "normal" - equivalent to default
+ // process priority.
+ // Returns true if the priority was changed, false otherwise.
+ bool SetProcessBackgrounded(bool value);
+
+ // Reduces the working set of memory used by the process.
+ // The algorithm used by this function is intentionally vague. Repeated calls
+ // to this function consider the process' previous required Working Set sizes
+ // to determine a reasonable reduction. This helps give memory back to the OS
+ // in increments without over releasing memory.
+ // When the WorkingSet is reduced, it is permanent, until the caller calls
+ // UnReduceWorkingSet.
+ // Returns true if successful, false otherwise.
+ bool ReduceWorkingSet();
+
+ // Undoes the effects of prior calls to ReduceWorkingSet().
+ // Returns true if successful, false otherwise.
+ bool UnReduceWorkingSet();
+
+ // Releases as much of the working set back to the OS as possible.
+ // Returns true if successful, false otherwise.
+ bool EmptyWorkingSet();
+
+ private:
+ ProcessHandle process_;
+ size_t last_working_set_size_;
+};
+
+#endif // BASE_PROCESS_H__