Skip to content

Commit

Permalink
Bug 1615552 - Enhance SimpleDB to support other persistence types; r=…
Browse files Browse the repository at this point in the history
…ttung,dom-workers-and-storage-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D62058
  • Loading branch information
janvarga committed Feb 27, 2020
1 parent 48dbb3b commit 9d7855a
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dom/quota/test/unit/head-shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function getCurrentPrincipal() {
return Cc["@mozilla.org/systemprincipal;1"].createInstance(Ci.nsIPrincipal);
}

function getSimpleDatabase(principal) {
function getSimpleDatabase(principal, persistence) {
let connection = Cc["@mozilla.org/dom/sdb-connection;1"].createInstance(
Ci.nsISDBConnection
);
Expand All @@ -392,7 +392,7 @@ function getSimpleDatabase(principal) {
principal = getCurrentPrincipal();
}

connection.init(principal);
connection.init(principal, persistence);

return connection;
}
Expand Down
28 changes: 21 additions & 7 deletions dom/simpledb/ActorsParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ class Connection final : public PBackgroundSDBConnectionParent {
nsCString mOrigin;
nsString mName;

PersistenceType mPersistenceType;
bool mRunningRequest;
bool mOpen;
bool mAllowedToClose;
bool mActorDestroyed;

public:
explicit Connection(const PrincipalInfo& aPrincipalInfo);
Connection(PersistenceType aPersistenceType,
const PrincipalInfo& aPrincipalInfo);

NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::dom::Connection)

Expand All @@ -94,6 +96,8 @@ class Connection final : public PBackgroundSDBConnectionParent {
return mFileStream;
}

PersistenceType GetPersistenceType() const { return mPersistenceType; }

const PrincipalInfo& GetPrincipalInfo() const {
MOZ_ASSERT(NS_IsMainThread());

Expand Down Expand Up @@ -485,13 +489,19 @@ StaticAutoPtr<ConnectionArray> gOpenConnections;
******************************************************************************/

PBackgroundSDBConnectionParent* AllocPBackgroundSDBConnectionParent(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsOnBackgroundThread();

if (NS_WARN_IF(QuotaClient::IsShuttingDownOnBackgroundThread())) {
return nullptr;
}

if (NS_WARN_IF(aPersistenceType == PERSISTENCE_TYPE_INVALID)) {
ASSERT_UNLESS_FUZZING();
return nullptr;
}

if (NS_WARN_IF(aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo)) {
ASSERT_UNLESS_FUZZING();
return nullptr;
Expand All @@ -502,13 +512,14 @@ PBackgroundSDBConnectionParent* AllocPBackgroundSDBConnectionParent(
return nullptr;
}

RefPtr<Connection> actor = new Connection(aPrincipalInfo);
RefPtr<Connection> actor = new Connection(aPersistenceType, aPrincipalInfo);

return actor.forget().take();
}

bool RecvPBackgroundSDBConnectionConstructor(
PBackgroundSDBConnectionParent* aActor,
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);
Expand Down Expand Up @@ -608,8 +619,10 @@ StreamHelper::Run() {
* Connection
******************************************************************************/

Connection::Connection(const PrincipalInfo& aPrincipalInfo)
Connection::Connection(PersistenceType aPersistenceType,
const PrincipalInfo& aPrincipalInfo)
: mPrincipalInfo(aPrincipalInfo),
mPersistenceType(aPersistenceType),
mRunningRequest(false),
mOpen(false),
mAllowedToClose(false),
Expand Down Expand Up @@ -1103,7 +1116,8 @@ nsresult OpenOp::OpenDirectory() {
MOZ_ASSERT(QuotaManager::Get());

mState = State::DirectoryOpenPending;
QuotaManager::Get()->OpenDirectory(PERSISTENCE_TYPE_DEFAULT, mGroup, mOrigin,
QuotaManager::Get()->OpenDirectory(GetConnection()->GetPersistenceType(),
mGroup, mOrigin,
mozilla::dom::quota::Client::SDB,
/* aExclusive */ false, this);

Expand All @@ -1119,8 +1133,8 @@ nsresult OpenOp::SendToIOThread() {
return NS_ERROR_FAILURE;
}

mFileStream = new FileStream(PERSISTENCE_TYPE_DEFAULT, mGroup, mOrigin,
mozilla::dom::quota::Client::SDB);
mFileStream = new FileStream(GetConnection()->GetPersistenceType(), mGroup,
mOrigin, mozilla::dom::quota::Client::SDB);

QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
Expand Down Expand Up @@ -1152,7 +1166,7 @@ nsresult OpenOp::DatabaseWork() {

nsCOMPtr<nsIFile> dbDirectory;
nsresult rv = quotaManager->EnsureStorageAndOriginIsInitialized(
PERSISTENCE_TYPE_DEFAULT, mSuffix, mGroup, mOrigin,
GetConnection()->GetPersistenceType(), mSuffix, mGroup, mOrigin,
mozilla::dom::quota::Client::SDB, getter_AddRefs(dbDirectory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
Expand Down
4 changes: 4 additions & 0 deletions dom/simpledb/ActorsParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef mozilla_dom_simpledb_ActorsParent_h
#define mozilla_dom_simpledb_ActorsParent_h

#include "mozilla/dom/quota/PersistenceType.h"

template <class>
struct already_AddRefed;

Expand All @@ -29,10 +31,12 @@ class Client;
} // namespace quota

PBackgroundSDBConnectionParent* AllocPBackgroundSDBConnectionParent(
const mozilla::dom::quota::PersistenceType& aPersistenceType,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);

bool RecvPBackgroundSDBConnectionConstructor(
PBackgroundSDBConnectionParent* aActor,
const mozilla::dom::quota::PersistenceType& aPersistenceType,
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);

bool DeallocPBackgroundSDBConnectionParent(
Expand Down
14 changes: 12 additions & 2 deletions dom/simpledb/SDBConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ nsresult GetWriteData(JSContext* aCx, JS::Handle<JS::Value> aValue,

SDBConnection::SDBConnection()
: mBackgroundActor(nullptr),
mPersistenceType(PERSISTENCE_TYPE_INVALID),
mRunningRequest(false),
mOpen(false),
mAllowedToClose(false) {
Expand Down Expand Up @@ -176,7 +177,7 @@ nsresult SDBConnection::EnsureBackgroundActor() {

mBackgroundActor = static_cast<SDBConnectionChild*>(
backgroundActor->SendPBackgroundSDBConnectionConstructor(
actor, *mPrincipalInfo));
actor, mPersistenceType, *mPrincipalInfo));
if (NS_WARN_IF(!mBackgroundActor)) {
return NS_ERROR_FAILURE;
}
Expand Down Expand Up @@ -205,7 +206,8 @@ nsresult SDBConnection::InitiateRequest(SDBRequest* aRequest,
NS_IMPL_ISUPPORTS(SDBConnection, nsISDBConnection)

NS_IMETHODIMP
SDBConnection::Init(nsIPrincipal* aPrincipal) {
SDBConnection::Init(nsIPrincipal* aPrincipal,
const nsACString& aPersistenceType) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPrincipal);

Expand All @@ -225,7 +227,15 @@ SDBConnection::Init(nsIPrincipal* aPrincipal) {
return NS_ERROR_INVALID_ARG;
}

Nullable<PersistenceType> persistenceType;
rv = NullablePersistenceTypeFromText(aPersistenceType, &persistenceType);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_INVALID_ARG;
}

mPrincipalInfo = std::move(principalInfo);
mPersistenceType = persistenceType.IsNull() ? PERSISTENCE_TYPE_DEFAULT
: persistenceType.Value();

return NS_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions dom/simpledb/SDBConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef mozilla_dom_simpledb_SDBConnection_h
#define mozilla_dom_simpledb_SDBConnection_h

#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/UniquePtr.h"
#include "nsISDBConnection.h"
#include "nsTArray.h"
Expand All @@ -31,6 +32,7 @@ class SDBRequest;
class SDBRequestParams;

class SDBConnection final : public nsISDBConnection {
typedef mozilla::dom::quota::PersistenceType PersistenceType;
typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;

Expand All @@ -40,6 +42,7 @@ class SDBConnection final : public nsISDBConnection {

SDBConnectionChild* mBackgroundActor;

PersistenceType mPersistenceType;
bool mRunningRequest;
bool mOpen;
bool mAllowedToClose;
Expand Down
2 changes: 1 addition & 1 deletion dom/simpledb/nsISDBConnection.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface nsISDBRequest;
interface nsISDBConnection : nsISupports
{
[must_use] void
init(in nsIPrincipal aPrincipal);
init(in nsIPrincipal aPrincipal, [optional] in ACString aPersistenceType);

[must_use] nsISDBRequest
open(in AString aName);
Expand Down
1 change: 1 addition & 0 deletions ipc/glue/BackgroundChildImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ bool BackgroundChildImpl::DeallocPBackgroundIndexedDBUtilsChild(

BackgroundChildImpl::PBackgroundSDBConnectionChild*
BackgroundChildImpl::AllocPBackgroundSDBConnectionChild(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
MOZ_CRASH(
"PBackgroundSDBConnectionChild actor should be manually "
Expand Down
1 change: 1 addition & 0 deletions ipc/glue/BackgroundChildImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class BackgroundChildImpl : public PBackgroundChild,
PBackgroundIndexedDBUtilsChild* aActor) override;

virtual PBackgroundSDBConnectionChild* AllocPBackgroundSDBConnectionChild(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) override;

virtual bool DeallocPBackgroundSDBConnectionChild(
Expand Down
9 changes: 6 additions & 3 deletions ipc/glue/BackgroundParentImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,26 @@ mozilla::ipc::IPCResult BackgroundParentImpl::RecvFlushPendingFileDeletions() {

BackgroundParentImpl::PBackgroundSDBConnectionParent*
BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();

return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPrincipalInfo);
return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType,
aPrincipalInfo);
}

mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
PBackgroundSDBConnectionParent* aActor,
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) {
AssertIsInMainOrSocketProcess();
AssertIsOnBackgroundThread();
MOZ_ASSERT(aActor);

if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(aActor,
aPrincipalInfo)) {
if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(
aActor, aPersistenceType, aPrincipalInfo)) {
return IPC_FAIL_NO_REASON(this);
}
return IPC_OK();
Expand Down
2 changes: 2 additions & 0 deletions ipc/glue/BackgroundParentImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ class BackgroundParentImpl : public PBackgroundParent,
virtual mozilla::ipc::IPCResult RecvFlushPendingFileDeletions() override;

virtual PBackgroundSDBConnectionParent* AllocPBackgroundSDBConnectionParent(
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) override;

virtual mozilla::ipc::IPCResult RecvPBackgroundSDBConnectionConstructor(
PBackgroundSDBConnectionParent* aActor,
const PersistenceType& aPersistenceType,
const PrincipalInfo& aPrincipalInfo) override;

virtual bool DeallocPBackgroundSDBConnectionParent(
Expand Down
3 changes: 2 additions & 1 deletion ipc/glue/PBackground.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ parent:
// Use only for testing!
async FlushPendingFileDeletions();

async PBackgroundSDBConnection(PrincipalInfo principalInfo);
async PBackgroundSDBConnection(PersistenceType persistenceType,
PrincipalInfo principalInfo);

async PBackgroundLSDatabase(PrincipalInfo principalInfo,
uint32_t privateBrowsingId,
Expand Down

0 comments on commit 9d7855a

Please sign in to comment.