dom/src/storage/DOMStorageIPC.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsDOMStorageIPC_h___
michael@0 7 #define nsDOMStorageIPC_h___
michael@0 8
michael@0 9 #include "mozilla/dom/PStorageChild.h"
michael@0 10 #include "mozilla/dom/PStorageParent.h"
michael@0 11 #include "DOMStorageDBThread.h"
michael@0 12 #include "DOMStorageCache.h"
michael@0 13 #include "DOMStorageObserver.h"
michael@0 14 #include "mozilla/Mutex.h"
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace dom {
michael@0 18
michael@0 19 class DOMLocalStorageManager;
michael@0 20
michael@0 21 // Child side of the IPC protocol, exposes as DB interface but
michael@0 22 // is responsible to send all requests to the parent process
michael@0 23 // and expects asynchronous answers. Those are then transparently
michael@0 24 // forwarded back to consumers on the child process.
michael@0 25 class DOMStorageDBChild MOZ_FINAL : public DOMStorageDBBridge
michael@0 26 , public PStorageChild
michael@0 27 {
michael@0 28 public:
michael@0 29 DOMStorageDBChild(DOMLocalStorageManager* aManager);
michael@0 30 virtual ~DOMStorageDBChild();
michael@0 31
michael@0 32 NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
michael@0 33 NS_IMETHOD_(MozExternalRefCountType) Release(void);
michael@0 34
michael@0 35 void AddIPDLReference();
michael@0 36 void ReleaseIPDLReference();
michael@0 37
michael@0 38 virtual nsresult Init();
michael@0 39 virtual nsresult Shutdown();
michael@0 40
michael@0 41 virtual void AsyncPreload(DOMStorageCacheBridge* aCache, bool aPriority = false);
michael@0 42 virtual void AsyncGetUsage(DOMStorageUsageBridge* aUsage);
michael@0 43
michael@0 44 virtual void SyncPreload(DOMStorageCacheBridge* aCache, bool aForceSync = false);
michael@0 45
michael@0 46 virtual nsresult AsyncAddItem(DOMStorageCacheBridge* aCache, const nsAString& aKey, const nsAString& aValue);
michael@0 47 virtual nsresult AsyncUpdateItem(DOMStorageCacheBridge* aCache, const nsAString& aKey, const nsAString& aValue);
michael@0 48 virtual nsresult AsyncRemoveItem(DOMStorageCacheBridge* aCache, const nsAString& aKey);
michael@0 49 virtual nsresult AsyncClear(DOMStorageCacheBridge* aCache);
michael@0 50
michael@0 51 virtual void AsyncClearAll()
michael@0 52 {
michael@0 53 if (mScopesHavingData) {
michael@0 54 mScopesHavingData->Clear(); /* NO-OP on the child process otherwise */
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 virtual void AsyncClearMatchingScope(const nsACString& aScope)
michael@0 59 { /* NO-OP on the child process */ }
michael@0 60
michael@0 61 virtual void AsyncFlush()
michael@0 62 { SendAsyncFlush(); }
michael@0 63
michael@0 64 virtual bool ShouldPreloadScope(const nsACString& aScope);
michael@0 65 virtual void GetScopesHavingData(InfallibleTArray<nsCString>* aScopes)
michael@0 66 { NS_NOTREACHED("Not implemented for child process"); }
michael@0 67
michael@0 68 private:
michael@0 69 bool RecvObserve(const nsCString& aTopic,
michael@0 70 const nsCString& aScopePrefix);
michael@0 71 bool RecvLoadItem(const nsCString& aScope,
michael@0 72 const nsString& aKey,
michael@0 73 const nsString& aValue);
michael@0 74 bool RecvLoadDone(const nsCString& aScope,
michael@0 75 const nsresult& aRv);
michael@0 76 bool RecvScopesHavingData(const InfallibleTArray<nsCString>& aScopes);
michael@0 77 bool RecvLoadUsage(const nsCString& aScope,
michael@0 78 const int64_t& aUsage);
michael@0 79 bool RecvError(const nsresult& aRv);
michael@0 80
michael@0 81 nsTHashtable<nsCStringHashKey>& ScopesHavingData();
michael@0 82
michael@0 83 ThreadSafeAutoRefCnt mRefCnt;
michael@0 84 NS_DECL_OWNINGTHREAD
michael@0 85
michael@0 86 // Held to get caches to forward answers to.
michael@0 87 nsRefPtr<DOMLocalStorageManager> mManager;
michael@0 88
michael@0 89 // Scopes having data hash, for optimization purposes only
michael@0 90 nsAutoPtr<nsTHashtable<nsCStringHashKey> > mScopesHavingData;
michael@0 91
michael@0 92 // List of caches waiting for preload. This ensures the contract that
michael@0 93 // AsyncPreload call references the cache for time of the preload.
michael@0 94 nsTHashtable<nsRefPtrHashKey<DOMStorageCacheBridge> > mLoadingCaches;
michael@0 95
michael@0 96 // Status of the remote database
michael@0 97 nsresult mStatus;
michael@0 98
michael@0 99 bool mIPCOpen;
michael@0 100 };
michael@0 101
michael@0 102
michael@0 103 // Receives async requests from child processes and is responsible
michael@0 104 // to send back responses from the DB thread. Exposes as a fake
michael@0 105 // DOMStorageCache consumer.
michael@0 106 // Also responsible for forwardning all chrome operation notifications
michael@0 107 // such as cookie cleaning etc to the child process.
michael@0 108 class DOMStorageDBParent MOZ_FINAL : public PStorageParent
michael@0 109 , public DOMStorageObserverSink
michael@0 110 {
michael@0 111 public:
michael@0 112 DOMStorageDBParent();
michael@0 113 virtual ~DOMStorageDBParent();
michael@0 114
michael@0 115 virtual mozilla::ipc::IProtocol*
michael@0 116 CloneProtocol(Channel* aChannel,
michael@0 117 mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
michael@0 118
michael@0 119 NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
michael@0 120 NS_IMETHOD_(MozExternalRefCountType) Release(void);
michael@0 121
michael@0 122 void AddIPDLReference();
michael@0 123 void ReleaseIPDLReference();
michael@0 124
michael@0 125 bool IPCOpen() { return mIPCOpen; }
michael@0 126
michael@0 127 public:
michael@0 128 // Fake cache class receiving async callbacks from DB thread, sending
michael@0 129 // them back to appropriate cache object on the child process.
michael@0 130 class CacheParentBridge : public DOMStorageCacheBridge {
michael@0 131 public:
michael@0 132 CacheParentBridge(DOMStorageDBParent* aParentDB, const nsACString& aScope)
michael@0 133 : mParent(aParentDB), mScope(aScope), mLoaded(false), mLoadedCount(0) {}
michael@0 134 virtual ~CacheParentBridge() {}
michael@0 135
michael@0 136 // DOMStorageCacheBridge
michael@0 137 virtual const nsCString& Scope() const
michael@0 138 { return mScope; }
michael@0 139 virtual bool Loaded()
michael@0 140 { return mLoaded; }
michael@0 141 virtual uint32_t LoadedCount()
michael@0 142 { return mLoadedCount; }
michael@0 143
michael@0 144 virtual bool LoadItem(const nsAString& aKey, const nsString& aValue);
michael@0 145 virtual void LoadDone(nsresult aRv);
michael@0 146 virtual void LoadWait();
michael@0 147
michael@0 148 private:
michael@0 149 nsRefPtr<DOMStorageDBParent> mParent;
michael@0 150 nsCString mScope;
michael@0 151 bool mLoaded;
michael@0 152 uint32_t mLoadedCount;
michael@0 153 };
michael@0 154
michael@0 155 // Fake usage class receiving async callbacks from DB thread
michael@0 156 class UsageParentBridge : public DOMStorageUsageBridge
michael@0 157 {
michael@0 158 public:
michael@0 159 UsageParentBridge(DOMStorageDBParent* aParentDB, const nsACString& aScope)
michael@0 160 : mParent(aParentDB), mScope(aScope) {}
michael@0 161 virtual ~UsageParentBridge() {}
michael@0 162
michael@0 163 // DOMStorageUsageBridge
michael@0 164 virtual const nsCString& Scope() { return mScope; }
michael@0 165 virtual void LoadUsage(const int64_t usage);
michael@0 166
michael@0 167 private:
michael@0 168 nsRefPtr<DOMStorageDBParent> mParent;
michael@0 169 nsCString mScope;
michael@0 170 };
michael@0 171
michael@0 172 private:
michael@0 173 // IPC
michael@0 174 bool RecvAsyncPreload(const nsCString& aScope, const bool& aPriority);
michael@0 175 bool RecvPreload(const nsCString& aScope, const uint32_t& aAlreadyLoadedCount,
michael@0 176 InfallibleTArray<nsString>* aKeys, InfallibleTArray<nsString>* aValues,
michael@0 177 nsresult* aRv);
michael@0 178 bool RecvAsyncGetUsage(const nsCString& aScope);
michael@0 179 bool RecvAsyncAddItem(const nsCString& aScope, const nsString& aKey, const nsString& aValue);
michael@0 180 bool RecvAsyncUpdateItem(const nsCString& aScope, const nsString& aKey, const nsString& aValue);
michael@0 181 bool RecvAsyncRemoveItem(const nsCString& aScope, const nsString& aKey);
michael@0 182 bool RecvAsyncClear(const nsCString& aScope);
michael@0 183 bool RecvAsyncFlush();
michael@0 184
michael@0 185 // DOMStorageObserverSink
michael@0 186 virtual nsresult Observe(const char* aTopic, const nsACString& aScopePrefix);
michael@0 187
michael@0 188 private:
michael@0 189 CacheParentBridge* NewCache(const nsACString& aScope);
michael@0 190
michael@0 191 ThreadSafeAutoRefCnt mRefCnt;
michael@0 192 NS_DECL_OWNINGTHREAD
michael@0 193
michael@0 194 // True when IPC channel is open and Send*() methods are OK to use.
michael@0 195 bool mIPCOpen;
michael@0 196 };
michael@0 197
michael@0 198 } // ::dom
michael@0 199 } // ::mozilla
michael@0 200
michael@0 201 #endif

mercurial