Bug 1353629 - PBlob refactoring - part 5 - IPCBlobInputStreamStorage, r=smaug

An IPCBlobInputStream can be sent back to the parent process (not implemented
in this patch). When this is done, we basically send only the internal ID.
From this ID, we can retrieve the original inputStream because any
IPCBlobInputStreamParent actor has previously registered it into a singleton:
IPCBlobInputStreamStorage.

So, if we have a IPCBlobInputStreamParent, we have an inputStream, and this
inputStream is known by IPCBlobInputStreamStorage. This will be useful in the
next patches.
This commit is contained in:
Andrea Marchesini 2017-04-24 12:09:40 +02:00
Родитель db0019c058
Коммит b90e19e9d1
5 изменённых файлов: 113 добавлений и 2 удалений

Просмотреть файл

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "IPCBlobInputStreamParent.h"
#include "IPCBlobInputStreamStorage.h"
#include "nsContentUtils.h"
namespace mozilla {
@ -23,7 +24,7 @@ IPCBlobInputStreamParent::Create(nsIInputStream* aInputStream, uint64_t aSize,
return nullptr;
}
// TODO: register to a service.
IPCBlobInputStreamStorage::Get()->AddStream(aInputStream, id);
return new IPCBlobInputStreamParent(id, aSize);
}
@ -37,7 +38,7 @@ IPCBlobInputStreamParent::IPCBlobInputStreamParent(const nsID& aID,
void
IPCBlobInputStreamParent::ActorDestroy(IProtocol::ActorDestroyReason aReason)
{
// TODO: unregister
IPCBlobInputStreamStorage::Get()->ForgetStream(mID);
}
} // namespace dom

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "IPCBlobInputStreamStorage.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
namespace mozilla {
namespace dom {
namespace {
StaticMutex gMutex;
StaticRefPtr<IPCBlobInputStreamStorage> gStorage;
}
IPCBlobInputStreamStorage::~IPCBlobInputStreamStorage()
{}
/* static */ IPCBlobInputStreamStorage*
IPCBlobInputStreamStorage::Get()
{
return gStorage;
}
/* static */ void
IPCBlobInputStreamStorage::Initialize()
{
MOZ_ASSERT(!gStorage);
gStorage = new IPCBlobInputStreamStorage();
ClearOnShutdown(&gStorage);
}
void
IPCBlobInputStreamStorage::AddStream(nsIInputStream* aInputStream,
const nsID& aID)
{
MOZ_ASSERT(aInputStream);
mozilla::StaticMutexAutoLock lock(gMutex);
mStorage.Put(aID, aInputStream);
}
void
IPCBlobInputStreamStorage::ForgetStream(const nsID& aID)
{
mozilla::StaticMutexAutoLock lock(gMutex);
mStorage.Remove(aID);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_dom_ipc_IPCBlobInputStreamStorage_h
#define mozilla_dom_ipc_IPCBlobInputStreamStorage_h
#include "mozilla/RefPtr.h"
#include "nsInterfaceHashtable.h"
#include "nsISupportsImpl.h"
class nsIInputStream;
struct nsID;
namespace mozilla {
namespace dom {
class IPCBlobInputStreamStorage final
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IPCBlobInputStreamStorage);
// This initializes the singleton and it must be called on the main-thread.
static void
Initialize();
static IPCBlobInputStreamStorage*
Get();
void
AddStream(nsIInputStream* aInputStream, const nsID& aID);
void
ForgetStream(const nsID& aID);
private:
~IPCBlobInputStreamStorage();
nsInterfaceHashtable<nsIDHashKey, nsIInputStream> mStorage;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_ipc_IPCBlobInputStreamStorage_h

Просмотреть файл

@ -10,6 +10,7 @@ EXPORTS.mozilla.dom.ipc += [
'IPCBlobInputStream.h',
'IPCBlobInputStreamChild.h',
'IPCBlobInputStreamParent.h',
'IPCBlobInputStreamStorage.h',
'MemoryStreamChild.h',
'MemoryStreamParent.h',
'nsIRemoteBlob.h',
@ -24,6 +25,7 @@ UNIFIED_SOURCES += [
'IPCBlobInputStream.cpp',
'IPCBlobInputStreamChild.cpp',
'IPCBlobInputStreamParent.cpp',
'IPCBlobInputStreamStorage.cpp',
'IPCBlobUtils.cpp',
'MemoryStreamParent.cpp',
]

Просмотреть файл

@ -127,6 +127,7 @@
#include "mozilla/ServoBindings.h"
#include "mozilla/StaticPresData.h"
#include "mozilla/dom/WebIDLGlobalNameHash.h"
#include "mozilla/dom/ipc/IPCBlobInputStreamStorage.h"
using namespace mozilla;
using namespace mozilla::net;
@ -315,6 +316,9 @@ nsLayoutStatics::Initialize()
MediaPrefs::GetSingleton();
#endif
// This must be initialized on the main-thread.
mozilla::dom::IPCBlobInputStreamStorage::Initialize();
return NS_OK;
}