Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a4efb77 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Add locking when mutating RecentTasks." into mnc-dr-dev

parents 38463bb9 a1123479
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Log;


import com.android.documentsui.BaseActivity.State;
import com.android.documentsui.BaseActivity.State;
import com.android.documentsui.model.RootInfo;
import com.android.documentsui.model.RootInfo;
import com.android.internal.annotations.GuardedBy;
import com.google.android.collect.Maps;
import com.google.android.collect.Maps;
import com.google.common.collect.Lists;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.AbstractFuture;
import com.google.common.util.concurrent.AbstractFuture;
@@ -81,6 +82,7 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
    private final RootsCache mRoots;
    private final RootsCache mRoots;
    private final State mState;
    private final State mState;


    @GuardedBy("mTasks")
    private final HashMap<RootInfo, RecentTask> mTasks = Maps.newHashMap();
    private final HashMap<RootInfo, RecentTask> mTasks = Maps.newHashMap();


    private final int mSortOrder = State.SORT_ORDER_LAST_MODIFIED;
    private final int mSortOrder = State.SORT_ORDER_LAST_MODIFIED;
@@ -167,6 +169,12 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {


    @Override
    @Override
    public DirectoryResult loadInBackground() {
    public DirectoryResult loadInBackground() {
        synchronized (mTasks) {
            return loadInBackgroundLocked();
        }
    }

    private DirectoryResult loadInBackgroundLocked() {
        if (mFirstPassLatch == null) {
        if (mFirstPassLatch == null) {
            // First time through we kick off all the recent tasks, and wait
            // First time through we kick off all the recent tasks, and wait
            // around to see if everyone finishes quickly.
            // around to see if everyone finishes quickly.
@@ -304,9 +312,11 @@ public class RecentLoader extends AsyncTaskLoader<DirectoryResult> {
        // Ensure the loader is stopped
        // Ensure the loader is stopped
        onStopLoading();
        onStopLoading();


        synchronized (mTasks) {
            for (RecentTask task : mTasks.values()) {
            for (RecentTask task : mTasks.values()) {
                IoUtils.closeQuietly(task);
                IoUtils.closeQuietly(task);
            }
            }
        }


        IoUtils.closeQuietly(mResult);
        IoUtils.closeQuietly(mResult);
        mResult = null;
        mResult = null;