Bug 599970 - Add GetInterface for nsIEventTarget on Connection

r=asuth
This commit is contained in:
Shawn Wilsher 2010-10-05 15:01:22 -07:00
parent 50d31806a3
commit ca8b2b3da8
5 changed files with 50 additions and 7 deletions

View File

@ -271,7 +271,8 @@ AsyncStatement::~AsyncStatement()
// nsCOMPtr. Which it is not; it's an nsRefPtr.
Connection *forgottenConn = nsnull;
mDBConnection.swap(forgottenConn);
(void)::NS_ProxyRelease(forgottenConn->threadOpenedOn, forgottenConn);
(void)::NS_ProxyRelease(forgottenConn->threadOpenedOn,
static_cast<mozIStorageConnection *>(forgottenConn));
}
}

View File

@ -322,7 +322,7 @@ public:
return NS_OK;
}
private:
nsCOMPtr<Connection> mConnection;
nsRefPtr<Connection> mConnection;
nsCOMPtr<nsIEventTarget> mCallingThread;
nsCOMPtr<nsIRunnable> mCallbackEvent;
};
@ -352,9 +352,10 @@ Connection::~Connection()
(void)Close();
}
NS_IMPL_THREADSAFE_ISUPPORTS1(
NS_IMPL_THREADSAFE_ISUPPORTS2(
Connection,
mozIStorageConnection
mozIStorageConnection,
nsIInterfaceRequestor
)
nsIEventTarget *
@ -641,6 +642,22 @@ Connection::getFilename()
return leafname;
}
////////////////////////////////////////////////////////////////////////////////
//// nsIInterfaceRequestor
NS_IMETHODIMP
Connection::GetInterface(const nsIID &aIID,
void **_result)
{
if (aIID.Equals(NS_GET_IID(nsIEventTarget))) {
nsIEventTarget *background = getAsyncExecutionTarget();
NS_IF_ADDREF(background);
*_result = background;
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
//// mozIStorageConnection

View File

@ -38,12 +38,13 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef MOZSTORAGECONNECTION_H
#define MOZSTORAGECONNECTION_H
#ifndef mozilla_storage_Connection_h
#define mozilla_storage_Connection_h
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "mozilla/Mutex.h"
#include "nsIInterfaceRequestor.h"
#include "nsString.h"
#include "nsDataHashtable.h"
@ -65,10 +66,12 @@ namespace mozilla {
namespace storage {
class Connection : public mozIStorageConnection
, public nsIInterfaceRequestor
{
public:
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGECONNECTION
NS_DECL_NSIINTERFACEREQUESTOR
/**
* Structure used to describe user functions on the database connection.
@ -244,4 +247,4 @@ private:
} // namespace storage
} // namespace mozilla
#endif /* MOZSTORAGECONNECTION_H */
#endif // mozilla_storage_Connection_h

View File

@ -39,6 +39,7 @@
#include "storage_test_harness.h"
#include "prthread.h"
#include "nsIEventTarget.h"
#include "nsIInterfaceRequestorUtils.h"
#include "sqlite3.h"
@ -221,6 +222,14 @@ get_conn_async_thread(mozIStorageConnection *db)
nsCOMPtr<nsIThread> asyncThread;
threadMan->GetThreadFromPRThread(last_non_watched_thread,
getter_AddRefs(asyncThread));
// Additionally, check that the thread we get as the background thread is the
// same one as the one we report from getInterface.
nsCOMPtr<nsIEventTarget> target = do_GetInterface(db);
nsCOMPtr<nsIThread> allegedAsyncThread = do_QueryInterface(target);
PRThread *allegedPRThread;
(void)allegedAsyncThread->GetPRThread(&allegedPRThread);
do_check_eq(allegedPRThread, last_non_watched_thread);
return asyncThread.forget();
}

View File

@ -482,6 +482,18 @@ function test_clone_copies_overridden_functions()
run_next_test();
}
function test_getInterface()
{
let db = getOpenedDatabase();
let target = db.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEventTarget);
// Just check that target is non-null. Other tests will ensure that it has
// the correct value.
do_check_true(target != null);
run_next_test();
}
////////////////////////////////////////////////////////////////////////////////
//// Test Runner
@ -513,6 +525,7 @@ var tests = [
test_close_clone_fails,
test_clone_copies_functions,
test_clone_copies_overridden_functions,
test_getInterface,
];
let index = 0;