Bug 1292323 - Update usage of UsesNativeCallProxy; r=snorp

Remove uses of UsesNativeCallProxy and UsesGeckoThreadProxy, now that
they are not needed.

Remove cases where we had to invoke a call in a proxy, because the call
is now specified to be invoked directly in the WrapForJNI annotation,
without the need to go through the proxy.

For SmsManager and AlarmReceiver, we no longer need to manually dispatch
everything to the Gecko thread because that's now handled automatically.
This commit is contained in:
Jim Chen 2016-08-12 23:15:53 -04:00
Родитель 36628f0198
Коммит 347603e672
10 изменённых файлов: 117 добавлений и 210 удалений

Просмотреть файл

@ -13,17 +13,10 @@ namespace dom {
class AndroidGamepadManager final
: public java::AndroidGamepadManager::Natives<AndroidGamepadManager>
, public jni::UsesNativeCallProxy
{
AndroidGamepadManager() = delete;
public:
template<class Functor>
static void OnNativeCall(Functor&& aCall)
{
NS_DispatchToMainThread(NS_NewRunnableFunction(Move(aCall)));
}
static void
OnGamepadChange(int32_t aID, bool aAdded)
{

Просмотреть файл

@ -15,7 +15,6 @@
#include "mozilla/Services.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsIObserverService.h"
#include "nsThreadUtils.h"
using namespace mozilla::dom;
using namespace mozilla::dom::mobilemessage;
@ -47,16 +46,13 @@ SmsManager::NotifySmsReceived(int32_t aId,
message.deliveryTimestamp() = aTimestamp;
message.read() = false;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=] () {
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
obs->NotifyObservers(domMessage, kSmsReceivedObserverTopic, nullptr);
});
NS_DispatchToMainThread(runnable);
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
obs->NotifyObservers(domMessage, kSmsReceivedObserverTopic, nullptr);
}
/*static*/
@ -84,28 +80,25 @@ SmsManager::NotifySmsSent(int32_t aId,
message.deliveryTimestamp() = aTimestamp;
message.read() = true;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
/*
* First, we are going to notify all SmsManager that a message has
* been sent. Then, we will notify the SmsRequest object about it.
*/
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
/*
* First, we are going to notify all SmsManager that a message has
* been sent. Then, we will notify the SmsRequest object about it.
*/
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
obs->NotifyObservers(domMessage, kSmsSentObserverTopic, nullptr);
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
obs->NotifyObservers(domMessage, kSmsSentObserverTopic, nullptr);
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
request->NotifyMessageSent(domMessage);
});
NS_DispatchToMainThread(runnable);
request->NotifyMessageSent(domMessage);
}
/*static*/
@ -133,35 +126,29 @@ SmsManager::NotifySmsDelivery(int32_t aId,
message.deliveryTimestamp() = aTimestamp;
message.read() = true;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
const char* topic = (message.deliveryStatus() == eDeliveryStatus_Success)
? kSmsDeliverySuccessObserverTopic
: kSmsDeliveryErrorObserverTopic;
obs->NotifyObservers(domMessage, topic, nullptr);
});
NS_DispatchToMainThread(runnable);
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
const char* topic = (message.deliveryStatus() == eDeliveryStatus_Success)
? kSmsDeliverySuccessObserverTopic
: kSmsDeliveryErrorObserverTopic;
obs->NotifyObservers(domMessage, topic, nullptr);
}
/*static*/
void
SmsManager::NotifySmsSendFailed(int32_t aError, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if(!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if(!request) {
return;
}
request->NotifySendMessageFailed(aError, nullptr);
});
NS_DispatchToMainThread(runnable);
request->NotifySendMessageFailed(aError, nullptr);
}
/*static*/
@ -196,83 +183,68 @@ SmsManager::NotifyGetSms(int32_t aId,
message.deliveryTimestamp() = aTimestamp;
message.read() = aRead;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
request->NotifyMessageGot(domMessage);
});
NS_DispatchToMainThread(runnable);
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
request->NotifyMessageGot(domMessage);
}
/*static*/
void
SmsManager::NotifyGetSmsFailed(int32_t aError, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
request->NotifyGetMessageFailed(aError);
});
NS_DispatchToMainThread(runnable);
request->NotifyGetMessageFailed(aError);
}
/*static*/
void
SmsManager::NotifySmsDeleted(bool aDeleted, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
// For android, we support only single SMS deletion.
bool deleted = aDeleted;
request->NotifyMessageDeleted(&deleted, 1);
});
NS_DispatchToMainThread(runnable);
// For android, we support only single SMS deletion.
bool deleted = aDeleted;
request->NotifyMessageDeleted(&deleted, 1);
}
/*static*/
void
SmsManager::NotifySmsDeleteFailed(int32_t aError, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
request->NotifyDeleteMessageFailed(aError);
});
NS_DispatchToMainThread(runnable);
request->NotifyDeleteMessageFailed(aError);
}
/*static*/
void
SmsManager::NotifyCursorError(int32_t aError, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
if (!request) {
return;
}
request->NotifyCursorError(aError);
});
NS_DispatchToMainThread(runnable);
request->NotifyCursorError(aError);
}
/*static*/
@ -296,7 +268,7 @@ SmsManager::NotifyThreadCursorResult(int64_t aId,
thread.timestamp() = aTimestamp;
thread.lastMessageType() = eMessageType_SMS;
JNIEnv* const env = jni::GetEnvForThread();
JNIEnv* const env = jni::GetGeckoThreadEnv();
jobjectArray participants = aParticipants.Get();
jsize length = env->GetArrayLength(participants);
@ -305,27 +277,25 @@ SmsManager::NotifyThreadCursorResult(int64_t aId,
static_cast<jstring>(env->GetObjectArrayElement(participants, i));
if (participant) {
thread.participants().AppendElement(nsJNIString(participant, env));
env->DeleteLocalRef(participant);
}
}
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMArray<nsIMobileMessageThread> arr;
arr.AppendElement(new MobileMessageThreadInternal(thread));
nsCOMArray<nsIMobileMessageThread> arr;
arr.AppendElement(new MobileMessageThreadInternal(thread));
nsIMobileMessageThread** elements;
int32_t size;
size = arr.Forget(&elements);
nsIMobileMessageThread** elements;
int32_t size;
size = arr.Forget(&elements);
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
size);
});
NS_DispatchToMainThread(runnable);
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
size);
}
/*static*/
@ -360,72 +330,60 @@ SmsManager::NotifyMessageCursorResult(int32_t aMessageId,
message.deliveryTimestamp() = aTimestamp;
message.read() = aRead;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMArray<nsISmsMessage> arr;
arr.AppendElement(new SmsMessageInternal(message));
nsCOMArray<nsISmsMessage> arr;
arr.AppendElement(new SmsMessageInternal(message));
nsISmsMessage** elements;
int32_t size;
size = arr.Forget(&elements);
nsISmsMessage** elements;
int32_t size;
size = arr.Forget(&elements);
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
size);
});
NS_DispatchToMainThread(runnable);
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
size);
}
/*static*/
void
SmsManager::NotifyCursorDone(int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCursorCallback> request =
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
if (!request) {
return;
}
request->NotifyCursorDone();
});
NS_DispatchToMainThread(runnable);
request->NotifyCursorDone();
}
/*static*/
void
SmsManager::NotifySmsMarkedAsRead(bool aMarkedAsRead, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
request->NotifyMessageMarkedRead(aMarkedAsRead);
});
NS_DispatchToMainThread(runnable);
request->NotifyMessageMarkedRead(aMarkedAsRead);
}
/*static*/
void
SmsManager::NotifySmsMarkAsReadFailed(int32_t aError, int32_t aRequestId)
{
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
nsCOMPtr<nsIMobileMessageCallback> request =
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
if (!request) {
return;
}
request->NotifyMarkMessageReadFailed(aError);
});
NS_DispatchToMainThread(runnable);
request->NotifyMarkMessageReadFailed(aError);
}
} // namespace

Просмотреть файл

@ -19,10 +19,7 @@ private:
public:
static void NotifyAlarmFired() {
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=]() {
hal::NotifyAlarmFired();
});
NS_DispatchToMainThread(runnable);
hal::NotifyAlarmFired();
}
};

Просмотреть файл

@ -17,7 +17,6 @@ namespace mozilla {
class GeckoNetworkManager final
: public java::GeckoNetworkManager::Natives<GeckoNetworkManager>
, public UsesGeckoThreadProxy
{
GeckoNetworkManager() = delete;

Просмотреть файл

@ -18,7 +18,6 @@ namespace mozilla {
class GeckoScreenOrientation final
: public java::GeckoScreenOrientation::Natives<GeckoScreenOrientation>
, public UsesGeckoThreadProxy
{
GeckoScreenOrientation() = delete;

Просмотреть файл

@ -19,7 +19,6 @@ namespace mozilla {
class PrefsHelper
: public java::PrefsHelper::Natives<PrefsHelper>
, public UsesGeckoThreadProxy
{
PrefsHelper() = delete;

Просмотреть файл

@ -17,7 +17,6 @@ namespace widget {
class Telemetry final
: public java::Telemetry::Natives<Telemetry>
, public UsesGeckoThreadProxy
{
Telemetry() = delete;

Просмотреть файл

@ -29,7 +29,6 @@ namespace mozilla {
class ThumbnailHelper final
: public java::ThumbnailHelper::Natives<ThumbnailHelper>
, public java::ZoomedView::Natives<ThumbnailHelper>
, public UsesGeckoThreadProxy
{
ThumbnailHelper() = delete;
@ -202,11 +201,6 @@ public:
template<class Functor>
static void OnNativeCall(Functor&& aCall)
{
if (!aCall.IsTarget(&RequestThumbnail)) {
UsesGeckoThreadProxy::OnNativeCall(Move(aCall));
return;
}
class IdleEvent : public nsAppShell::LambdaEvent<Functor>
{
using Base = nsAppShell::LambdaEvent<Functor>;

Просмотреть файл

@ -96,23 +96,10 @@ StaticRefPtr<WakeLockListener> sWakeLockListener;
class GeckoThreadSupport final
: public java::GeckoThread::Natives<GeckoThreadSupport>
, public UsesGeckoThreadProxy
{
static uint32_t sPauseCount;
public:
template<typename Functor>
static void OnNativeCall(Functor&& aCall)
{
if (aCall.IsTarget(&SpeculativeConnect) ||
aCall.IsTarget(&WaitOnGecko)) {
aCall();
return;
}
return UsesGeckoThreadProxy::OnNativeCall(aCall);
}
static void SpeculativeConnect(jni::String::Param aUriStr)
{
if (!NS_IsMainThread()) {
@ -201,6 +188,8 @@ public:
static void CreateServices(jni::String::Param aCategory, jni::String::Param aData)
{
MOZ_ASSERT(NS_IsMainThread());
nsCString category(aCategory->ToCString());
NS_CreateServicesFromCategory(
@ -216,19 +205,8 @@ uint32_t GeckoThreadSupport::sPauseCount;
class GeckoAppShellSupport final
: public java::GeckoAppShell::Natives<GeckoAppShellSupport>
, public UsesGeckoThreadProxy
{
public:
template<typename Functor>
static void OnNativeCall(Functor&& aCall)
{
if (aCall.IsTarget(&SyncNotifyObservers)) {
aCall();
return;
}
return UsesGeckoThreadProxy::OnNativeCall(aCall);
}
static void SyncNotifyObservers(jni::String::Param aTopic,
jni::String::Param aData)
{

Просмотреть файл

@ -184,7 +184,6 @@ class nsWindow::GeckoViewSupport final
: public GeckoView::Window::Natives<GeckoViewSupport>
, public GeckoEditable::Natives<GeckoViewSupport>
, public SupportsWeakPtr<GeckoViewSupport>
, public UsesGeckoThreadProxy
{
nsWindow& window;
@ -880,7 +879,6 @@ public:
class nsWindow::LayerViewSupport final
: public LayerView::Compositor::Natives<LayerViewSupport>
, public SupportsWeakPtr<LayerViewSupport>
, public UsesGeckoThreadProxy
{
nsWindow& window;
LayerView::Compositor::GlobalRef mCompositor;
@ -930,7 +928,6 @@ public:
static void OnNativeCall(Functor&& aCall)
{
if (aCall.IsTarget(&LayerViewSupport::CreateCompositor)) {
// This call is blocking.
nsAppShell::SyncRunEvent(WindowEvent<Functor>(
mozilla::Move(aCall)), &LayerViewEvent::MakeEvent);
@ -950,12 +947,6 @@ public:
mozilla::MakeUnique<WindowEvent<Functor>>(
mozilla::Move(aCall))));
return;
} else if (aCall.IsTarget(
&LayerViewSupport::SyncInvalidateAndScheduleComposite) ||
aCall.IsTarget(&LayerViewSupport::SyncPauseCompositor)) {
// This call is synchronous.
return aCall();
}
// LayerViewEvent (i.e. prioritized event) applies to