зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 6ccfb75c8926 (bug 1260499) for wrong patch
--HG-- extra : rebase_source : 2915ef7ca91bafc94532fb38a179cc49e9d4e9a0
This commit is contained in:
Родитель
df28f2e515
Коммит
3b5039d9a7
|
@ -147,19 +147,11 @@ this.PushServiceAndroidGCM = {
|
||||||
prefs.observe("debug", this);
|
prefs.observe("debug", this);
|
||||||
Services.obs.addObserver(this, "PushServiceAndroidGCM:ReceivedPushMessage", false);
|
Services.obs.addObserver(this, "PushServiceAndroidGCM:ReceivedPushMessage", false);
|
||||||
|
|
||||||
return this._configure(serverURL, !!prefs.get("debug")).then(() => {
|
return this._configure(serverURL, !!prefs.get("debug"));
|
||||||
return Messaging.sendRequestForResult({
|
|
||||||
type: "PushServiceAndroidGCM:Initialized"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
uninit: function() {
|
uninit: function() {
|
||||||
console.debug("uninit()");
|
console.debug("uninit()");
|
||||||
Messaging.sendRequest({
|
|
||||||
type: "PushServiceAndroidGCM:Uninitialized"
|
|
||||||
});
|
|
||||||
|
|
||||||
this._mainPushService = null;
|
this._mainPushService = null;
|
||||||
Services.obs.removeObserver(this, "PushServiceAndroidGCM:ReceivedPushMessage");
|
Services.obs.removeObserver(this, "PushServiceAndroidGCM:ReceivedPushMessage");
|
||||||
prefs.ignore("debug", this);
|
prefs.ignore("debug", this);
|
||||||
|
|
|
@ -26,8 +26,6 @@ import org.mozilla.gecko.util.EventCallback;
|
||||||
import org.mozilla.gecko.util.ThreadUtils;
|
import org.mozilla.gecko.util.ThreadUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,10 +34,6 @@ import java.util.Map;
|
||||||
* This singleton services Gecko messages from dom/push/PushServiceAndroidGCM.jsm and Google Cloud
|
* This singleton services Gecko messages from dom/push/PushServiceAndroidGCM.jsm and Google Cloud
|
||||||
* Messaging requests.
|
* Messaging requests.
|
||||||
* <p/>
|
* <p/>
|
||||||
* It is expected that Gecko is started (if not already running) soon after receiving GCM messages
|
|
||||||
* otherwise there is a greater risk that pending messages that have not been handle by Gecko will
|
|
||||||
* be lost if this service is killed.
|
|
||||||
* <p/>
|
|
||||||
* It's worth noting that we allow the DOM push API in restricted profiles.
|
* It's worth noting that we allow the DOM push API in restricted profiles.
|
||||||
*/
|
*/
|
||||||
@ReflectionTarget
|
@ReflectionTarget
|
||||||
|
@ -54,8 +48,6 @@ public class PushService implements BundleEventListener {
|
||||||
"PushServiceAndroidGCM:Configure",
|
"PushServiceAndroidGCM:Configure",
|
||||||
"PushServiceAndroidGCM:DumpRegistration",
|
"PushServiceAndroidGCM:DumpRegistration",
|
||||||
"PushServiceAndroidGCM:DumpSubscriptions",
|
"PushServiceAndroidGCM:DumpSubscriptions",
|
||||||
"PushServiceAndroidGCM:Initialized",
|
|
||||||
"PushServiceAndroidGCM:Uninitialized",
|
|
||||||
"PushServiceAndroidGCM:RegisterUserAgent",
|
"PushServiceAndroidGCM:RegisterUserAgent",
|
||||||
"PushServiceAndroidGCM:UnregisterUserAgent",
|
"PushServiceAndroidGCM:UnregisterUserAgent",
|
||||||
"PushServiceAndroidGCM:SubscribeChannel",
|
"PushServiceAndroidGCM:SubscribeChannel",
|
||||||
|
@ -82,10 +74,6 @@ public class PushService implements BundleEventListener {
|
||||||
|
|
||||||
protected final PushManager pushManager;
|
protected final PushManager pushManager;
|
||||||
|
|
||||||
private boolean canSendPushMessagesToGecko;
|
|
||||||
|
|
||||||
private final List<String> pendingPushMessages;
|
|
||||||
|
|
||||||
public PushService(Context context) {
|
public PushService(Context context) {
|
||||||
pushManager = new PushManager(new PushState(context, "GeckoPushState.json"), new GcmTokenClient(context), new PushManager.PushClientFactory() {
|
pushManager = new PushManager(new PushState(context, "GeckoPushState.json"), new GcmTokenClient(context), new PushManager.PushClientFactory() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,8 +81,6 @@ public class PushService implements BundleEventListener {
|
||||||
return new PushClient(autopushEndpoint);
|
return new PushClient(autopushEndpoint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
pendingPushMessages = new LinkedList<String>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStartup() {
|
public void onStartup() {
|
||||||
|
@ -197,26 +183,13 @@ public class PushService implements BundleEventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
enqueueOrSendMessage(data.toString());
|
Log.i(LOG_TAG, "Delivering dom/push message to Gecko!");
|
||||||
|
GeckoAppShell.notifyObservers("PushServiceAndroidGCM:ReceivedPushMessage", data.toString());
|
||||||
} else {
|
} else {
|
||||||
Log.e(LOG_TAG, "Message directed to unknown service; dropping: " + subscription.service);
|
Log.e(LOG_TAG, "Message directed to unknown service; dropping: " + subscription.service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void enqueueOrSendMessage(final @NonNull String message) {
|
|
||||||
if (canSendPushMessagesToGecko) {
|
|
||||||
sendMessageToGeckoService(message);
|
|
||||||
} else {
|
|
||||||
Log.i(LOG_TAG, "Service not initialized, adding message to queue.");
|
|
||||||
pendingPushMessages.add(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void sendMessageToGeckoService(final @NonNull String message) {
|
|
||||||
Log.i(LOG_TAG, "Delivering dom/push message to Gecko!");
|
|
||||||
GeckoAppShell.notifyObservers("PushServiceAndroidGCM:ReceivedPushMessage", message);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void registerGeckoEventListener() {
|
protected void registerGeckoEventListener() {
|
||||||
Log.d(LOG_TAG, "Registered Gecko event listener.");
|
Log.d(LOG_TAG, "Registered Gecko event listener.");
|
||||||
EventDispatcher.getInstance().registerBackgroundThreadListener(this, GECKO_EVENTS);
|
EventDispatcher.getInstance().registerBackgroundThreadListener(this, GECKO_EVENTS);
|
||||||
|
@ -273,24 +246,6 @@ public class PushService implements BundleEventListener {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("PushServiceAndroidGCM:Initialized".equals(event)) {
|
|
||||||
// Send all pending messages to Gecko and set the
|
|
||||||
// canSendPushMessageToGecko flag to true so that
|
|
||||||
// all new push messages are sent directly to Gecko
|
|
||||||
// instead of being queued.
|
|
||||||
canSendPushMessagesToGecko = true;
|
|
||||||
for (String pushMessage : pendingPushMessages) {
|
|
||||||
sendMessageToGeckoService(pushMessage);
|
|
||||||
}
|
|
||||||
pendingPushMessages.clear();
|
|
||||||
callback.sendSuccess(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ("PushServiceAndroidGCM:Uninitialized".equals(event)) {
|
|
||||||
canSendPushMessagesToGecko = false;
|
|
||||||
callback.sendSuccess(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ("PushServiceAndroidGCM:RegisterUserAgent".equals(event)) {
|
if ("PushServiceAndroidGCM:RegisterUserAgent".equals(event)) {
|
||||||
try {
|
try {
|
||||||
pushManager.registerUserAgent(geckoProfile.getName(), System.currentTimeMillis()); // For side-effects.
|
pushManager.registerUserAgent(geckoProfile.getName(), System.currentTimeMillis()); // For side-effects.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче