Bug 706740 - Backout bug 667075. r=dcamp

This commit is contained in:
Gian-Carlo Pascutto 2011-12-02 10:47:43 +01:00
parent c07592e6bc
commit 097a7859a1

View File

@ -62,7 +62,6 @@
#include "nsIProperties.h"
#include "nsToolkitCompsCID.h"
#include "nsIUrlClassifierUtils.h"
#include "nsIRandomGenerator.h"
#include "nsUrlClassifierDBService.h"
#include "nsUrlClassifierUtils.h"
#include "nsUrlClassifierProxies.h"
@ -488,9 +487,13 @@ public:
bool before,
nsTArray<nsUrlClassifierEntry> &entries);
// Ask the db for a random number. This is temporary, and should be
// replaced with nsIRandomGenerator when 419739 is fixed.
nsresult RandomNumber(PRInt64 *randomNum);
// Return an array with all Prefixes known
nsresult ReadPrefixes(nsTArray<PRUint32>& array, PRUint32 aKey);
protected:
nsresult ReadEntries(mozIStorageStatement *statement,
nsTArray<nsUrlClassifierEntry>& entries);
@ -509,6 +512,7 @@ protected:
nsCOMPtr<mozIStorageStatement> mLastPartialEntriesStatement;
nsCOMPtr<mozIStorageStatement> mPartialEntriesBeforeStatement;
nsCOMPtr<mozIStorageStatement> mRandomStatement;
nsCOMPtr<mozIStorageStatement> mAllPrefixStatement;
};
@ -567,7 +571,11 @@ nsUrlClassifierStore::Init(nsUrlClassifierDBServiceWorker *worker,
NS_ENSURE_SUCCESS(rv, rv);
rv = mConnection->CreateStatement
(NS_LITERAL_CSTRING("SELECT domain, partial_data, complete_data FROM ")
(NS_LITERAL_CSTRING("SELECT abs(random())"),
getter_AddRefs(mRandomStatement));
NS_ENSURE_SUCCESS(rv, rv);
rv = mConnection->CreateStatement(NS_LITERAL_CSTRING("SELECT domain, partial_data, complete_data FROM ")
+ entriesName,
getter_AddRefs(mAllPrefixStatement));
NS_ENSURE_SUCCESS(rv, rv);
@ -589,6 +597,7 @@ nsUrlClassifierStore::Close()
mPartialEntriesAfterStatement = nsnull;
mPartialEntriesBeforeStatement = nsnull;
mLastPartialEntriesStatement = nsnull;
mRandomStatement = nsnull;
mAllPrefixStatement = nsnull;
@ -773,6 +782,21 @@ nsUrlClassifierStore::ReadNoiseEntries(PRInt64 rowID,
return ReadEntries(wraparoundStatement, entries);
}
nsresult
nsUrlClassifierStore::RandomNumber(PRInt64 *randomNum)
{
mozStorageStatementScoper randScoper(mRandomStatement);
PRBool exists;
nsresult rv = mRandomStatement->ExecuteStep(&exists);
NS_ENSURE_SUCCESS(rv, rv);
if (!exists)
return NS_ERROR_NOT_AVAILABLE;
*randomNum = mRandomStatement->AsInt64(0);
return NS_OK;
}
// -------------------------------------------------------------------------
// nsUrlClassifierAddStore class implementation
@ -1767,16 +1791,9 @@ nsUrlClassifierDBServiceWorker::AddNoise(PRInt64 nearID,
return NS_OK;
}
nsCOMPtr<nsIRandomGenerator> rg =
do_GetService("@mozilla.org/security/random-generator;1");
NS_ENSURE_STATE(rg);
PRInt32 randomNum;
PRUint8 *temp;
nsresult rv = rg->GenerateRandomBytes(sizeof(randomNum), &temp);
PRInt64 randomNum;
nsresult rv = mMainStore.RandomNumber(&randomNum);
NS_ENSURE_SUCCESS(rv, rv);
memcpy(&randomNum, temp, sizeof(randomNum));
NS_Free(temp);
PRInt32 numBefore = randomNum % count;