Bug 1130066 - Be careful about environment changes during early or failed BrowserHealthRecorder init. r=mcomella

--HG--
extra : commitid : 8adUOMlVMj4
This commit is contained in:
Richard Newman 2015-07-21 13:26:34 -07:00
parent 57d8b2b908
commit ed84104432

View File

@ -263,6 +263,12 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
*/
@Override
public synchronized void onEnvironmentChanged(final boolean startNewSession, final String sessionEndReason) {
if (!(state == State.INITIALIZING ||
state == State.INITIALIZED)) {
Log.w(LOG_TAG, "Not initialized. Ignoring environment change. State is " + state);
return;
}
final int previousEnv = this.env;
this.env = -1;
try {
@ -295,7 +301,7 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
protected synchronized int ensureEnvironment() {
if (!(state == State.INITIALIZING ||
state == State.INITIALIZED)) {
throw new IllegalStateException("Not initialized.");
throw new IllegalStateException("Not initialized. State is " + state);
}
if (this.env != -1) {
@ -566,10 +572,18 @@ public class BrowserHealthRecorder implements HealthRecorder, GeckoEventListener
try {
profileCache.completeInitialization();
if (state == State.INITIALIZING) {
initializeStorage();
} else {
onEnvironmentChanged();
synchronized (BrowserHealthRecorder.this) {
switch (state) {
case State.INITIALIZING:
initializeStorage();
break;
case State.INITIALIZED:
onEnvironmentChanged();
break;
default:
Log.e(LOG_TAG, "Unexpected state " + state + " when handling late distribution.");
return;
}
}
} catch (Exception e) {
// Well, we tried.