Commit 7bb929b8 authored by Jan Varga's avatar Jan Varga
Browse files

Bug 1182987 - Part 2: Add getQuotaObjects() to mozIStorageConnection; r=mak

parent f3d631ab
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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
+10 −0
Original line number Diff line number Diff line
@@ -888,5 +888,15 @@ sqlite3_vfs* ConstructTelemetryVFS()
  return tvfs;
}

already_AddRefed<QuotaObject>
GetQuotaObjectForFile(sqlite3_file *pFile)
{
  MOZ_ASSERT(pFile);

  telemetry_file *p = (telemetry_file *)pFile;
  RefPtr<QuotaObject> result = p->quotaObject;
  return result.forget();
}

} // namespace storage
} // namespace mozilla
+26 −0
Original line number Diff line number Diff line
@@ -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);
};
+44 −0
Original line number Diff line number Diff line
@@ -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<QuotaObject>
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<QuotaObject> databaseQuotaObject = GetQuotaObjectForFile(file);

  srv = ::sqlite3_file_control(mDBConn,
                               nullptr,
                               SQLITE_FCNTL_JOURNAL_POINTER,
                               &file);
  if (srv != SQLITE_OK) {
    return convertResultCode(srv);
  }

  RefPtr<QuotaObject> journalQuotaObject = GetQuotaObjectForFile(file);

  databaseQuotaObject.forget(aDatabaseQuotaObject);
  journalQuotaObject.forget(aJournalQuotaObject);
  return NS_OK;
}

} // namespace storage
} // namespace mozilla