Skip to content

Commit 04263dc

Browse files
Jeff BrownAndroid (Google) Code Review
authored andcommitted
Merge "AbstractWindowedCursor is not special."
2 parents d008510 + b4009c7 commit 04263dc

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed

core/java/android/database/CursorToBulkCursorAdaptor.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
/**
2626
* Wraps a BulkCursor around an existing Cursor making it remotable.
2727
* <p>
28-
* If the wrapped cursor is a {@link AbstractWindowedCursor} then it owns
29-
* the cursor window. Otherwise, the adaptor takes ownership of the
30-
* cursor itself and ensures it gets closed as needed during deactivation
28+
* If the wrapped cursor returns non-null from {@link CrossProcessCursor#getWindow}
29+
* then it is assumed to own the window. Otherwise, the adaptor provides a
30+
* window to be filled and ensures it gets closed as needed during deactivation
3131
* and requeries.
3232
* </p>
3333
*
@@ -48,12 +48,11 @@ public final class CursorToBulkCursorAdaptor extends BulkCursorNative
4848
private CrossProcessCursor mCursor;
4949

5050
/**
51-
* The cursor window used by the cross process cursor.
52-
* This field is always null for abstract windowed cursors since they are responsible
53-
* for managing the lifetime of their window.
51+
* The cursor window that was filled by the cross process cursor in the
52+
* case where the cursor does not support getWindow.
53+
* This field is only ever non-null when the window has actually be filled.
5454
*/
55-
private CursorWindow mWindowForNonWindowedCursor;
56-
private boolean mWindowForNonWindowedCursorWasFilled;
55+
private CursorWindow mFilledWindow;
5756

5857
private static final class ContentObserverProxy extends ContentObserver {
5958
protected IContentObserver mRemote;
@@ -103,11 +102,10 @@ public CursorToBulkCursorAdaptor(Cursor cursor, IContentObserver observer,
103102
}
104103
}
105104

106-
private void closeWindowForNonWindowedCursorLocked() {
107-
if (mWindowForNonWindowedCursor != null) {
108-
mWindowForNonWindowedCursor.close();
109-
mWindowForNonWindowedCursor = null;
110-
mWindowForNonWindowedCursorWasFilled = false;
105+
private void closeFilledWindowLocked() {
106+
if (mFilledWindow != null) {
107+
mFilledWindow.close();
108+
mFilledWindow = null;
111109
}
112110
}
113111

@@ -118,7 +116,7 @@ private void disposeLocked() {
118116
mCursor = null;
119117
}
120118

121-
closeWindowForNonWindowedCursorLocked();
119+
closeFilledWindowLocked();
122120
}
123121

124122
private void throwIfCursorIsClosed() {
@@ -139,30 +137,24 @@ public CursorWindow getWindow(int startPos) {
139137
synchronized (mLock) {
140138
throwIfCursorIsClosed();
141139

142-
CursorWindow window;
143-
if (mCursor instanceof AbstractWindowedCursor) {
144-
AbstractWindowedCursor windowedCursor = (AbstractWindowedCursor)mCursor;
145-
window = windowedCursor.getWindow();
146-
if (window == null) {
147-
window = new CursorWindow(mProviderName);
148-
windowedCursor.setWindow(window);
149-
}
140+
if (!mCursor.moveToPosition(startPos)) {
141+
closeFilledWindowLocked();
142+
return null;
143+
}
150144

151-
mCursor.moveToPosition(startPos);
145+
CursorWindow window = mCursor.getWindow();
146+
if (window != null) {
147+
closeFilledWindowLocked();
152148
} else {
153-
window = mWindowForNonWindowedCursor;
149+
window = mFilledWindow;
154150
if (window == null) {
155-
window = new CursorWindow(mProviderName);
156-
mWindowForNonWindowedCursor = window;
157-
}
158-
159-
mCursor.moveToPosition(startPos);
160-
161-
if (!mWindowForNonWindowedCursorWasFilled
162-
|| startPos < window.getStartPosition()
151+
mFilledWindow = new CursorWindow(mProviderName);
152+
window = mFilledWindow;
153+
mCursor.fillWindow(startPos, window);
154+
} else if (startPos < window.getStartPosition()
163155
|| startPos >= window.getStartPosition() + window.getNumRows()) {
156+
window.clear();
164157
mCursor.fillWindow(startPos, window);
165-
mWindowForNonWindowedCursorWasFilled = true;
166158
}
167159
}
168160

@@ -211,7 +203,7 @@ public void deactivate() {
211203
mCursor.deactivate();
212204
}
213205

214-
closeWindowForNonWindowedCursorLocked();
206+
closeFilledWindowLocked();
215207
}
216208
}
217209

@@ -227,7 +219,7 @@ public int requery(IContentObserver observer) {
227219
synchronized (mLock) {
228220
throwIfCursorIsClosed();
229221

230-
closeWindowForNonWindowedCursorLocked();
222+
closeFilledWindowLocked();
231223

232224
try {
233225
if (!mCursor.requery()) {

0 commit comments

Comments
 (0)