forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1841012 - Ensure OPFS transactions are started with a factory met…
…hod. r=dom-storage-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D182489
- Loading branch information
1 parent
75c7895
commit 165460d
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */ | ||
/* 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 "StartedTransaction.h" | ||
|
||
#include "ResultConnection.h" | ||
#include "mozilla/dom/quota/QuotaCommon.h" | ||
#include "mozilla/dom/quota/ResultExtensions.h" | ||
|
||
namespace mozilla::dom::fs { | ||
|
||
/* static */ | ||
Result<StartedTransaction, QMResult> StartedTransaction::Create( | ||
const ResultConnection& aConn) { | ||
auto transaction = MakeUnique<mozStorageTransaction>( | ||
aConn.get(), /* aCommitOnComplete */ false, | ||
mozIStorageConnection::TRANSACTION_IMMEDIATE); | ||
|
||
QM_TRY(QM_TO_RESULT(transaction->Start())); | ||
|
||
return StartedTransaction(std::move(transaction)); | ||
} | ||
|
||
nsresult StartedTransaction::Commit() { return mTransaction->Commit(); } | ||
|
||
nsresult StartedTransaction::Rollback() { return mTransaction->Rollback(); } | ||
|
||
StartedTransaction::StartedTransaction( | ||
UniquePtr<mozStorageTransaction>&& aTransaction) | ||
: mTransaction(std::move(aTransaction)) {} | ||
|
||
} // namespace mozilla::dom::fs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | ||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */ | ||
/* 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/. */ | ||
|
||
#ifndef DOM_FS_PARENT_STARTEDTRANSACTION_H_ | ||
#define DOM_FS_PARENT_STARTEDTRANSACTION_H_ | ||
|
||
#include "ResultConnection.h" | ||
#include "mozStorageHelper.h" | ||
#include "mozilla/dom/QMResult.h" | ||
|
||
namespace mozilla::dom::fs { | ||
|
||
class StartedTransaction { | ||
public: | ||
static Result<StartedTransaction, QMResult> Create( | ||
const ResultConnection& aConn); | ||
|
||
StartedTransaction(StartedTransaction&& aOther) = default; | ||
|
||
StartedTransaction(const StartedTransaction& aOther) = delete; | ||
|
||
nsresult Commit(); | ||
|
||
nsresult Rollback(); | ||
|
||
~StartedTransaction() = default; | ||
|
||
private: | ||
explicit StartedTransaction(UniquePtr<mozStorageTransaction>&& aTransaction); | ||
|
||
UniquePtr<mozStorageTransaction> mTransaction; | ||
}; | ||
|
||
} // namespace mozilla::dom::fs | ||
|
||
#endif // DOM_FS_PARENT_STARTEDTRANSACTION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters