| Index: mojo/system/android/src/org/chromium/mojo/system/HandleImpl.java
|
| diff --git a/mojo/system/android/src/org/chromium/mojo/system/HandleImpl.java b/mojo/system/android/src/org/chromium/mojo/system/HandleImpl.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..baf1fb277b31a5a3098bd57a693dfb4d04cf9330
|
| --- /dev/null
|
| +++ b/mojo/system/android/src/org/chromium/mojo/system/HandleImpl.java
|
| @@ -0,0 +1,102 @@
|
| +// Copyright 2014 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.
|
| +
|
| +package org.chromium.mojo.system;
|
| +
|
| +
|
| +/**
|
| + * TODO(qsr): Insert description here.
|
| + */
|
| +public class HandleImpl implements Handle {
|
| +
|
| + static final int INVALID_HANDLE = 0;
|
| +
|
| + /**
|
| + * The pointer to the scoped handle owned by this object.
|
| + */
|
| + private int mMojoHandle;
|
| +
|
| + /**
|
| + * the core implementation. Will be used to delegate all behavior.
|
| + */
|
| + protected CoreImpl mCore;
|
| +
|
| + /**
|
| + * TODO(qsr):
|
| + */
|
| + HandleImpl(CoreImpl core, int mojoHandle) {
|
| + this.mCore = core;
|
| + mMojoHandle = mojoHandle;
|
| + }
|
| +
|
| + /**
|
| + * TODO(qsr):
|
| + */
|
| + HandleImpl(HandleImpl other) {
|
| + this.mCore = other.mCore;
|
| + int mojoHandle = other.mMojoHandle;
|
| + other.mMojoHandle = INVALID_HANDLE;
|
| + this.mMojoHandle = mojoHandle;
|
| + }
|
| +
|
| + /*
|
| + * (non-Javadoc)
|
| + * @see org.chromium.mojo.system.Handle#close()
|
| + */
|
| + @Override
|
| + public void close() {
|
| + // After a close, the handle is invalid whether the close succeed or not.
|
| + int handle = mMojoHandle;
|
| + mMojoHandle = INVALID_HANDLE;
|
| + mCore.close(handle);
|
| + }
|
| +
|
| + /*
|
| + * (non-Javadoc)
|
| + * @see org.chromium.mojo.system.Handle#wait(...)
|
| + */
|
| + @Override
|
| + public MojoResult wait(Core.WaitFlags flags, long deadline) {
|
| + return mCore.wait(this, flags, deadline);
|
| + }
|
| +
|
| + /*
|
| + * (non-Javadoc)
|
| + * @see org.chromium.mojo.system.Handle#isValid()
|
| + */
|
| + @Override
|
| + public boolean isValid() {
|
| + return mMojoHandle != INVALID_HANDLE;
|
| + }
|
| +
|
| + /**
|
| + * Getter for the native scoped handle.
|
| + *
|
| + * @return the native scoped handle.
|
| + */
|
| + int getMojoHandle() {
|
| + return mMojoHandle;
|
| + }
|
| +
|
| + /**
|
| + * TODO(qsr):
|
| + */
|
| + void invalidateHandle() {
|
| + mMojoHandle = INVALID_HANDLE;
|
| + }
|
| +
|
| + /*
|
| + * (non-Javadoc)
|
| + * @see java.lang.Object#finalize()
|
| + */
|
| + @Override
|
| + protected void finalize() throws Throwable {
|
| + if (isValid()) {
|
| + // Ignore result at thit point.
|
| + mCore.closeWithResult(mMojoHandle);
|
| + }
|
| + super.finalize();
|
| + }
|
| +
|
| +}
|
|
|