Bug 1120728 - remove nsIUrlClassifierDBServiceWorker. r=francois, r=gcp
MozReview-Commit-ID: G3HeQ5pecrE
--- a/toolkit/components/url-classifier/nsIUrlClassifierDBService.idl
+++ b/toolkit/components/url-classifier/nsIUrlClassifierDBService.idl
@@ -189,32 +189,16 @@ interface nsIUrlClassifierDBService : ns
/**
* Reset the url-classifier database. This call will delete the existing
* database, emptying all tables. Mostly intended for use in unit tests.
*/
void resetDatabase();
};
/**
- * Interface for the actual worker thread. Implementations of this need not
- * be thread aware and just work on the database.
- */
-[scriptable, uuid(b7b505d0-bfa2-44db-abf8-6e2bfc25bbab)]
-interface nsIUrlClassifierDBServiceWorker : nsIUrlClassifierDBService
-{
- // Open the DB connection
- void openDb();
- // Provide a way to forcibly close the db connection.
- void closeDb();
-
- [noscript]void cacheCompletions(in CacheCompletionArray completions);
- [noscript]void cacheMisses(in PrefixArray misses);
-};
-
-/**
* This is an internal helper interface for communication between the
* main thread and the dbservice worker thread. It is called for each
* lookup to provide a set of possible results, which the main thread
* may need to expand using an nsIUrlClassifierCompleter.
*/
[uuid(b903dc8f-dff1-42fe-894b-36e7a59bb801)]
interface nsIUrlClassifierLookupCallback : nsISupports
{
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -100,17 +100,16 @@ nsIThread* nsUrlClassifierDBService::gDb
// Once we've committed to shutting down, don't do work in the background
// thread.
static bool gShuttingDownThread = false;
static mozilla::Atomic<int32_t> gFreshnessGuarantee(CONFIRM_AGE_DEFAULT_SEC);
NS_IMPL_ISUPPORTS(nsUrlClassifierDBServiceWorker,
- nsIUrlClassifierDBServiceWorker,
nsIUrlClassifierDBService)
nsUrlClassifierDBServiceWorker::nsUrlClassifierDBServiceWorker()
: mInStream(false)
, mGethashNoise(0)
, mPendingLookupLock("nsUrlClassifierDBServerWorker.mPendingLookupLock")
{
}
@@ -654,31 +653,31 @@ nsUrlClassifierDBServiceWorker::CancelUp
return NS_OK;
}
// Allows the main thread to delete the connection which may be in
// a background thread.
// XXX This could be turned into a single shutdown event so the logic
// is simpler in nsUrlClassifierDBService::Shutdown.
-NS_IMETHODIMP
+nsresult
nsUrlClassifierDBServiceWorker::CloseDb()
{
if (mClassifier) {
mClassifier->Close();
mClassifier = nullptr;
}
mCryptoHash = nullptr;
LOG(("urlclassifier db closed\n"));
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
nsUrlClassifierDBServiceWorker::CacheCompletions(CacheResultArray *results)
{
LOG(("nsUrlClassifierDBServiceWorker::CacheCompletions [%p]", this));
if (!mClassifier)
return NS_OK;
// Ownership is transferred in to us
nsAutoPtr<CacheResultArray> resultsPtr(results);
@@ -729,17 +728,17 @@ nsUrlClassifierDBServiceWorker::CacheCom
}
}
mClassifier->ApplyUpdates(&updates);
mLastResults = *resultsPtr;
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
nsUrlClassifierDBServiceWorker::CacheMisses(PrefixArray *results)
{
LOG(("nsUrlClassifierDBServiceWorker::CacheMisses [%p] %d",
this, results->Length()));
// Ownership is transferred in to us
nsAutoPtr<PrefixArray> resultsPtr(results);
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h
@@ -133,25 +133,23 @@ private:
// The list of tables that should never be hash completed.
nsTArray<nsCString> mDisallowCompletionsTables;
// Thread that we do the updates on.
static nsIThread* gDbBackgroundThread;
};
-class nsUrlClassifierDBServiceWorker final :
- public nsIUrlClassifierDBServiceWorker
+class nsUrlClassifierDBServiceWorker final : public nsIUrlClassifierDBService
{
public:
nsUrlClassifierDBServiceWorker();
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIURLCLASSIFIERDBSERVICE
- NS_DECL_NSIURLCLASSIFIERDBSERVICEWORKER
nsresult Init(uint32_t aGethashNoise, nsCOMPtr<nsIFile> aCacheDir);
// Queue a lookup for the worker to perform, called in the main thread.
// tables is a comma-separated list of tables to query
nsresult QueueLookup(const nsACString& lookupKey,
const nsACString& tables,
nsIUrlClassifierLookupCallback* callback);
@@ -161,16 +159,25 @@ public:
nsresult HandlePendingLookups();
// Perform a blocking classifier lookup for a given url. Can be called on
// either the main thread or the worker thread.
nsresult DoLocalLookup(const nsACString& spec,
const nsACString& tables,
LookupResultArray* results);
+ // Open the DB connection
+ nsresult OpenDb();
+
+ // Provide a way to forcibly close the db connection.
+ nsresult CloseDb();
+
+ nsresult CacheCompletions(CacheResultArray * aEntries);
+ nsresult CacheMisses(PrefixArray * aEntries);
+
private:
// No subclassing
~nsUrlClassifierDBServiceWorker();
// Disallow copy constructor
nsUrlClassifierDBServiceWorker(nsUrlClassifierDBServiceWorker&);
// Applies the current transaction and resets the update/working times.
--- a/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp
@@ -16,18 +16,17 @@ DispatchToWorkerThread(nsIRunnable* r)
{
nsIThread* t = nsUrlClassifierDBService::BackgroundThread();
if (!t)
return NS_ERROR_FAILURE;
return t->Dispatch(r, NS_DISPATCH_NORMAL);
}
-NS_IMPL_ISUPPORTS(UrlClassifierDBServiceWorkerProxy,
- nsIUrlClassifierDBServiceWorker)
+NS_IMPL_ISUPPORTS(UrlClassifierDBServiceWorkerProxy, nsIUrlClassifierDBService)
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::Lookup(nsIPrincipal* aPrincipal,
const nsACString& aTables,
nsIUrlClassifierCallback* aCB)
{
nsCOMPtr<nsIRunnable> r = new LookupRunnable(mTarget, aPrincipal, aTables,
aCB);
@@ -110,17 +109,17 @@ UrlClassifierDBServiceWorkerProxy::Updat
return NS_OK;
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::FinishStream()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::FinishStream);
+ &nsUrlClassifierDBServiceWorker::FinishStream);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::DoLocalLookupRunnable::Run()
{
mTarget->DoLocalLookup(mSpec, mTables, mResults);
return NS_OK;
@@ -144,71 +143,71 @@ UrlClassifierDBServiceWorkerProxy::DoLoc
return NS_OK;
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::FinishUpdate()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::FinishUpdate);
+ &nsUrlClassifierDBServiceWorker::FinishUpdate);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::CancelUpdate()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::CancelUpdate);
+ &nsUrlClassifierDBServiceWorker::CancelUpdate);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::ResetDatabase()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::ResetDatabase);
+ &nsUrlClassifierDBServiceWorker::ResetDatabase);
return DispatchToWorkerThread(r);
}
-NS_IMETHODIMP
+nsresult
UrlClassifierDBServiceWorkerProxy::OpenDb()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::OpenDb);
+ &nsUrlClassifierDBServiceWorker::OpenDb);
return DispatchToWorkerThread(r);
}
-NS_IMETHODIMP
+nsresult
UrlClassifierDBServiceWorkerProxy::CloseDb()
{
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod(mTarget,
- &nsIUrlClassifierDBServiceWorker::CloseDb);
+ &nsUrlClassifierDBServiceWorker::CloseDb);
return DispatchToWorkerThread(r);
}
-NS_IMETHODIMP
+nsresult
UrlClassifierDBServiceWorkerProxy::CacheCompletions(CacheResultArray * aEntries)
{
nsCOMPtr<nsIRunnable> r = new CacheCompletionsRunnable(mTarget, aEntries);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable::Run()
{
mTarget->CacheCompletions(mEntries);
return NS_OK;
}
-NS_IMETHODIMP
+nsresult
UrlClassifierDBServiceWorkerProxy::CacheMisses(PrefixArray * aEntries)
{
nsCOMPtr<nsIRunnable> r = new CacheMissesRunnable(mTarget, aEntries);
return DispatchToWorkerThread(r);
}
NS_IMETHODIMP
UrlClassifierDBServiceWorkerProxy::CacheMissesRunnable::Run()
--- a/toolkit/components/url-classifier/nsUrlClassifierProxies.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierProxies.h
@@ -13,27 +13,25 @@
#include "mozilla/Attributes.h"
#include "nsIPrincipal.h"
#include "LookupCache.h"
/**
* Thread proxy from the main thread to the worker thread.
*/
-class UrlClassifierDBServiceWorkerProxy final :
- public nsIUrlClassifierDBServiceWorker
+class UrlClassifierDBServiceWorkerProxy final : public nsIUrlClassifierDBService
{
public:
explicit UrlClassifierDBServiceWorkerProxy(nsUrlClassifierDBServiceWorker* aTarget)
: mTarget(aTarget)
{ }
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIURLCLASSIFIERDBSERVICE
- NS_DECL_NSIURLCLASSIFIERDBSERVICEWORKER
class LookupRunnable : public mozilla::Runnable
{
public:
LookupRunnable(nsUrlClassifierDBServiceWorker* aTarget,
nsIPrincipal* aPrincipal,
const nsACString& aTables,
nsIUrlClassifierCallback* aCB)
@@ -203,16 +201,22 @@ public:
RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
};
public:
nsresult DoLocalLookup(const nsACString& spec,
const nsACString& tables,
mozilla::safebrowsing::LookupResultArray* results);
+ nsresult OpenDb();
+ nsresult CloseDb();
+
+ nsresult CacheCompletions(mozilla::safebrowsing::CacheResultArray * aEntries);
+ nsresult CacheMisses(mozilla::safebrowsing::PrefixArray * aEntries);
+
private:
~UrlClassifierDBServiceWorkerProxy() {}
RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
};
// The remaining classes here are all proxies to the main thread