Backed out 3 changesets (bug 1638256) for causing GTest failures CLOSED TREE

Backed out changeset 556614d4b90a (bug 1638256)
Backed out changeset dfd4d3679ccf (bug 1638256)
Backed out changeset 30c66c06f6ce (bug 1638256)
This commit is contained in:
Norisz Fay 2023-06-21 22:41:40 +03:00
Родитель 67d28b87b2
Коммит 45e83e3152
10 изменённых файлов: 72 добавлений и 405 удалений

Просмотреть файл

@ -18,21 +18,6 @@ interface nsIPropertyBag2;
interface nsIVariant;
interface mozIStorageCompletionCallback;
/**
* PRIVACY WARNING
* ===============
*
* Database file names can be exposed through telemetry and in crash reports on
* the https://crash-stats.mozilla.org site, to allow recognizing the affected
* database.
* if your database name may contain privacy sensitive information, e.g. an
* URL origin, you should use openDatabaseWithFileURL and pass an explicit
* TelemetryFilename to it. That name will be used both for telemetry and for
* thread names in crash reports.
* If you have different needs (e.g. using the javascript module or an async
* connection from the main thread) please coordinate with the mozStorage peers.
*/
/**
* The mozIStorageService interface is intended to be implemented by
* a service that can create storage connections (mozIStorageConnection)

Просмотреть файл

@ -4,13 +4,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsError.h"
#include "nsThreadUtils.h"
#include "nsIFile.h"
#include "nsIFileURL.h"
#include "nsIXPConnect.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Telemetry.h"
#include "mozilla/Mutex.h"
#include "mozilla/CondVar.h"
@ -39,13 +37,10 @@
#include "FileSystemModule.h"
#include "mozStorageHelper.h"
#include "mozilla/Assertions.h"
#include "mozilla/Logging.h"
#include "mozilla/Printf.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/RefPtr.h"
#include "nsProxyRelease.h"
#include "nsStringFwd.h"
#include "nsURLHelper.h"
#define MIN_AVAILABLE_BYTES_PER_CHUNKED_GROWTH 524288000 // 500 MiB
@ -139,22 +134,15 @@ int sqlite3_T_double(sqlite3_context* aCtx, double aValue) {
}
int sqlite3_T_text(sqlite3_context* aCtx, const nsCString& aValue) {
CheckedInt<int32_t> length(aValue.Length());
if (!length.isValid()) {
return SQLITE_MISUSE;
}
::sqlite3_result_text(aCtx, aValue.get(), length.value(), SQLITE_TRANSIENT);
::sqlite3_result_text(aCtx, aValue.get(), aValue.Length(), SQLITE_TRANSIENT);
return SQLITE_OK;
}
int sqlite3_T_text16(sqlite3_context* aCtx, const nsString& aValue) {
CheckedInt<int32_t> n_bytes =
CheckedInt<int32_t>(aValue.Length()) * sizeof(char16_t);
if (!n_bytes.isValid()) {
return SQLITE_MISUSE;
}
::sqlite3_result_text16(aCtx, aValue.get(), n_bytes.value(),
SQLITE_TRANSIENT);
::sqlite3_result_text16(
aCtx, aValue.get(),
aValue.Length() * sizeof(char16_t), // Number of bytes.
SQLITE_TRANSIENT);
return SQLITE_OK;
}
@ -584,8 +572,7 @@ class AsyncVacuumEvent final : public Runnable {
Connection::Connection(Service* aService, int aFlags,
ConnectionOperation aSupportedOperations,
const nsCString& aTelemetryFilename, bool aInterruptible,
bool aIgnoreLockingMode)
bool aInterruptible, bool aIgnoreLockingMode)
: sharedAsyncExecutionMutex("Connection::sharedAsyncExecutionMutex"),
sharedDBMutex("Connection::sharedDBMutex"),
eventTargetOpenedOn(WrapNotNull(GetCurrentSerialEventTarget())),
@ -607,9 +594,6 @@ Connection::Connection(Service* aService, int aFlags,
MOZ_ASSERT(!mIgnoreLockingMode || mFlags & SQLITE_OPEN_READONLY,
"Can't ignore locking for a non-readonly connection!");
mStorageService->registerConnection(this);
MOZ_ASSERT(!aTelemetryFilename.IsEmpty(),
"A telemetry filename should have been passed-in.");
mTelemetryFilename.Assign(aTelemetryFilename);
}
Connection::~Connection() {
@ -715,15 +699,8 @@ nsIEventTarget* Connection::getAsyncExecutionTarget() {
// Create the async event target if there's none yet.
if (!mAsyncExecutionThread) {
// Names start with "sqldb:" followed by a recognizable name, like the
// database file name, or a specially crafted name like "memory".
// This name will be surfaced on https://crash-stats.mozilla.org, so any
// sensitive part of the file name (e.g. an URL origin) should be replaced
// by passing an explicit telemetryName to openDatabaseWithFileURL.
nsAutoCString name("sqldb:"_ns);
name.Append(mTelemetryFilename);
static nsThreadPoolNaming naming;
nsresult rv = NS_NewNamedThread(naming.GetNextThreadName(name),
nsresult rv = NS_NewNamedThread(naming.GetNextThreadName("mozStorage"),
getter_AddRefs(mAsyncExecutionThread));
if (NS_FAILED(rv)) {
NS_WARNING("Failed to create async thread.");
@ -846,6 +823,8 @@ nsresult Connection::initialize(const nsACString& aStorageKey,
mName.IsEmpty() ? nsAutoCString(":memory:"_ns)
: "file:"_ns + mName + "?mode=memory&cache=shared"_ns;
mTelemetryFilename.AssignLiteral(":memory:");
int srv =
::sqlite3_open_v2(path.get(), &mDBConn, mFlags, GetBaseVFSName(true));
if (srv != SQLITE_OK) {
@ -881,6 +860,7 @@ nsresult Connection::initialize(nsIFile* aDatabaseFile) {
// Do not set mFileURL here since this is database does not have an associated
// URL.
mDatabaseFile = aDatabaseFile;
aDatabaseFile->GetNativeLeafName(mTelemetryFilename);
nsAutoString path;
nsresult rv = aDatabaseFile->GetPath(path);
@ -929,7 +909,8 @@ nsresult Connection::initialize(nsIFile* aDatabaseFile) {
return NS_OK;
}
nsresult Connection::initialize(nsIFileURL* aFileURL) {
nsresult Connection::initialize(nsIFileURL* aFileURL,
const nsACString& aTelemetryFilename) {
NS_ASSERTION(aFileURL, "Passed null file URL!");
NS_ASSERTION(!connectionReady(),
"Initialize called on already opened database!");
@ -943,6 +924,12 @@ nsresult Connection::initialize(nsIFileURL* aFileURL) {
mFileURL = aFileURL;
mDatabaseFile = databaseFile;
if (!aTelemetryFilename.IsEmpty()) {
mTelemetryFilename = aTelemetryFilename;
} else {
databaseFile->GetNativeLeafName(mTelemetryFilename);
}
nsAutoCString spec;
rv = aFileURL->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
@ -1003,6 +990,9 @@ nsresult Connection::initializeInternal() {
"SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER should be enabled");
#endif
MOZ_ASSERT(!mTelemetryFilename.IsEmpty(),
"A telemetry filename should have been set by now.");
// Properly wrap the database handle's mutex.
sharedDBMutex.initWithMutex(sqlite3_db_mutex(mDBConn));
@ -1403,9 +1393,8 @@ int Connection::stepStatement(sqlite3* aNativeConnection,
: Telemetry::kSlowSQLThresholdForHelperThreads;
if (duration.ToMilliseconds() >= threshold) {
nsDependentCString statementString(::sqlite3_sql(aStatement));
Telemetry::RecordSlowSQLStatement(
statementString, mTelemetryFilename,
static_cast<uint32_t>(duration.ToMilliseconds()));
Telemetry::RecordSlowSQLStatement(statementString, mTelemetryFilename,
duration.ToMilliseconds());
}
(void)::sqlite3_extended_result_codes(aNativeConnection, 0);
@ -1483,9 +1472,8 @@ int Connection::executeSql(sqlite3* aNativeConnection, const char* aSqlString) {
: Telemetry::kSlowSQLThresholdForHelperThreads;
if (duration.ToMilliseconds() >= threshold) {
nsDependentCString statementString(aSqlString);
Telemetry::RecordSlowSQLStatement(
statementString, mTelemetryFilename,
static_cast<uint32_t>(duration.ToMilliseconds()));
Telemetry::RecordSlowSQLStatement(statementString, mTelemetryFilename,
duration.ToMilliseconds());
}
return srv;
@ -1726,7 +1714,7 @@ Connection::AsyncClone(bool aReadOnly,
// The cloned connection will still implement the synchronous API, but throw
// if any synchronous methods are called on the main thread.
RefPtr<Connection> clone =
new Connection(mStorageService, flags, ASYNCHRONOUS, mTelemetryFilename);
new Connection(mStorageService, flags, ASYNCHRONOUS);
RefPtr<AsyncInitializeClone> initEvent =
new AsyncInitializeClone(this, clone, aReadOnly, aCallback);
@ -1745,7 +1733,7 @@ nsresult Connection::initializeClone(Connection* aClone, bool aReadOnly) {
if (!mStorageKey.IsEmpty()) {
rv = aClone->initialize(mStorageKey, mName);
} else if (mFileURL) {
rv = aClone->initialize(mFileURL);
rv = aClone->initialize(mFileURL, mTelemetryFilename);
} else {
rv = aClone->initialize(mDatabaseFile);
}
@ -1890,9 +1878,8 @@ Connection::Clone(bool aReadOnly, mozIStorageConnection** _connection) {
flags = (~SQLITE_OPEN_CREATE & flags);
}
RefPtr<Connection> clone =
new Connection(mStorageService, flags, mSupportedOperations,
mTelemetryFilename, mInterruptible);
RefPtr<Connection> clone = new Connection(
mStorageService, flags, mSupportedOperations, mInterruptible);
rv = initializeClone(clone, aReadOnly);
if (NS_FAILED(rv)) {
@ -2070,9 +2057,8 @@ Connection::GetSchemaVersion(int32_t* _version) {
*_version = 0;
bool hasResult;
if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
if (NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult)
*_version = stmt->AsInt32(0);
}
return NS_OK;
}

Просмотреть файл

@ -32,7 +32,8 @@ class nsIEventTarget;
class nsISerialEventTarget;
class nsIThread;
namespace mozilla::storage {
namespace mozilla {
namespace storage {
class Connection final : public mozIStorageConnection,
public nsIInterfaceRequestor {
@ -84,8 +85,7 @@ class Connection final : public mozIStorageConnection,
*/
Connection(Service* aService, int aFlags,
ConnectionOperation aSupportedOperations,
const nsCString& aTelemetryFilename, bool aInterruptible = false,
bool aIgnoreLockingMode = false);
bool aInterruptible = false, bool aIgnoreLockingMode = false);
/**
* Creates the connection to an in-memory database.
@ -108,7 +108,8 @@ class Connection final : public mozIStorageConnection,
* The nsIFileURL of the location of the database to open, or create if
* it does not exist.
*/
nsresult initialize(nsIFileURL* aFileURL);
nsresult initialize(nsIFileURL* aFileURL,
const nsACString& aTelemetryFilename);
/**
* Same as initialize, but to be used on the async thread.
@ -185,7 +186,7 @@ class Connection final : public mozIStorageConnection,
/**
* Closes the SQLite database, and warns about any non-finalized statements.
*/
nsresult internalClose(sqlite3* aNativeconnection);
nsresult internalClose(sqlite3* aDBConn);
/**
* Shuts down the passed-in async thread.
@ -546,7 +547,8 @@ class CallbackComplete final : public Runnable {
RefPtr<mozIStorageCompletionCallback> mCallback;
};
} // namespace mozilla::storage
} // namespace storage
} // namespace mozilla
/**
* Casting Connection to nsISupports is ambiguous.

Просмотреть файл

@ -7,8 +7,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/SpinEventLoopUntil.h"
#include "nsIFile.h"
#include "nsIFileURL.h"
#include "mozStorageService.h"
#include "mozStorageConnection.h"
#include "nsComponentManagerUtils.h"
@ -36,7 +35,8 @@
using mozilla::intl::Collator;
namespace mozilla::storage {
namespace mozilla {
namespace storage {
////////////////////////////////////////////////////////////////////////////////
//// Memory Reporting
@ -147,7 +147,7 @@ Service::CollectReports(nsIHandleReportCallback* aHandleReport,
#endif
}
int64_t other = static_cast<int64_t>(::sqlite3_memory_used() - totalConnSize);
int64_t other = ::sqlite3_memory_used() - totalConnSize;
MOZ_COLLECT_REPORT("explicit/storage/sqlite/other", KIND_HEAP, UNITS_BYTES,
other, "All unclassified sqlite memory.");
@ -202,8 +202,7 @@ Service::AutoVFSRegistration::~AutoVFSRegistration() {
Service::Service()
: mMutex("Service::mMutex"),
mRegistrationMutex("Service::mRegistrationMutex"),
mConnections(),
mLastSensitivity(mozilla::intl::Collator::Sensitivity::Base) {}
mConnections() {}
Service::~Service() {
mozilla::UnregisterWeakMemoryReporter(this);
@ -376,8 +375,8 @@ nsresult Service::initialize() {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
for (auto& sObserverTopic : sObserverTopics) {
nsresult rv = os->AddObserver(this, sObserverTopic, false);
for (size_t i = 0; i < ArrayLength(sObserverTopics); ++i) {
nsresult rv = os->AddObserver(this, sObserverTopics[i], false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -469,8 +468,8 @@ Service::OpenSpecialDatabase(const nsACString& aStorageKey,
}
RefPtr<Connection> msc =
new Connection(this, flags, Connection::SYNCHRONOUS,
kMozStorageMemoryStorageKey, interruptible);
new Connection(this, flags, Connection::SYNCHRONOUS, interruptible);
const nsresult rv = msc->initialize(aStorageKey, aName);
NS_ENSURE_SUCCESS(rv, rv);
@ -589,15 +588,8 @@ Service::OpenAsyncDatabase(nsIVariant* aDatabaseStore, uint32_t aOpenFlags,
}
// Create connection on this thread, but initialize it on its helper thread.
nsAutoCString telemetryFilename;
if (!storageFile) {
telemetryFilename.Assign(kMozStorageMemoryStorageKey);
} else {
rv = storageFile->GetNativeLeafName(telemetryFilename);
NS_ENSURE_SUCCESS(rv, rv);
}
RefPtr<Connection> msc =
new Connection(this, flags, Connection::ASYNCHRONOUS, telemetryFilename,
new Connection(this, flags, Connection::ASYNCHRONOUS,
/* interruptible */ true, ignoreLockingMode);
nsCOMPtr<nsIEventTarget> target = msc->getAsyncExecutionTarget();
MOZ_ASSERT(target,
@ -620,12 +612,10 @@ Service::OpenDatabase(nsIFile* aDatabaseFile, uint32_t aConnectionFlags,
// reasons.
const int flags =
SQLITE_OPEN_READWRITE | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_CREATE;
nsAutoCString telemetryFilename;
nsresult rv = aDatabaseFile->GetNativeLeafName(telemetryFilename);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<Connection> msc = new Connection(this, flags, Connection::SYNCHRONOUS,
telemetryFilename, interruptible);
rv = msc->initialize(aDatabaseFile);
RefPtr<Connection> msc =
new Connection(this, flags, Connection::SYNCHRONOUS, interruptible);
const nsresult rv = msc->initialize(aDatabaseFile);
NS_ENSURE_SUCCESS(rv, rv);
msc.forget(_connection);
@ -644,12 +634,10 @@ Service::OpenUnsharedDatabase(nsIFile* aDatabaseFile, uint32_t aConnectionFlags,
// reasons.
const int flags =
SQLITE_OPEN_READWRITE | SQLITE_OPEN_PRIVATECACHE | SQLITE_OPEN_CREATE;
nsAutoCString telemetryFilename;
nsresult rv = aDatabaseFile->GetNativeLeafName(telemetryFilename);
NS_ENSURE_SUCCESS(rv, rv);
RefPtr<Connection> msc = new Connection(this, flags, Connection::SYNCHRONOUS,
telemetryFilename, interruptible);
rv = msc->initialize(aDatabaseFile);
RefPtr<Connection> msc =
new Connection(this, flags, Connection::SYNCHRONOUS, interruptible);
const nsresult rv = msc->initialize(aDatabaseFile);
NS_ENSURE_SUCCESS(rv, rv);
msc.forget(_connection);
@ -670,20 +658,10 @@ Service::OpenDatabaseWithFileURL(nsIFileURL* aFileURL,
// reasons.
const int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_SHAREDCACHE |
SQLITE_OPEN_CREATE | SQLITE_OPEN_URI;
nsresult rv;
nsAutoCString telemetryFilename;
if (!aTelemetryFilename.IsEmpty()) {
telemetryFilename = aTelemetryFilename;
} else {
nsCOMPtr<nsIFile> databaseFile;
rv = aFileURL->GetFile(getter_AddRefs(databaseFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = databaseFile->GetNativeLeafName(telemetryFilename);
NS_ENSURE_SUCCESS(rv, rv);
}
RefPtr<Connection> msc = new Connection(this, flags, Connection::SYNCHRONOUS,
telemetryFilename, interruptible);
rv = msc->initialize(aFileURL);
RefPtr<Connection> msc =
new Connection(this, flags, Connection::SYNCHRONOUS, interruptible);
const nsresult rv = msc->initialize(aFileURL, aTelemetryFilename);
NS_ENSURE_SUCCESS(rv, rv);
msc.forget(_connection);
@ -741,8 +719,8 @@ Service::Observe(nsISupports*, const char* aTopic, const char16_t*) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
for (auto& sObserverTopic : sObserverTopics) {
(void)os->RemoveObserver(this, sObserverTopic);
for (size_t i = 0; i < ArrayLength(sObserverTopics); ++i) {
(void)os->RemoveObserver(this, sObserverTopics[i]);
}
SpinEventLoopUntil("storage::Service::Observe(xpcom-shutdown-threads)"_ns,
@ -780,4 +758,5 @@ Service::Observe(nsISupports*, const char* aTopic, const char16_t*) {
return NS_OK;
}
} // namespace mozilla::storage
} // namespace storage
} // namespace mozilla

Просмотреть файл

@ -24,7 +24,8 @@ namespace mozilla::intl {
class Collator;
}
namespace mozilla::storage {
namespace mozilla {
namespace storage {
class Connection;
class Service : public mozIStorageService,
@ -178,6 +179,7 @@ class Service : public mozIStorageService,
mozilla::intl::Collator::Sensitivity mLastSensitivity;
};
} // namespace mozilla::storage
} // namespace storage
} // namespace mozilla
#endif /* MOZSTORAGESERVICE_H */

Просмотреть файл

@ -8,7 +8,6 @@ UNIFIED_SOURCES += [
"storage_test_harness.cpp",
"test_AsXXX_helpers.cpp",
"test_async_callbacks_with_spun_event_loops.cpp",
"test_async_thread_naming.cpp",
"test_asyncStatementExecution_transaction.cpp",
"test_binding_params.cpp",
"test_file_perms.cpp",

Просмотреть файл

@ -105,28 +105,6 @@ void AsyncStatementSpinner::SpinUntilCompleted() {
#define NS_DECL_ASYNCSTATEMENTSPINNER \
NS_IMETHOD HandleResult(mozIStorageResultSet* aResultSet) override;
NS_IMPL_ISUPPORTS(AsyncCompletionSpinner, mozIStorageCompletionCallback)
AsyncCompletionSpinner::AsyncCompletionSpinner()
: mCompletionReason(NS_OK), mCompleted(false) {}
NS_IMETHODIMP
AsyncCompletionSpinner::Complete(nsresult reason, nsISupports* value) {
mCompleted = true;
mCompletionReason = reason;
mCompletionValue = value;
return NS_OK;
}
void AsyncCompletionSpinner::SpinUntilCompleted() {
nsCOMPtr<nsIThread> thread(::do_GetCurrentThread());
nsresult rv = NS_OK;
bool processed = true;
while (!mCompleted && NS_SUCCEEDED(rv)) {
rv = thread->ProcessNextEvent(true, &processed);
}
}
////////////////////////////////////////////////////////////////////////////////
//// Async Helpers
@ -186,18 +164,16 @@ nsIThread* last_non_watched_thread = nullptr;
* call the real mutex function.
*/
extern "C" void wrapped_MutexEnter(sqlite3_mutex* mutex) {
if (PR_GetCurrentThread() == watched_thread) {
if (PR_GetCurrentThread() == watched_thread)
mutex_used_on_watched_thread = true;
} else {
else
last_non_watched_thread = NS_GetCurrentThread();
}
orig_mutex_methods.xMutexEnter(mutex);
}
extern "C" int wrapped_MutexTry(sqlite3_mutex* mutex) {
if (::PR_GetCurrentThread() == watched_thread) {
if (::PR_GetCurrentThread() == watched_thread)
mutex_used_on_watched_thread = true;
}
return orig_mutex_methods.xMutexTry(mutex);
}

Просмотреть файл

@ -66,24 +66,7 @@ class AsyncStatementSpinner : public mozIStorageStatementCallback,
uint16_t completionReason;
protected:
virtual ~AsyncStatementSpinner() = default;
volatile bool mCompleted;
};
class AsyncCompletionSpinner : public mozIStorageCompletionCallback {
public:
NS_DECL_ISUPPORTS
NS_DECL_MOZISTORAGECOMPLETIONCALLBACK
AsyncCompletionSpinner();
void SpinUntilCompleted();
nsresult mCompletionReason;
nsCOMPtr<nsISupports> mCompletionValue;
protected:
virtual ~AsyncCompletionSpinner() = default;
virtual ~AsyncStatementSpinner() {}
volatile bool mCompleted;
};

Просмотреть файл

@ -1,230 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsVariant.h"
#include "storage_test_harness.h"
#include "nsThreadUtils.h"
#include "nsIURI.h"
#include "nsIFileURL.h"
#include "nsIVariant.h"
#include "nsNetUtil.h"
////////////////////////////////////////////////////////////////////////////////
//// Tests
TEST(storage_async_thread_naming, MemoryDatabase)
{
HookSqliteMutex hook;
nsCOMPtr<mozIStorageConnection> db(getMemoryDatabase());
nsCOMPtr<nsIThread> target(get_conn_async_thread(db));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
printf("%s", name.get());
do_check_true(StringBeginsWith(name, "sqldb:memory"_ns));
blocking_async_close(db);
}
TEST(storage_async_thread_naming, FileDatabase)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<mozIStorageService> ss = getService();
nsCOMPtr<mozIStorageConnection> conn;
do_check_success(ss->OpenDatabase(dbFile, 0, getter_AddRefs(conn)));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
{
nsCOMPtr<mozIStorageConnection> clone;
do_check_success(conn->Clone(true, getter_AddRefs(clone)));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(clone);
}
blocking_async_close(conn);
}
TEST(storage_async_thread_naming, FileUnsharedDatabase)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<mozIStorageService> ss = getService();
nsCOMPtr<mozIStorageConnection> conn;
do_check_success(ss->OpenUnsharedDatabase(dbFile, 0, getter_AddRefs(conn)));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(conn);
}
TEST(storage_async_thread_naming, FileURLDatabase)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<nsIURI> uri;
do_check_success(NS_NewFileURI(getter_AddRefs(uri), dbFile));
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(uri);
nsCOMPtr<mozIStorageService> ss = getService();
nsCOMPtr<mozIStorageConnection> conn;
do_check_success(ss->OpenDatabaseWithFileURL(fileUrl, EmptyCString(), 0,
getter_AddRefs(conn)));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(conn);
}
TEST(storage_async_thread_naming, OverrideFileURLDatabase)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<nsIURI> uri;
do_check_success(NS_NewFileURI(getter_AddRefs(uri), dbFile));
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(uri);
nsCOMPtr<mozIStorageService> ss = getService();
nsCOMPtr<mozIStorageConnection> conn;
nsAutoCString override("override"_ns);
do_check_success(
ss->OpenDatabaseWithFileURL(fileUrl, override, 0, getter_AddRefs(conn)));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(override);
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(conn);
}
TEST(storage_async_thread_naming, AsyncOpenDatabase)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<mozIStorageService> ss = getService();
RefPtr<AsyncCompletionSpinner> completionSpinner =
new AsyncCompletionSpinner();
RefPtr<nsVariant> variant = new nsVariant();
variant->SetAsInterface(NS_GET_IID(nsIFile), dbFile);
do_check_success(ss->OpenAsyncDatabase(variant, 0, 0, completionSpinner));
completionSpinner->SpinUntilCompleted();
nsCOMPtr<mozIStorageConnection> conn(
do_QueryInterface(completionSpinner->mCompletionValue));
nsCOMPtr<nsIThread> target(get_conn_async_thread(conn));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(conn);
}
TEST(storage_async_thread_naming, AsyncClone)
{
HookSqliteMutex hook;
nsAutoString filename(u"test_thread_name.sqlite"_ns);
nsCOMPtr<nsIFile> dbFile;
do_check_success(NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(dbFile)));
do_check_success(dbFile->Append(filename));
nsCOMPtr<mozIStorageService> ss = getService();
nsCOMPtr<mozIStorageConnection> conn;
do_check_success(ss->OpenDatabase(dbFile, 0, getter_AddRefs(conn)));
RefPtr<AsyncCompletionSpinner> completionSpinner =
new AsyncCompletionSpinner();
RefPtr<nsVariant> variant = new nsVariant();
variant->SetAsInterface(NS_GET_IID(nsIFile), dbFile);
do_check_success(conn->AsyncClone(true, completionSpinner));
completionSpinner->SpinUntilCompleted();
nsCOMPtr<mozIStorageConnection> clone(
do_QueryInterface(completionSpinner->mCompletionValue));
nsCOMPtr<nsIThread> target(get_conn_async_thread(clone));
do_check_true(target);
PRThread* prThread;
target->GetPRThread(&prThread);
do_check_true(prThread);
nsAutoCString name(PR_GetThreadName(prThread));
nsAutoCString expected("sqldb:"_ns);
expected.Append(NS_ConvertUTF16toUTF8(filename));
do_check_true(StringBeginsWith(name, expected));
blocking_async_close(conn);
blocking_async_close(clone);
}

Просмотреть файл

@ -2,21 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* PRIVACY WARNING
* ===============
*
* Database file names can be exposed through telemetry and in crash reports on
* the https://crash-stats.mozilla.org site, to allow recognizing the affected
* database.
* if your database name may contain privacy sensitive information, e.g. an
* URL origin, you should use openDatabaseWithFileURL and pass an explicit
* TelemetryFilename to it. That name will be used both for telemetry and for
* thread names in crash reports.
* If you have different needs (e.g. using the javascript module or an async
* connection from the main thread) please coordinate with the mozStorage peers.
*/
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";