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

Unified Diff: base/process/process_fuchsia.cc

Issue 2692273008: Hacky slashy (Closed)
Patch Set: rebase on config CL, and minor fixes Created 3 years, 7 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/memory.cc ('k') | base/process/process_handle.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_fuchsia.cc
diff --git a/base/process/process_fuchsia.cc b/base/process/process_fuchsia.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7c2a1a1112509725b70a519579cebafd2d9fb15a
--- /dev/null
+++ b/base/process/process_fuchsia.cc
@@ -0,0 +1,151 @@
+// Copyright 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/process/process.h"
+
+#include <magenta/syscalls.h>
+
+#include "base/debug/activity_tracker.h"
+
+namespace base {
+
+Process::Process(ProcessHandle handle) : process_(handle) {
+}
+
+Process::~Process() {
+}
+
+Process::Process(Process&& other) : process_(other.process_) {
+ other.Close();
+}
+
+Process& Process::operator=(Process&& other) {
+ process_ = other.process_;
+ other.Close();
+ return *this;
+}
+
+// static
+Process Process::Current() {
+ return Process(GetCurrentProcessHandle());
+}
+
+// static
+Process Process::Open(ProcessId pid) {
+ if (pid == GetCurrentProcId())
+ return Current();
+ NOTIMPLEMENTED();
+ // TODO(scottmg): Port.
+ return Process(MX_HANDLE_INVALID);
+}
+
+// static
+Process Process::OpenWithExtraPrivileges(ProcessId pid) {
+ // No privileges to set.
+ return Open(pid);
+}
+
+// static
+Process Process::DeprecatedGetProcessFromHandle(ProcessHandle handle) {
+ DCHECK_NE(handle, GetCurrentProcessHandle());
+ return Process(handle);
+}
+
+// static
+bool Process::CanBackgroundProcesses() {
+ return false;
+}
+
+// static
+void Process::TerminateCurrentProcessImmediately(int exit_code) {
+ _exit(exit_code);
+}
+
+bool Process::IsValid() const {
+ return process_ != kNullProcessHandle;
+}
+
+ProcessHandle Process::Handle() const {
+ return process_;
+}
+
+Process Process::Duplicate() const {
+ if (is_current())
+ return Current();
+
+ return Process(process_);
+}
+
+ProcessId Process::Pid() const {
+ DCHECK(IsValid());
+ return GetProcId(process_);
+}
+
+bool Process::is_current() const {
+ return process_ == GetCurrentProcessHandle();
+}
+
+void Process::Close() {
+ process_ = kNullProcessHandle;
+ // if the process wasn't terminated (so we waited) or the state
+ // wasn't already collected w/ a wait from process_utils, we're gonna
+ // end up w/ a zombie when it does finally exit.
+}
+
+bool Process::Terminate(int exit_code, bool wait) const {
+ mx_status_t status = mx_task_kill(process_);
+ // TODO(scottmg): Use |wait|.
+ return status >= 0;
+}
+
+bool Process::WaitForExit(int* exit_code) const {
+ return WaitForExitWithTimeout(TimeDelta::Max(), exit_code);
+}
+
+bool Process::WaitForExitWithTimeout(TimeDelta timeout, int* exit_code) const {
+ // Record the event that this thread is blocking upon (for hang diagnosis).
+ base::debug::ScopedProcessWaitActivity process_activity(this);
+
+ mx_time_t mxtimeout =
+ timeout == TimeDelta::Max()
+ ? MX_TIME_INFINITE
+ : timeout.InMicroseconds() * Time::kNanosecondsPerMicrosecond;
+ mx_signals_t signals_observed;
+ mx_status_t status = mx_object_wait_one(process_, MX_TASK_TERMINATED,
+ mxtimeout, &signals_observed);
+ *exit_code = -1;
+ if (status != NO_ERROR && status != ERR_TIMED_OUT)
+ return false;
+ if (status == ERR_TIMED_OUT && !signals_observed)
+ return false;
+
+ mx_info_process_t proc_info;
+ status = mx_object_get_info(process_, MX_INFO_PROCESS, &proc_info,
+ sizeof(proc_info), nullptr, nullptr);
+ if (status != NO_ERROR)
+ return status;
+
+ *exit_code = proc_info.return_code;
+ return true;
+}
+
+bool Process::IsProcessBackgrounded() const {
+ // See SetProcessBackgrounded().
+ DCHECK(IsValid());
+ return false;
+}
+
+bool Process::SetProcessBackgrounded(bool value) {
+ // TODO(scottmg): Port.
+ NOTIMPLEMENTED();
+ return false;
+}
+
+int Process::GetPriority() const {
+ // TODO(scottmg): Port.
+ DCHECK(IsValid());
+ return 0;
+}
+
+} // namespace base
« no previous file with comments | « base/process/memory.cc ('k') | base/process/process_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698