2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-15 16:38:48 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
#include "StorageIPC.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
#include "StorageManager.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2013-06-03 14:14:37 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2013-05-10 18:20:05 +04:00
|
|
|
#include "nsIDiskSpaceWatcher.h"
|
2013-09-24 01:30:40 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Child
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_IMPL_ADDREF(StorageDBChild)
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_IMETHODIMP_(MozExternalRefCountType) StorageDBChild::Release(void)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
|
|
nsrefcnt count = --mRefCnt;
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_LOG_RELEASE(this, count, "StorageDBChild");
|
2013-04-15 16:38:48 +04:00
|
|
|
if (count == 1 && mIPCOpen) {
|
|
|
|
Send__delete__(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
|
|
|
mRefCnt = 1;
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AddIPDLReference()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIPCOpen, "Attempting to retain multiple IPDL references");
|
2013-04-15 16:38:48 +04:00
|
|
|
mIPCOpen = true;
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::ReleaseIPDLReference()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mIPCOpen, "Attempting to release non-existent IPDL reference");
|
2013-04-15 16:38:48 +04:00
|
|
|
mIPCOpen = false;
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::StorageDBChild(DOMLocalStorageManager* aManager)
|
2013-04-15 16:38:48 +04:00
|
|
|
: mManager(aManager)
|
|
|
|
, mStatus(NS_OK)
|
|
|
|
, mIPCOpen(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::~StorageDBChild()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTHashtable<nsCStringHashKey>&
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::OriginsHavingData()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-01-05 15:25:00 +03:00
|
|
|
if (!mOriginsHavingData) {
|
|
|
|
mOriginsHavingData = new nsTHashtable<nsCStringHashKey>;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
return *mOriginsHavingData;
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::Init()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
ContentChild* child = ContentChild::GetSingleton();
|
|
|
|
AddIPDLReference();
|
|
|
|
child->SendPStorageConstructor(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::Shutdown()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
// There is nothing to do here, IPC will release automatically and
|
|
|
|
// the actual thread running on the parent process will also stop
|
|
|
|
// automatically in profile-before-change topic observer.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncPreload(StorageCacheBridge* aCache, bool aPriority)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (mIPCOpen) {
|
|
|
|
// Adding ref to cache for the time of preload. This ensures a reference to
|
|
|
|
// to the cache and that all keys will load into this cache object.
|
|
|
|
mLoadingCaches.PutEntry(aCache);
|
2017-01-04 16:53:01 +03:00
|
|
|
SendAsyncPreload(aCache->OriginSuffix(), aCache->OriginNoSuffix(),
|
|
|
|
aPriority);
|
2013-04-15 16:38:48 +04:00
|
|
|
} else {
|
|
|
|
// No IPC, no love. But the LoadDone call is expected.
|
|
|
|
aCache->LoadDone(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncGetUsage(StorageUsageBridge* aUsage)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (mIPCOpen) {
|
2016-01-05 15:25:00 +03:00
|
|
|
SendAsyncGetUsage(aUsage->OriginScope());
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::SyncPreload(StorageCacheBridge* aCache, bool aForceSync)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus)) {
|
|
|
|
aCache->LoadDone(mStatus);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIPCOpen) {
|
|
|
|
aCache->LoadDone(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There is no way to put the child process to a wait state to receive all
|
2017-01-04 16:53:01 +03:00
|
|
|
// incoming async responses from the parent, hence we have to do a sync
|
|
|
|
// preload instead. We are smart though, we only demand keys that are left to
|
|
|
|
// load in case the async preload has already loaded some keys.
|
2013-04-15 16:38:48 +04:00
|
|
|
InfallibleTArray<nsString> keys, values;
|
|
|
|
nsresult rv;
|
2017-01-04 16:53:01 +03:00
|
|
|
SendPreload(aCache->OriginSuffix(), aCache->OriginNoSuffix(),
|
|
|
|
aCache->LoadedCount(), &keys, &values, &rv);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < keys.Length(); ++i) {
|
|
|
|
aCache->LoadItem(keys[i], values[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
aCache->LoadDone(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncAddItem(StorageCacheBridge* aCache,
|
|
|
|
const nsAString& aKey,
|
|
|
|
const nsAString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus) || !mIPCOpen) {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
SendAsyncAddItem(aCache->OriginSuffix(), aCache->OriginNoSuffix(),
|
|
|
|
nsString(aKey), nsString(aValue));
|
|
|
|
OriginsHavingData().PutEntry(aCache->Origin());
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncUpdateItem(StorageCacheBridge* aCache,
|
|
|
|
const nsAString& aKey,
|
|
|
|
const nsAString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus) || !mIPCOpen) {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
SendAsyncUpdateItem(aCache->OriginSuffix(), aCache->OriginNoSuffix(),
|
|
|
|
nsString(aKey), nsString(aValue));
|
|
|
|
OriginsHavingData().PutEntry(aCache->Origin());
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncRemoveItem(StorageCacheBridge* aCache,
|
|
|
|
const nsAString& aKey)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus) || !mIPCOpen) {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
SendAsyncRemoveItem(aCache->OriginSuffix(), aCache->OriginNoSuffix(),
|
|
|
|
nsString(aKey));
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::AsyncClear(StorageCacheBridge* aCache)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (NS_FAILED(mStatus) || !mIPCOpen) {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
SendAsyncClear(aCache->OriginSuffix(), aCache->OriginNoSuffix());
|
|
|
|
OriginsHavingData().RemoveEntry(aCache->Origin());
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::ShouldPreloadOrigin(const nsACString& aOrigin)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-01-05 15:25:00 +03:00
|
|
|
// Return true if we didn't receive the origins list yet.
|
2013-04-15 16:38:48 +04:00
|
|
|
// I tend to rather preserve a bit of early-after-start performance
|
2016-01-05 15:25:00 +03:00
|
|
|
// than a bit of memory here.
|
|
|
|
return !mOriginsHavingData || mOriginsHavingData->Contains(aOrigin);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvObserve(const nsCString& aTopic,
|
|
|
|
const nsString& aOriginAttributesPattern,
|
|
|
|
const nsCString& aOriginScope)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageObserver::Self()->Notify(
|
2016-01-05 15:25:00 +03:00
|
|
|
aTopic.get(), aOriginAttributesPattern, aOriginScope);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvOriginsHavingData(nsTArray<nsCString>&& aOrigins)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-02-07 12:05:07 +03:00
|
|
|
// Force population of mOriginsHavingData even if there are no origins so that
|
|
|
|
// ShouldPreloadOrigin does not generate false positives for all origins.
|
|
|
|
if (!aOrigins.Length()) {
|
|
|
|
Unused << OriginsHavingData();
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
for (uint32_t i = 0; i < aOrigins.Length(); ++i) {
|
|
|
|
OriginsHavingData().PutEntry(aOrigins[i]);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvLoadItem(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const nsString& aKey,
|
|
|
|
const nsString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageCache* aCache = mManager->GetCache(aOriginSuffix, aOriginNoSuffix);
|
2013-04-15 16:38:48 +04:00
|
|
|
if (aCache) {
|
|
|
|
aCache->LoadItem(aKey, aValue);
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvLoadDone(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const nsresult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageCache* aCache = mManager->GetCache(aOriginSuffix, aOriginNoSuffix);
|
2013-04-15 16:38:48 +04:00
|
|
|
if (aCache) {
|
|
|
|
aCache->LoadDone(aRv);
|
|
|
|
|
|
|
|
// Just drop reference to this cache now since the load is done.
|
2017-01-04 16:53:01 +03:00
|
|
|
mLoadingCaches.RemoveEntry(static_cast<StorageCacheBridge*>(aCache));
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvLoadUsage(const nsCString& aOriginNoSuffix,
|
|
|
|
const int64_t& aUsage)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
RefPtr<StorageUsageBridge> scopeUsage =
|
|
|
|
mManager->GetOriginUsage(aOriginNoSuffix);
|
2013-04-15 16:38:48 +04:00
|
|
|
scopeUsage->LoadUsage(aUsage);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBChild::RecvError(const nsresult& aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
mStatus = aRv;
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Parent
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_IMPL_ADDREF(StorageDBParent)
|
|
|
|
NS_IMPL_RELEASE(StorageDBParent)
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::AddIPDLReference()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mIPCOpen, "Attempting to retain multiple IPDL references");
|
2013-04-15 16:38:48 +04:00
|
|
|
mIPCOpen = true;
|
|
|
|
AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::ReleaseIPDLReference()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mIPCOpen, "Attempting to release non-existent IPDL reference");
|
2013-04-15 16:38:48 +04:00
|
|
|
mIPCOpen = false;
|
|
|
|
Release();
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace {
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class SendInitialChildDataRunnable : public Runnable
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-01-04 16:53:01 +03:00
|
|
|
explicit SendInitialChildDataRunnable(StorageDBParent* aParent)
|
2013-04-15 16:38:48 +04:00
|
|
|
: mParent(aParent)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (!mParent->IPCOpen()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::GetDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (db) {
|
|
|
|
InfallibleTArray<nsCString> scopes;
|
2016-01-05 15:25:00 +03:00
|
|
|
db->GetOriginsHavingData(&scopes);
|
|
|
|
mozilla::Unused << mParent->SendOriginsHavingData(scopes);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2013-05-10 18:20:05 +04:00
|
|
|
// We need to check if the device is in a low disk space situation, so
|
|
|
|
// we can forbid in that case any write in localStorage.
|
|
|
|
nsCOMPtr<nsIDiskSpaceWatcher> diskSpaceWatcher =
|
|
|
|
do_GetService("@mozilla.org/toolkit/disk-space-watcher;1");
|
|
|
|
if (!diskSpaceWatcher) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-01-05 15:25:00 +03:00
|
|
|
|
2013-05-10 18:20:05 +04:00
|
|
|
bool lowDiskSpace = false;
|
|
|
|
diskSpaceWatcher->GetIsDiskFull(&lowDiskSpace);
|
2016-01-05 15:25:00 +03:00
|
|
|
|
2013-05-10 18:20:05 +04:00
|
|
|
if (lowDiskSpace) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << mParent->SendObserve(
|
2016-01-05 15:25:00 +03:00
|
|
|
nsDependentCString("low-disk-space"), EmptyString(), EmptyCString());
|
2013-05-10 18:20:05 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
RefPtr<StorageDBParent> mParent;
|
2013-04-15 16:38:48 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::StorageDBParent()
|
2013-04-15 16:38:48 +04:00
|
|
|
: mIPCOpen(false)
|
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageObserver* observer = StorageObserver::Self();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (observer) {
|
|
|
|
observer->AddSink(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are always open by IPC only
|
|
|
|
AddIPDLReference();
|
|
|
|
|
|
|
|
// Cannot send directly from here since the channel
|
|
|
|
// is not completely built at this moment.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SendInitialChildDataRunnable> r =
|
2013-05-10 18:20:05 +04:00
|
|
|
new SendInitialChildDataRunnable(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
NS_DispatchToCurrentThread(r);
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::~StorageDBParent()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageObserver* observer = StorageObserver::Self();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (observer) {
|
|
|
|
observer->RemoveSink(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::CacheParentBridge*
|
|
|
|
StorageDBParent::NewCache(const nsACString& aOriginSuffix,
|
|
|
|
const nsACString& aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-01-05 15:25:00 +03:00
|
|
|
return new CacheParentBridge(this, aOriginSuffix, aOriginNoSuffix);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2014-05-02 22:44:13 +04:00
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::ActorDestroy(ActorDestroyReason aWhy)
|
2014-05-02 22:44:13 +04:00
|
|
|
{
|
|
|
|
// Implement me! Bug 1005169
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncPreload(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const bool& aPriority)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
db->AsyncPreload(NewCache(aOriginSuffix, aOriginNoSuffix), aPriority);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncGetUsage(const nsCString& aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The object releases it self in LoadUsage method
|
2017-01-04 16:53:01 +03:00
|
|
|
RefPtr<UsageParentBridge> usage =
|
|
|
|
new UsageParentBridge(this, aOriginNoSuffix);
|
2013-04-15 16:38:48 +04:00
|
|
|
db->AsyncGetUsage(usage);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace {
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
// We need another implementation of StorageCacheBridge to do
|
2013-04-15 16:38:48 +04:00
|
|
|
// synchronous IPC preload. This class just receives Load* notifications
|
|
|
|
// and fills the returning arguments of RecvPreload with the database
|
|
|
|
// values for us.
|
2017-01-04 16:53:01 +03:00
|
|
|
class SyncLoadCacheHelper : public StorageCacheBridge
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-01-05 15:25:00 +03:00
|
|
|
SyncLoadCacheHelper(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
2013-04-15 16:38:48 +04:00
|
|
|
uint32_t aAlreadyLoadedCount,
|
|
|
|
InfallibleTArray<nsString>* aKeys,
|
|
|
|
InfallibleTArray<nsString>* aValues,
|
|
|
|
nsresult* rv)
|
|
|
|
: mMonitor("DOM Storage SyncLoad IPC")
|
2016-01-05 15:25:00 +03:00
|
|
|
, mSuffix(aOriginSuffix)
|
|
|
|
, mOrigin(aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
, mKeys(aKeys)
|
|
|
|
, mValues(aValues)
|
|
|
|
, mRv(rv)
|
|
|
|
, mLoaded(false)
|
|
|
|
, mLoadedCount(aAlreadyLoadedCount)
|
|
|
|
{
|
|
|
|
// Precaution
|
|
|
|
*mRv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
virtual const nsCString Origin() const
|
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
return StorageManagerBase::CreateOrigin(mSuffix, mOrigin);
|
2016-01-05 15:25:00 +03:00
|
|
|
}
|
|
|
|
virtual const nsCString& OriginNoSuffix() const { return mOrigin; }
|
|
|
|
virtual const nsCString& OriginSuffix() const { return mSuffix; }
|
2013-04-15 16:38:48 +04:00
|
|
|
virtual bool Loaded() { return mLoaded; }
|
|
|
|
virtual uint32_t LoadedCount() { return mLoadedCount; }
|
|
|
|
virtual bool LoadItem(const nsAString& aKey, const nsString& aValue)
|
|
|
|
{
|
|
|
|
// Called on the aCache background thread
|
|
|
|
if (mLoaded) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++mLoadedCount;
|
|
|
|
mKeys->AppendElement(aKey);
|
|
|
|
mValues->AppendElement(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void LoadDone(nsresult aRv)
|
|
|
|
{
|
|
|
|
// Called on the aCache background thread
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
mLoaded = true;
|
|
|
|
*mRv = aRv;
|
|
|
|
monitor.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void LoadWait()
|
|
|
|
{
|
|
|
|
// Called on the main thread, exits after LoadDone() call
|
|
|
|
MonitorAutoLock monitor(mMonitor);
|
|
|
|
while (!mLoaded) {
|
|
|
|
monitor.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Monitor mMonitor;
|
2016-01-05 15:25:00 +03:00
|
|
|
nsCString mSuffix, mOrigin;
|
2013-04-15 16:38:48 +04:00
|
|
|
InfallibleTArray<nsString>* mKeys;
|
|
|
|
InfallibleTArray<nsString>* mValues;
|
|
|
|
nsresult* mRv;
|
|
|
|
bool mLoaded;
|
|
|
|
uint32_t mLoadedCount;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvPreload(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const uint32_t& aAlreadyLoadedCount,
|
|
|
|
InfallibleTArray<nsString>* aKeys,
|
|
|
|
InfallibleTArray<nsString>* aValues,
|
|
|
|
nsresult* aRv)
|
|
|
|
{
|
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SyncLoadCacheHelper> cache(
|
2017-01-04 16:53:01 +03:00
|
|
|
new SyncLoadCacheHelper(aOriginSuffix, aOriginNoSuffix, aAlreadyLoadedCount,
|
|
|
|
aKeys, aValues, aRv));
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
db->SyncPreload(cache, true);
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncAddItem(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const nsString& aKey,
|
|
|
|
const nsString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
nsresult rv = db->AsyncAddItem(NewCache(aOriginSuffix, aOriginNoSuffix), aKey,
|
|
|
|
aValue);
|
2013-04-15 16:38:48 +04:00
|
|
|
if (NS_FAILED(rv) && mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << SendError(rv);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncUpdateItem(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const nsString& aKey,
|
|
|
|
const nsString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
nsresult rv = db->AsyncUpdateItem(NewCache(aOriginSuffix, aOriginNoSuffix),
|
|
|
|
aKey, aValue);
|
2013-04-15 16:38:48 +04:00
|
|
|
if (NS_FAILED(rv) && mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << SendError(rv);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncRemoveItem(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix,
|
|
|
|
const nsString& aKey)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
nsresult rv = db->AsyncRemoveItem(NewCache(aOriginSuffix, aOriginNoSuffix),
|
|
|
|
aKey);
|
2013-04-15 16:38:48 +04:00
|
|
|
if (NS_FAILED(rv) && mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << SendError(rv);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncClear(const nsCString& aOriginSuffix,
|
|
|
|
const nsCString& aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::StartDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
nsresult rv = db->AsyncClear(NewCache(aOriginSuffix, aOriginNoSuffix));
|
2013-04-15 16:38:48 +04:00
|
|
|
if (NS_FAILED(rv) && mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << SendError(rv);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::RecvAsyncFlush()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBBridge* db = StorageCache::GetDatabase();
|
2013-04-15 16:38:48 +04:00
|
|
|
if (!db) {
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_FAIL_NO_REASON(this);
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
db->AsyncFlush();
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
// StorageObserverSink
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
nsresult
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::Observe(const char* aTopic,
|
|
|
|
const nsAString& aOriginAttributesPattern,
|
|
|
|
const nsACString& aOriginScope)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (mIPCOpen) {
|
2015-11-02 08:53:26 +03:00
|
|
|
mozilla::Unused << SendObserve(nsDependentCString(aTopic),
|
2016-01-05 15:25:00 +03:00
|
|
|
nsString(aOriginAttributesPattern),
|
|
|
|
nsCString(aOriginScope));
|
2013-04-15 16:38:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace {
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
// Results must be sent back on the main thread
|
2016-04-26 03:23:21 +03:00
|
|
|
class LoadRunnable : public Runnable
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum TaskType {
|
|
|
|
loadItem,
|
|
|
|
loadDone
|
|
|
|
};
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
LoadRunnable(StorageDBParent* aParent,
|
2013-04-15 16:38:48 +04:00
|
|
|
TaskType aType,
|
2016-01-05 15:25:00 +03:00
|
|
|
const nsACString& aOriginSuffix,
|
|
|
|
const nsACString& aOriginNoSuffix,
|
2013-04-15 16:38:48 +04:00
|
|
|
const nsAString& aKey = EmptyString(),
|
|
|
|
const nsAString& aValue = EmptyString())
|
|
|
|
: mParent(aParent)
|
|
|
|
, mType(aType)
|
2016-01-05 15:25:00 +03:00
|
|
|
, mSuffix(aOriginSuffix)
|
|
|
|
, mOrigin(aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
, mKey(aKey)
|
|
|
|
, mValue(aValue)
|
|
|
|
{ }
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
LoadRunnable(StorageDBParent* aParent,
|
2013-04-15 16:38:48 +04:00
|
|
|
TaskType aType,
|
2016-01-05 15:25:00 +03:00
|
|
|
const nsACString& aOriginSuffix,
|
|
|
|
const nsACString& aOriginNoSuffix,
|
2013-04-15 16:38:48 +04:00
|
|
|
nsresult aRv)
|
|
|
|
: mParent(aParent)
|
|
|
|
, mType(aType)
|
2016-01-05 15:25:00 +03:00
|
|
|
, mSuffix(aOriginSuffix)
|
|
|
|
, mOrigin(aOriginNoSuffix)
|
2013-04-15 16:38:48 +04:00
|
|
|
, mRv(aRv)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
2017-01-04 16:53:01 +03:00
|
|
|
RefPtr<StorageDBParent> mParent;
|
2013-04-15 16:38:48 +04:00
|
|
|
TaskType mType;
|
2016-01-05 15:25:00 +03:00
|
|
|
nsCString mSuffix, mOrigin;
|
2013-04-15 16:38:48 +04:00
|
|
|
nsString mKey;
|
|
|
|
nsString mValue;
|
|
|
|
nsresult mRv;
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (!mParent->IPCOpen()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mType)
|
|
|
|
{
|
|
|
|
case loadItem:
|
2016-01-05 15:25:00 +03:00
|
|
|
mozilla::Unused << mParent->SendLoadItem(mSuffix, mOrigin, mKey, mValue);
|
2013-04-15 16:38:48 +04:00
|
|
|
break;
|
|
|
|
case loadDone:
|
2016-01-05 15:25:00 +03:00
|
|
|
mozilla::Unused << mParent->SendLoadDone(mSuffix, mOrigin, mRv);
|
2013-04-15 16:38:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
// StorageDBParent::CacheParentBridge
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
const nsCString
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::CacheParentBridge::Origin() const
|
2016-01-05 15:25:00 +03:00
|
|
|
{
|
2017-01-04 16:53:01 +03:00
|
|
|
return StorageManagerBase::CreateOrigin(mOriginSuffix, mOriginNoSuffix);
|
2016-01-05 15:25:00 +03:00
|
|
|
}
|
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
bool
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::CacheParentBridge::LoadItem(const nsAString& aKey,
|
|
|
|
const nsString& aValue)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (mLoaded) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++mLoadedCount;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<LoadRunnable> r =
|
2017-01-04 16:53:01 +03:00
|
|
|
new LoadRunnable(mParent, LoadRunnable::loadItem, mOriginSuffix,
|
|
|
|
mOriginNoSuffix, aKey, aValue);
|
2013-04-15 16:38:48 +04:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::CacheParentBridge::LoadDone(nsresult aRv)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
// Prevent send of duplicate LoadDone.
|
|
|
|
if (mLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLoaded = true;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<LoadRunnable> r =
|
2017-01-04 16:53:01 +03:00
|
|
|
new LoadRunnable(mParent, LoadRunnable::loadDone, mOriginSuffix,
|
|
|
|
mOriginNoSuffix, aRv);
|
2013-04-15 16:38:48 +04:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::CacheParentBridge::LoadWait()
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
// Should never be called on this implementation
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
// StorageDBParent::UsageParentBridge
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
namespace {
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class UsageRunnable : public Runnable
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-01-04 16:53:01 +03:00
|
|
|
UsageRunnable(StorageDBParent* aParent, const nsACString& aOriginScope,
|
|
|
|
const int64_t& aUsage)
|
|
|
|
: mParent(aParent)
|
|
|
|
, mOriginScope(aOriginScope)
|
|
|
|
, mUsage(aUsage)
|
2013-04-15 16:38:48 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
|
|
|
if (!mParent->IPCOpen()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-05 15:25:00 +03:00
|
|
|
mozilla::Unused << mParent->SendLoadUsage(mOriginScope, mUsage);
|
2013-04-15 16:38:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
RefPtr<StorageDBParent> mParent;
|
2016-01-05 15:25:00 +03:00
|
|
|
nsCString mOriginScope;
|
2013-04-15 16:38:48 +04:00
|
|
|
int64_t mUsage;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
void
|
2017-01-04 16:53:01 +03:00
|
|
|
StorageDBParent::UsageParentBridge::LoadUsage(const int64_t aUsage)
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2016-01-05 15:25:00 +03:00
|
|
|
RefPtr<UsageRunnable> r = new UsageRunnable(mParent, mOriginScope, aUsage);
|
2013-04-15 16:38:48 +04:00
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|