| Index: base/android/java/src/org/chromium/base/ApplicationStatus.java
|
| diff --git a/base/android/java/src/org/chromium/base/ApplicationStatus.java b/base/android/java/src/org/chromium/base/ApplicationStatus.java
|
| index d68160010767b1c12b96f3fa8fa8714c6227b427..954415d8554ca0d9b67c0995b48e052c659715c7 100644
|
| --- a/base/android/java/src/org/chromium/base/ApplicationStatus.java
|
| +++ b/base/android/java/src/org/chromium/base/ApplicationStatus.java
|
| @@ -12,9 +12,9 @@ import android.os.Bundle;
|
|
|
| import java.lang.ref.WeakReference;
|
| import java.util.ArrayList;
|
| -import java.util.HashMap;
|
| import java.util.List;
|
| import java.util.Map;
|
| +import java.util.concurrent.ConcurrentHashMap;
|
|
|
| /**
|
| * Provides information about the current activity's status, and a way
|
| @@ -51,6 +51,7 @@ public class ApplicationStatus {
|
|
|
| private static Application sApplication;
|
|
|
| + private static Object sCachedApplicationStateLock = new Object();
|
| private static Integer sCachedApplicationState;
|
|
|
| /** Last activity that was shown (or null if none or it was destroyed). */
|
| @@ -63,7 +64,7 @@ public class ApplicationStatus {
|
| * A map of which observers listen to state changes from which {@link Activity}.
|
| */
|
| private static final Map<Activity, ActivityInfo> sActivityInfo =
|
| - new HashMap<Activity, ActivityInfo>();
|
| + new ConcurrentHashMap<Activity, ActivityInfo>();
|
|
|
| /**
|
| * A list of observers to be notified when any {@link Activity} has a state change.
|
| @@ -187,7 +188,9 @@ public class ApplicationStatus {
|
| }
|
|
|
| // Invalidate the cached application state.
|
| - sCachedApplicationState = null;
|
| + synchronized (sCachedApplicationStateLock) {
|
| + sCachedApplicationState = null;
|
| + }
|
|
|
| ActivityInfo info = sActivityInfo.get(activity);
|
| info.setStatus(newState);
|
| @@ -235,7 +238,6 @@ public class ApplicationStatus {
|
| * @return A {@link List} of all non-destroyed {@link Activity}s.
|
| */
|
| public static List<WeakReference<Activity>> getRunningActivities() {
|
| - ThreadUtils.assertOnUiThread();
|
| List<WeakReference<Activity>> activities = new ArrayList<WeakReference<Activity>>();
|
| for (Activity activity : sActivityInfo.keySet()) {
|
| activities.add(new WeakReference<Activity>(activity));
|
| @@ -302,7 +304,11 @@ public class ApplicationStatus {
|
| * @return The state of the application (see {@link ApplicationState}).
|
| */
|
| public static int getStateForApplication() {
|
| - if (sCachedApplicationState == null) sCachedApplicationState = determineApplicationState();
|
| + synchronized (sCachedApplicationStateLock) {
|
| + if (sCachedApplicationState == null) {
|
| + sCachedApplicationState = determineApplicationState();
|
| + }
|
| + }
|
|
|
| return sCachedApplicationState.intValue();
|
| }
|
|
|