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/. */
|
|
|
|
|
|
|
|
#ifndef nsDOMStorageIPC_h___
|
|
|
|
#define nsDOMStorageIPC_h___
|
|
|
|
|
|
|
|
#include "mozilla/dom/PStorageChild.h"
|
|
|
|
#include "mozilla/dom/PStorageParent.h"
|
|
|
|
#include "DOMStorageDBThread.h"
|
|
|
|
#include "DOMStorageCache.h"
|
|
|
|
#include "DOMStorageObserver.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class DOMLocalStorageManager;
|
|
|
|
|
|
|
|
// Child side of the IPC protocol, exposes as DB interface but
|
|
|
|
// is responsible to send all requests to the parent process
|
|
|
|
// and expects asynchronous answers. Those are then transparently
|
|
|
|
// forwarded back to consumers on the child process.
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMStorageDBChild final : public DOMStorageDBBridge
|
2015-03-27 21:52:19 +03:00
|
|
|
, public PStorageChild
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~DOMStorageDBChild();
|
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit DOMStorageDBChild(DOMLocalStorageManager* aManager);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release(void);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
void AddIPDLReference();
|
|
|
|
void ReleaseIPDLReference();
|
|
|
|
|
|
|
|
virtual nsresult Init();
|
|
|
|
virtual nsresult Shutdown();
|
|
|
|
|
|
|
|
virtual void AsyncPreload(DOMStorageCacheBridge* aCache, bool aPriority = false);
|
|
|
|
virtual void AsyncGetUsage(DOMStorageUsageBridge* aUsage);
|
|
|
|
|
|
|
|
virtual void SyncPreload(DOMStorageCacheBridge* aCache, bool aForceSync = false);
|
|
|
|
|
|
|
|
virtual nsresult AsyncAddItem(DOMStorageCacheBridge* aCache, const nsAString& aKey, const nsAString& aValue);
|
|
|
|
virtual nsresult AsyncUpdateItem(DOMStorageCacheBridge* aCache, const nsAString& aKey, const nsAString& aValue);
|
|
|
|
virtual nsresult AsyncRemoveItem(DOMStorageCacheBridge* aCache, const nsAString& aKey);
|
|
|
|
virtual nsresult AsyncClear(DOMStorageCacheBridge* aCache);
|
|
|
|
|
|
|
|
virtual void AsyncClearAll()
|
2013-09-02 12:41:57 +04:00
|
|
|
{
|
|
|
|
if (mScopesHavingData) {
|
|
|
|
mScopesHavingData->Clear(); /* NO-OP on the child process otherwise */
|
|
|
|
}
|
|
|
|
}
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
virtual void AsyncClearMatchingScope(const nsACString& aScope)
|
|
|
|
{ /* NO-OP on the child process */ }
|
|
|
|
|
|
|
|
virtual void AsyncFlush()
|
|
|
|
{ SendAsyncFlush(); }
|
|
|
|
|
|
|
|
virtual bool ShouldPreloadScope(const nsACString& aScope);
|
|
|
|
virtual void GetScopesHavingData(InfallibleTArray<nsCString>* aScopes)
|
|
|
|
{ NS_NOTREACHED("Not implemented for child process"); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool RecvObserve(const nsCString& aTopic,
|
|
|
|
const nsCString& aScopePrefix);
|
|
|
|
bool RecvLoadItem(const nsCString& aScope,
|
|
|
|
const nsString& aKey,
|
|
|
|
const nsString& aValue);
|
|
|
|
bool RecvLoadDone(const nsCString& aScope,
|
|
|
|
const nsresult& aRv);
|
2015-01-16 22:58:52 +03:00
|
|
|
bool RecvScopesHavingData(nsTArray<nsCString>&& aScopes);
|
2013-04-15 16:38:48 +04:00
|
|
|
bool RecvLoadUsage(const nsCString& aScope,
|
|
|
|
const int64_t& aUsage);
|
|
|
|
bool RecvError(const nsresult& aRv);
|
|
|
|
|
|
|
|
nsTHashtable<nsCStringHashKey>& ScopesHavingData();
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
ThreadSafeAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
// Held to get caches to forward answers to.
|
|
|
|
nsRefPtr<DOMLocalStorageManager> mManager;
|
|
|
|
|
|
|
|
// Scopes having data hash, for optimization purposes only
|
2013-09-02 12:41:57 +04:00
|
|
|
nsAutoPtr<nsTHashtable<nsCStringHashKey> > mScopesHavingData;
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
// List of caches waiting for preload. This ensures the contract that
|
|
|
|
// AsyncPreload call references the cache for time of the preload.
|
|
|
|
nsTHashtable<nsRefPtrHashKey<DOMStorageCacheBridge> > mLoadingCaches;
|
|
|
|
|
|
|
|
// Status of the remote database
|
|
|
|
nsresult mStatus;
|
|
|
|
|
|
|
|
bool mIPCOpen;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Receives async requests from child processes and is responsible
|
|
|
|
// to send back responses from the DB thread. Exposes as a fake
|
|
|
|
// DOMStorageCache consumer.
|
|
|
|
// Also responsible for forwardning all chrome operation notifications
|
|
|
|
// such as cookie cleaning etc to the child process.
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMStorageDBParent final : public PStorageParent
|
2015-03-27 21:52:19 +03:00
|
|
|
, public DOMStorageObserverSink
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~DOMStorageDBParent();
|
|
|
|
|
2013-04-15 16:38:48 +04:00
|
|
|
public:
|
|
|
|
DOMStorageDBParent();
|
|
|
|
|
2013-06-03 14:14:37 +04:00
|
|
|
virtual mozilla::ipc::IProtocol*
|
|
|
|
CloneProtocol(Channel* aChannel,
|
2015-03-21 19:28:04 +03:00
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx) override;
|
2013-06-03 14:14:37 +04:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release(void);
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
void AddIPDLReference();
|
|
|
|
void ReleaseIPDLReference();
|
|
|
|
|
|
|
|
bool IPCOpen() { return mIPCOpen; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Fake cache class receiving async callbacks from DB thread, sending
|
|
|
|
// them back to appropriate cache object on the child process.
|
|
|
|
class CacheParentBridge : public DOMStorageCacheBridge {
|
|
|
|
public:
|
|
|
|
CacheParentBridge(DOMStorageDBParent* aParentDB, const nsACString& aScope)
|
|
|
|
: mParent(aParentDB), mScope(aScope), mLoaded(false), mLoadedCount(0) {}
|
|
|
|
virtual ~CacheParentBridge() {}
|
|
|
|
|
|
|
|
// DOMStorageCacheBridge
|
|
|
|
virtual const nsCString& Scope() const
|
|
|
|
{ return mScope; }
|
|
|
|
virtual bool Loaded()
|
|
|
|
{ return mLoaded; }
|
|
|
|
virtual uint32_t LoadedCount()
|
|
|
|
{ return mLoadedCount; }
|
|
|
|
|
|
|
|
virtual bool LoadItem(const nsAString& aKey, const nsString& aValue);
|
|
|
|
virtual void LoadDone(nsresult aRv);
|
|
|
|
virtual void LoadWait();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<DOMStorageDBParent> mParent;
|
|
|
|
nsCString mScope;
|
|
|
|
bool mLoaded;
|
|
|
|
uint32_t mLoadedCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fake usage class receiving async callbacks from DB thread
|
|
|
|
class UsageParentBridge : public DOMStorageUsageBridge
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UsageParentBridge(DOMStorageDBParent* aParentDB, const nsACString& aScope)
|
|
|
|
: mParent(aParentDB), mScope(aScope) {}
|
|
|
|
virtual ~UsageParentBridge() {}
|
|
|
|
|
|
|
|
// DOMStorageUsageBridge
|
|
|
|
virtual const nsCString& Scope() { return mScope; }
|
|
|
|
virtual void LoadUsage(const int64_t usage);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<DOMStorageDBParent> mParent;
|
|
|
|
nsCString mScope;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
// IPC
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
|
|
|
bool RecvAsyncPreload(const nsCString& aScope, const bool& aPriority) override;
|
2013-04-15 16:38:48 +04:00
|
|
|
bool RecvPreload(const nsCString& aScope, const uint32_t& aAlreadyLoadedCount,
|
|
|
|
InfallibleTArray<nsString>* aKeys, InfallibleTArray<nsString>* aValues,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult* aRv) override;
|
|
|
|
bool RecvAsyncGetUsage(const nsCString& aScope) override;
|
|
|
|
bool RecvAsyncAddItem(const nsCString& aScope, const nsString& aKey, const nsString& aValue) override;
|
|
|
|
bool RecvAsyncUpdateItem(const nsCString& aScope, const nsString& aKey, const nsString& aValue) override;
|
|
|
|
bool RecvAsyncRemoveItem(const nsCString& aScope, const nsString& aKey) override;
|
|
|
|
bool RecvAsyncClear(const nsCString& aScope) override;
|
|
|
|
bool RecvAsyncFlush() override;
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
// DOMStorageObserverSink
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Observe(const char* aTopic, const nsACString& aScopePrefix) override;
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
CacheParentBridge* NewCache(const nsACString& aScope);
|
|
|
|
|
2013-07-19 06:21:20 +04:00
|
|
|
ThreadSafeAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
2015-01-07 07:51:13 +03:00
|
|
|
|
|
|
|
// True when IPC channel is open and Send*() methods are OK to use.
|
2013-04-15 16:38:48 +04:00
|
|
|
bool mIPCOpen;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // ::dom
|
|
|
|
} // ::mozilla
|
|
|
|
|
|
|
|
#endif
|