diff --git a/dom/cache/Connection.cpp b/dom/cache/Connection.cpp index 91b2bb1882b8..f1acdb383261 100644 --- a/dom/cache/Connection.cpp +++ b/dom/cache/Connection.cpp @@ -13,6 +13,8 @@ namespace mozilla { namespace dom { namespace cache { +using mozilla::dom::quota::QuotaObject; + NS_IMPL_ISUPPORTS(cache::Connection, mozIStorageAsyncConnection, mozIStorageConnection); @@ -272,6 +274,13 @@ Connection::EnableModule(const nsACString& aModule) return mBase->EnableModule(aModule); } +NS_IMETHODIMP +Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject, + QuotaObject** aJournalQuotaObject) +{ + return mBase->GetQuotaObjects(aDatabaseQuotaObject, aJournalQuotaObject); +} + } // namespace cache } // namespace dom } // namespace mozilla diff --git a/storage/TelemetryVFS.cpp b/storage/TelemetryVFS.cpp index aad401192431..740efe8af32c 100644 --- a/storage/TelemetryVFS.cpp +++ b/storage/TelemetryVFS.cpp @@ -888,5 +888,15 @@ sqlite3_vfs* ConstructTelemetryVFS() return tvfs; } +already_AddRefed +GetQuotaObjectForFile(sqlite3_file *pFile) +{ + MOZ_ASSERT(pFile); + + telemetry_file *p = (telemetry_file *)pFile; + RefPtr result = p->quotaObject; + return result.forget(); +} + } // namespace storage } // namespace mozilla diff --git a/storage/mozIStorageConnection.idl b/storage/mozIStorageConnection.idl index df6b18ce0145..137dbd8d6d10 100644 --- a/storage/mozIStorageConnection.idl +++ b/storage/mozIStorageConnection.idl @@ -6,6 +6,19 @@ #include "nsISupports.idl" #include "mozIStorageAsyncConnection.idl" +%{C++ +namespace mozilla { +namespace dom { +namespace quota { +class QuotaObject; +} +} +} + +%} + +[ptr] native QuotaObject(mozilla::dom::quota::QuotaObject); + interface mozIStorageAggregateFunction; interface mozIStorageCompletionCallback; interface mozIStorageFunction; @@ -238,4 +251,17 @@ interface mozIStorageConnection : mozIStorageAsyncConnection { * For unknown module names. */ [noscript] void enableModule(in ACString aModuleName); + + /** + * Get quota objects. + * + * @param[out] aDatabaseQuotaObject + * The QuotaObject associated with the database file. + * @param[out] aJournalQuotaObject + * The QuotaObject associated with the journal file. + * + * @throws NS_ERROR_NOT_INITIALIZED. + */ + [noscript] void getQuotaObjects(out QuotaObject aDatabaseQuotaObject, + out QuotaObject aJournalQuotaObject); }; diff --git a/storage/mozStorageConnection.cpp b/storage/mozStorageConnection.cpp index f303620551ad..ad76b7deca19 100644 --- a/storage/mozStorageConnection.cpp +++ b/storage/mozStorageConnection.cpp @@ -19,6 +19,7 @@ #include "mozilla/Attributes.h" #include "mozilla/ErrorNames.h" #include "mozilla/unused.h" +#include "mozilla/dom/quota/QuotaObject.h" #include "mozIStorageAggregateFunction.h" #include "mozIStorageCompletionCallback.h" @@ -67,6 +68,8 @@ mozilla::LazyLogModule gStorageLog("mozStorage"); namespace mozilla { namespace storage { +using mozilla::dom::quota::QuotaObject; + namespace { int @@ -1915,5 +1918,46 @@ Connection::EnableModule(const nsACString& aModuleName) return NS_ERROR_FAILURE; } +// Implemented in TelemetryVFS.cpp +already_AddRefed +GetQuotaObjectForFile(sqlite3_file *pFile); + +NS_IMETHODIMP +Connection::GetQuotaObjects(QuotaObject** aDatabaseQuotaObject, + QuotaObject** aJournalQuotaObject) +{ + MOZ_ASSERT(aDatabaseQuotaObject); + MOZ_ASSERT(aJournalQuotaObject); + + if (!mDBConn) { + return NS_ERROR_NOT_INITIALIZED; + } + + sqlite3_file* file; + int srv = ::sqlite3_file_control(mDBConn, + nullptr, + SQLITE_FCNTL_FILE_POINTER, + &file); + if (srv != SQLITE_OK) { + return convertResultCode(srv); + } + + RefPtr databaseQuotaObject = GetQuotaObjectForFile(file); + + srv = ::sqlite3_file_control(mDBConn, + nullptr, + SQLITE_FCNTL_JOURNAL_POINTER, + &file); + if (srv != SQLITE_OK) { + return convertResultCode(srv); + } + + RefPtr journalQuotaObject = GetQuotaObjectForFile(file); + + databaseQuotaObject.forget(aDatabaseQuotaObject); + journalQuotaObject.forget(aJournalQuotaObject); + return NS_OK; +} + } // namespace storage } // namespace mozilla