Bug 674725 - Part AD - Notify when getMessage() fails. r=smaug,cjones sr=sicking

This commit is contained in:
Mounir Lamouri 2011-12-22 23:14:45 +01:00
parent 608642548a
commit bbb4a45fc6
11 changed files with 102 additions and 15 deletions

View File

@ -195,6 +195,9 @@ SmsRequest::GetError(nsAString& aError)
case eNoSignalError:
aError.AssignLiteral("NoSignalError");
break;
case eNotFoundError:
aError.AssignLiteral("NotFoundError");
break;
case eUnknownError:
aError.AssignLiteral("UnknownError");
break;

View File

@ -61,6 +61,7 @@ public:
enum ErrorType {
eNoError = 0,
eNoSignalError,
eNotFoundError,
eUnknownError,
eInternalError,
};

View File

@ -135,13 +135,7 @@ SmsRequestManager::NotifySuccessWithMessage(PRInt32 aRequestId,
}
void
SmsRequestManager::NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
{
NotifySuccessWithMessage(aRequestId, aMessage);
}
void
SmsRequestManager::NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError)
SmsRequestManager::NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError)
{
NS_ASSERTION(mRequests.Count() > aRequestId && mRequests[aRequestId],
"Got an invalid request id or it has been already deleted!");
@ -156,12 +150,31 @@ SmsRequestManager::NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType
mRequests.ReplaceObjectAt(nsnull, aRequestId);
}
void
SmsRequestManager::NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
{
NotifySuccessWithMessage(aRequestId, aMessage);
}
void
SmsRequestManager::NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError)
{
NotifyError(aRequestId, aError);
}
void
SmsRequestManager::NotifyGotSms(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
{
NotifySuccessWithMessage(aRequestId, aMessage);
}
void
SmsRequestManager::NotifyGetSmsFailed(PRInt32 aRequestId,
SmsRequest::ErrorType aError)
{
NotifyError(aRequestId, aError);
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -65,6 +65,7 @@ public:
void NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
void NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError);
void NotifyGotSms(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
void NotifyGetSmsFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError);
private:
static SmsRequestManager* sInstance;
@ -73,6 +74,7 @@ private:
nsIDOMMozSmsRequest* aRequest);
void NotifySuccessWithMessage(PRInt32 aRequestId,
nsIDOMMozSmsMessage* aMessage);
void NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError);
nsCOMArray<nsIDOMMozSmsRequest> mRequests;
};

View File

@ -74,6 +74,9 @@ child:
NotifyRequestGotSms(SmsMessageData aMessageData, PRInt32 aRequestId,
PRUint64 aProcessId);
NotifyRequestGetSmsFailed(PRInt32 aError, PRInt32 aRequestId,
PRUint64 aProcessId);
parent:
sync HasSupport()
returns (bool aHasSupport);

View File

@ -135,6 +135,21 @@ SmsChild::RecvNotifyRequestGotSms(const SmsMessageData& aMessage,
return true;
}
bool
SmsChild::RecvNotifyRequestGetSmsFailed(const PRInt32& aError,
const PRInt32& aRequestId,
const PRUint64& aProcessId)
{
if (ContentChild::GetSingleton()->GetID() != aProcessId) {
return true;
}
SmsRequestManager::GetInstance()->NotifyGetSmsFailed(aRequestId,
SmsRequest::ErrorType(aError));
return true;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -53,6 +53,7 @@ public:
NS_OVERRIDE virtual bool RecvNotifyRequestSmsSent(const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestSmsSendFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestGotSms(const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
NS_OVERRIDE virtual bool RecvNotifyRequestGetSmsFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId);
};
} // namespace sms

View File

@ -127,6 +127,7 @@ public class GeckoAppShell
public static native void notifySmsDelivered(int aId, String aReceiver, String aBody, long aTimestamp);
public static native void notifySmsSendFailed(int aError, int aRequestId, long aProcessId);
public static native void notifyGetSms(int aId, String aReceiver, String aSender, String aBody, long aTimestamp, int aRequestId, long aProcessId);
public static native void notifyGetSmsFailed(int aError, int aRequestId, long aProcessId);
// A looper thread, accessed by GeckoAppShell.getHandler
private static class LooperThread extends Thread {

View File

@ -265,8 +265,9 @@ public class GeckoSmsManager
*/
public final static int kNoError = 0;
public final static int kNoSignalError = 1;
public final static int kUnknownError = 2;
public final static int kInternalError = 3;
public final static int kNotFoundError = 2;
public final static int kUnknownError = 3;
public final static int kInternalError = 4;
private final static int kMaxMessageSize = 160;
@ -582,21 +583,21 @@ public class GeckoSmsManager
cursor.getLong(cursor.getColumnIndex("date")),
mRequestId, mProcessId);
} catch (NotFoundException e) {
// TODO: send failure notification
Log.i("GeckoSmsManager", "Message id " + mMessageId + " not found");
GeckoAppShell.notifyGetSmsFailed(kNotFoundError, mRequestId, mProcessId);
} catch (UnmatchingIdException e) {
// TODO: send failure notification
Log.e("GeckoSmsManager", "Requested message id (" + mMessageId +
") is different from the one we got.");
GeckoAppShell.notifyGetSmsFailed(kUnknownError, mRequestId, mProcessId);
} catch (TooManyResultsException e) {
// TODO: send failure notification
Log.e("GeckoSmsManager", "Get too many results for id " + mMessageId);
GeckoAppShell.notifyGetSmsFailed(kUnknownError, mRequestId, mProcessId);
} catch (InvalidTypeException e) {
// TODO: send failure notification
Log.i("GeckoSmsManager", "Message has an invalid type, we ignore it.");
GeckoAppShell.notifyGetSmsFailed(kNotFoundError, mRequestId, mProcessId);
} catch (Exception e) {
// TODO: send failure notification
Log.e("GeckoSmsManager", "Error while trying to get message: " + e);
GeckoAppShell.notifyGetSmsFailed(kUnknownError, mRequestId, mProcessId);
} finally {
if (cursor != null) {
cursor.close();
@ -606,8 +607,8 @@ public class GeckoSmsManager
}
if (!SmsIOThread.getInstance().execute(new GetMessageRunnable(aMessageId, aRequestId, aProcessId))) {
// TODO: send failure notification
Log.e("GeckoSmsManager", "Failed to add GetMessageRunnable to the SmsIOThread");
GeckoAppShell.notifyGetSmsFailed(kUnknownError, aRequestId, aProcessId);
}
}

View File

@ -275,6 +275,7 @@ SHELL_WRAPPER6(notifySmsSent, jint, jstring, jstring, jlong, jint, jlong);
SHELL_WRAPPER4(notifySmsDelivered, jint, jstring, jstring, jlong);
SHELL_WRAPPER3(notifySmsSendFailed, jint, jint, jlong);
SHELL_WRAPPER7(notifyGetSms, jint, jstring, jstring, jstring, jlong, jint, jlong);
SHELL_WRAPPER3(notifyGetSmsFailed, jint, jint, jlong);
static void * xul_handle = NULL;
static time_t apk_mtime = 0;
@ -667,6 +668,7 @@ loadLibs(const char *apkName)
GETFUNC(notifySmsDelivered);
GETFUNC(notifySmsSendFailed);
GETFUNC(notifyGetSms);
GETFUNC(notifyGetSmsFailed);
#undef GETFUNC
sStartupTimeline = (uint64_t *)__wrap_dlsym(xul_handle, "_ZN7mozilla15StartupTimeline16sStartupTimelineE");
gettimeofday(&t1, 0);

View File

@ -96,6 +96,7 @@ extern "C" {
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsDelivered(JNIEnv* jenv, jclass, jint, jstring, jstring, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsSendFailed(JNIEnv* jenv, jclass, jint, jint, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGetSms(JNIEnv* jenv, jclass, jint, jstring, jstring, jstring, jlong, jint, jlong);
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGetSmsFailed(JNIEnv* jenv, jclass, jint, jint, jlong);
#ifdef MOZ_JAVA_COMPOSITOR
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_bindWidgetTexture(JNIEnv* jenv, jclass);
@ -501,6 +502,50 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyGetSms(JNIEnv* jenv, jclass,
NS_DispatchToMainThread(runnable);
}
NS_EXPORT void JNICALL
Java_org_mozilla_gecko_GeckoAppShell_notifyGetSmsFailed(JNIEnv* jenv, jclass,
jint aError,
jint aRequestId,
jlong aProcessId)
{
class NotifyGetSmsFailedRunnable : public nsRunnable {
public:
NotifyGetSmsFailedRunnable(SmsRequest::ErrorType aError,
PRInt32 aRequestId, PRUint64 aProcessId)
: mError(aError)
, mRequestId(aRequestId)
, mProcessId(aProcessId)
{}
NS_IMETHODIMP Run() {
if (mProcessId == 0) { // Parent process.
SmsRequestManager::GetInstance()->NotifyGetSmsFailed(mRequestId, mError);
} else { // Content process.
nsTArray<SmsParent*> spList;
SmsParent::GetAll(spList);
for (PRUint32 i=0; i<spList.Length(); ++i) {
unused << spList[i]->SendNotifyRequestGetSmsFailed(mError,
mRequestId,
mProcessId);
}
}
return NS_OK;
}
private:
SmsRequest::ErrorType mError;
PRInt32 mRequestId;
PRUint64 mProcessId;
};
nsCOMPtr<nsIRunnable> runnable =
new NotifyGetSmsFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
NS_DispatchToMainThread(runnable);
}
#ifdef MOZ_JAVA_COMPOSITOR
NS_EXPORT void JNICALL