rolling back patch for bug 340603 (files are missing) to fix the build

This commit is contained in:
tony%ponderer.org 2006-06-08 01:42:28 +00:00
parent eacda8057f
commit 3930b2c904
5 changed files with 16 additions and 195 deletions

View File

@ -9,7 +9,6 @@ MODULE = url-classifier
XPIDL_MODULE = url-classifier
XPIDLSRCS = nsIUrlClassifierDBService.idl \
nsIUrlClassifierStreamUpdater.idl \
nsIUrlClassifierTable.idl \
nsIUrlListManager.idl \
$(NULL)

View File

@ -49,7 +49,7 @@ interface nsIUrlClassifierCallback : nsISupports {
* It provides async methods for querying and updating the database. As the
* methods complete, they call the callback function.
*/
[scriptable, uuid(61759a52-fbbb-4c5e-b1df-fce67b6d10c8)]
[scriptable, uuid(88519724-2225-4b4f-8ba7-365b4d138c3a)]
interface nsIUrlClassifierDBService : nsISupports
{
/**
@ -67,24 +67,6 @@ interface nsIUrlClassifierDBService : nsISupports
* allows us to keep track of the table version in our main thread.
*/
void updateTables(in ACString updateString, in nsIUrlClassifierCallback c);
////////////////////////////////////////////////////////////////////////////
// Incremental update methods. These are named to match similar methods
// in, e.g., nsICryptoHash.
/**
* Update the table incrementally.
*/
void update(in ACString updateChunk);
// It would be nice to have an updateFromStream method to round out the
// interface, but it's tricky because of XPCOM proxies.
/**
* Finish an incremental update. This commits any pending tables and
* calls the callback for each completed table.
*/
void finish(in nsIUrlClassifierCallback c);
};
/**

View File

@ -12,15 +12,14 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Url Classifier code
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Tony Chang <tony@ponderer.org> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or

View File

@ -12,15 +12,13 @@ MOZILLA_INTERNAL_API = 1
FORCE_STATIC_LIB = 1
REQUIRES = necko \
storage \
REQUIRES = storage \
string \
xpcom \
$(NULL)
CPPSRCS = \
nsUrlClassifierDBService.cpp \
nsUrlClassifierStreamUpdater.cpp \
$(NULL)
LOCAL_INCLUDES = \

View File

@ -51,12 +51,11 @@
#include "nsIProxyObjectManager.h"
#include "nsToolkitCompsCID.h"
#include "nsUrlClassifierDBService.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#include "nsString.h"
#include "prlog.h"
#include "prmon.h"
// NSPR_LOG_MODULES=UrlClassifierDbService:5
#if defined(PR_LOGGING)
static const PRLogModuleInfo *gUrlClassifierDbServiceLog = nsnull;
#define LOG(args) PR_LOG(gUrlClassifierDbServiceLog, PR_LOG_DEBUG, args)
@ -150,25 +149,13 @@ private:
// to be created in the background thread (currently mozStorageConnection
// isn't thread safe).
mozIStorageConnection* mConnection;
// True if we're in the middle of a streaming update.
PRBool mHasPendingUpdate;
// For incremental updates, keep track of tables that have been updated.
// When finish() is called, we go ahead and pass these update lines to
// the callback.
nsTArray<nsCString> mTableUpdateLines;
// We receive data in small chunks that may be broken in the middle of
// a line. So we save the last partial line here.
nsCString mPendingStreamUpdate;
};
NS_IMPL_THREADSAFE_ISUPPORTS1(nsUrlClassifierDBServiceWorker,
nsIUrlClassifierDBServiceWorker)
nsUrlClassifierDBServiceWorker::nsUrlClassifierDBServiceWorker()
: mConnection(nsnull), mHasPendingUpdate(PR_FALSE), mTableUpdateLines()
: mConnection(nsnull)
{
}
nsUrlClassifierDBServiceWorker::~nsUrlClassifierDBServiceWorker()
@ -183,8 +170,7 @@ nsUrlClassifierDBServiceWorker::~nsUrlClassifierDBServiceWorker()
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName,
const nsACString& key,
nsIUrlClassifierCallback *c)
{
nsIUrlClassifierCallback *c) {
LOG(("Exists\n"));
nsresult rv = OpenDb();
@ -228,8 +214,7 @@ nsUrlClassifierDBServiceWorker::Exists(const nsACString& tableName,
// we call the callback with the table line.
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::UpdateTables(const nsACString& updateString,
nsIUrlClassifierCallback *c)
{
nsIUrlClassifierCallback *c) {
LOG(("Updating tables\n"));
nsresult rv = OpenDb();
@ -266,14 +251,11 @@ nsUrlClassifierDBServiceWorker::UpdateTables(const nsACString& updateString,
getter_AddRefs(deleteStatement));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "malformed table line");
if (NS_SUCCEEDED(rv)) {
// If it's a new table, we may have completed a table.
// Go ahead and post the completion to the UI thread and db.
if (lastTableLine.Length() > 0) {
mConnection->CommitTransaction();
// If it's a new table, we must have completed the last table.
// Go ahead and post the completion to the UI thread.
// XXX This shouldn't happen before we commit the transaction.
if (lastTableLine.Length() > 0)
c->HandleEvent(lastTableLine);
mConnection->BeginTransaction();
}
lastTableLine.Assign(line);
}
} else {
@ -294,92 +276,6 @@ nsUrlClassifierDBServiceWorker::UpdateTables(const nsACString& updateString,
return NS_OK;
}
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Update(const nsACString& chunk)
{
LOG(("Update from Stream."));
nsresult rv = OpenDb();
if (NS_FAILED(rv)) {
NS_ERROR("Unable to open database");
return NS_ERROR_FAILURE;
}
nsCAutoString updateString(mPendingStreamUpdate);
updateString.Append(chunk);
nsCOMPtr<mozIStorageStatement> updateStatement;
nsCOMPtr<mozIStorageStatement> deleteStatement;
nsCAutoString dbTableName;
// If we're not in the middle of an update, we start a new transaction.
// Otherwise, we need to pick up where we left off.
if (!mHasPendingUpdate) {
mConnection->BeginTransaction();
mHasPendingUpdate = PR_TRUE;
} else {
PRUint32 numTables = mTableUpdateLines.Length();
if (numTables > 0) {
const nsDependentCSubstring &line = Substring(
mTableUpdateLines[numTables - 1], 0);
rv = ProcessNewTable(line, &dbTableName,
getter_AddRefs(updateStatement),
getter_AddRefs(deleteStatement));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "malformed table line");
}
}
PRUint32 cur = 0;
PRInt32 next;
while(cur < updateString.Length() &&
(next = updateString.FindChar('\n', cur)) != kNotFound) {
const nsDependentCSubstring &line = Substring(updateString,
cur, next - cur);
cur = next + 1; // prepare for next run
// Skip blank lines
if (line.Length() == 0)
continue;
if ('[' == line[0]) {
rv = ProcessNewTable(line, &dbTableName,
getter_AddRefs(updateStatement),
getter_AddRefs(deleteStatement));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "malformed table line");
if (NS_SUCCEEDED(rv)) {
// Add the line to our array of table lines.
mTableUpdateLines.AppendElement(line);
}
} else {
rv = ProcessUpdateTable(line, dbTableName, updateStatement,
deleteStatement);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "malformed update line");
}
}
// Save the remaining string fragment.
mPendingStreamUpdate = Substring(updateString, cur);
return NS_OK;
}
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Finish(nsIUrlClassifierCallback *c)
{
if (!mHasPendingUpdate)
return NS_OK;
mConnection->CommitTransaction();
for (PRUint32 i = 0; i < mTableUpdateLines.Length(); ++i) {
c->HandleEvent(mTableUpdateLines[i]);
}
mTableUpdateLines.Clear();
mPendingStreamUpdate.Truncate();
mHasPendingUpdate = PR_FALSE;
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
@ -513,8 +409,7 @@ nsUrlClassifierDBServiceWorker::OpenDb()
}
nsresult
nsUrlClassifierDBServiceWorker::MaybeCreateTable(const nsCString& aTableName)
{
nsUrlClassifierDBServiceWorker::MaybeCreateTable(const nsCString& aTableName) {
LOG(("MaybeCreateTable %s\n", aTableName.get()));
nsCOMPtr<mozIStorageStatement> createStatement;
@ -531,8 +426,7 @@ nsUrlClassifierDBServiceWorker::MaybeCreateTable(const nsCString& aTableName)
void
nsUrlClassifierDBServiceWorker::GetDbTableName(const nsACString& aTableName,
nsCString* aDbTableName)
{
nsCString* aDbTableName) {
aDbTableName->Assign(aTableName);
aDbTableName->ReplaceChar('-', '_');
}
@ -674,57 +568,6 @@ nsUrlClassifierDBService::UpdateTables(const nsACString& updateString,
return proxy->UpdateTables(updateString, proxyCallback);
}
NS_IMETHODIMP
nsUrlClassifierDBService::Update(const nsACString& aUpdateChunk)
{
NS_ENSURE_TRUE(gDbBackgroundThread, NS_ERROR_NOT_INITIALIZED);
nsresult rv;
// The actual worker uses the background thread.
nsCOMPtr<nsIUrlClassifierDBServiceWorker> proxy;
rv = NS_GetProxyForObject(gDbBackgroundThread,
NS_GET_IID(nsIUrlClassifierDBServiceWorker),
mWorker,
NS_PROXY_ASYNC,
getter_AddRefs(proxy));
NS_ENSURE_SUCCESS(rv, rv);
return proxy->Update(aUpdateChunk);
}
NS_IMETHODIMP
nsUrlClassifierDBService::Finish(nsIUrlClassifierCallback *c)
{
NS_ENSURE_TRUE(gDbBackgroundThread, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIUrlClassifierCallback> wrapper =
new nsUrlClassifierCallbackWrapper(c);
NS_ENSURE_TRUE(wrapper, NS_ERROR_OUT_OF_MEMORY);
nsresult rv;
// The proxy callback uses the current thread.
nsCOMPtr<nsIUrlClassifierCallback> proxyCallback;
rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD,
NS_GET_IID(nsIUrlClassifierCallback),
wrapper,
NS_PROXY_ASYNC,
getter_AddRefs(proxyCallback));
NS_ENSURE_SUCCESS(rv, rv);
// The actual worker uses the background thread.
nsCOMPtr<nsIUrlClassifierDBServiceWorker> proxy;
rv = NS_GetProxyForObject(gDbBackgroundThread,
NS_GET_IID(nsIUrlClassifierDBServiceWorker),
mWorker,
NS_PROXY_ASYNC,
getter_AddRefs(proxy));
NS_ENSURE_SUCCESS(rv, rv);
return proxy->Finish(proxyCallback);
}
NS_IMETHODIMP
nsUrlClassifierDBService::Observe(nsISupports *aSubject, const char *aTopic,
const PRUnichar *aData)