am 04263dc5: Merge "AbstractWindowedCursor is not special."

* commit '04263dc591b07a4d5a9b53163dcb421ccffd34d4':
  AbstractWindowedCursor is not special.
This commit is contained in:
Jeff Brown
2011-10-14 21:10:02 -07:00
committed by Android Git Automerger

View File

@@ -25,9 +25,9 @@ import android.util.Log;
/**
* Wraps a BulkCursor around an existing Cursor making it remotable.
* <p>
* If the wrapped cursor is a {@link AbstractWindowedCursor} then it owns
* the cursor window. Otherwise, the adaptor takes ownership of the
* cursor itself and ensures it gets closed as needed during deactivation
* If the wrapped cursor returns non-null from {@link CrossProcessCursor#getWindow}
* then it is assumed to own the window. Otherwise, the adaptor provides a
* window to be filled and ensures it gets closed as needed during deactivation
* and requeries.
* </p>
*
@@ -48,12 +48,11 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
private CrossProcessCursor mCursor;
/**
* The cursor window used by the cross process cursor.
* This field is always null for abstract windowed cursors since they are responsible
* for managing the lifetime of their window.
* The cursor window that was filled by the cross process cursor in the
* case where the cursor does not support getWindow.
* This field is only ever non-null when the window has actually be filled.
*/
private CursorWindow mWindowForNonWindowedCursor;
private boolean mWindowForNonWindowedCursorWasFilled;
private CursorWindow mFilledWindow;
private static final class ContentObserverProxy extends ContentObserver {
protected IContentObserver mRemote;
@@ -103,11 +102,10 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
}
}
private void closeWindowForNonWindowedCursorLocked() {
if (mWindowForNonWindowedCursor != null) {
mWindowForNonWindowedCursor.close();
mWindowForNonWindowedCursor = null;
mWindowForNonWindowedCursorWasFilled = false;
private void closeFilledWindowLocked() {
if (mFilledWindow != null) {
mFilledWindow.close();
mFilledWindow = null;
}
}
@@ -118,7 +116,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
mCursor = null;
}
closeWindowForNonWindowedCursorLocked();
closeFilledWindowLocked();
}
private void throwIfCursorIsClosed() {
@@ -139,30 +137,24 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
synchronized (mLock) {
throwIfCursorIsClosed();
CursorWindow window;
if (mCursor instanceof AbstractWindowedCursor) {
AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor)mCursor;
window = windowedCursor.getWindow();
if (window == null) {
window = new CursorWindow(mProviderName);
windowedCursor.setWindow(window);
}
if (!mCursor.moveToPosition(startPos)) {
closeFilledWindowLocked();
return null;
}
mCursor.moveToPosition(startPos);
CursorWindow window = mCursor.getWindow();
if (window != null) {
closeFilledWindowLocked();
} else {
window = mWindowForNonWindowedCursor;
window = mFilledWindow;
if (window == null) {
window = new CursorWindow(mProviderName);
mWindowForNonWindowedCursor = window;
}
mCursor.moveToPosition(startPos);
if (!mWindowForNonWindowedCursorWasFilled
|| startPos < window.getStartPosition()
|| startPos >= window.getStartPosition() + window.getNumRows()) {
mFilledWindow = new CursorWindow(mProviderName);
window = mFilledWindow;
mCursor.fillWindow(startPos, window);
} else if (startPos < window.getStartPosition()
|| startPos >= window.getStartPosition() + window.getNumRows()) {
window.clear();
mCursor.fillWindow(startPos, window);
mWindowForNonWindowedCursorWasFilled = true;
}
}
@@ -211,7 +203,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
mCursor.deactivate();
}
closeWindowForNonWindowedCursorLocked();
closeFilledWindowLocked();
}
}
@@ -227,7 +219,7 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
synchronized (mLock) {
throwIfCursorIsClosed();
closeWindowForNonWindowedCursorLocked();
closeFilledWindowLocked();
try {
if (!mCursor.requery()) {