2014-08-19 08:56:33 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 GMPStorageChild_h_
|
|
|
|
#define GMPStorageChild_h_
|
|
|
|
|
|
|
|
#include "mozilla/gmp/PGMPStorageChild.h"
|
|
|
|
#include "gmp-storage.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
2014-11-20 23:25:12 +00:00
|
|
|
#include "gmp-platform.h"
|
|
|
|
|
|
|
|
#include <queue>
|
2014-08-19 08:56:33 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gmp {
|
|
|
|
|
|
|
|
class GMPChild;
|
|
|
|
class GMPStorageChild;
|
|
|
|
|
|
|
|
class GMPRecordImpl : public GMPRecord
|
|
|
|
{
|
|
|
|
public:
|
2014-12-04 20:34:00 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPRecordImpl)
|
2014-08-19 08:56:33 +00:00
|
|
|
|
|
|
|
GMPRecordImpl(GMPStorageChild* aOwner,
|
|
|
|
const nsCString& aName,
|
|
|
|
GMPRecordClient* aClient);
|
|
|
|
|
|
|
|
// GMPRecord.
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual GMPErr Open() override;
|
|
|
|
virtual GMPErr Read() override;
|
2014-08-19 08:56:33 +00:00
|
|
|
virtual GMPErr Write(const uint8_t* aData,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aDataSize) override;
|
|
|
|
virtual GMPErr Close() override;
|
2014-08-19 08:56:33 +00:00
|
|
|
|
|
|
|
const nsCString& Name() const { return mName; }
|
|
|
|
|
|
|
|
void OpenComplete(GMPErr aStatus);
|
|
|
|
void ReadComplete(GMPErr aStatus, const uint8_t* aBytes, uint32_t aLength);
|
|
|
|
void WriteComplete(GMPErr aStatus);
|
|
|
|
|
|
|
|
private:
|
|
|
|
~GMPRecordImpl() {}
|
|
|
|
const nsCString mName;
|
|
|
|
GMPRecordClient* const mClient;
|
|
|
|
GMPStorageChild* const mOwner;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GMPStorageChild : public PGMPStorageChild
|
|
|
|
{
|
|
|
|
public:
|
2014-12-04 20:34:00 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPStorageChild)
|
2014-08-19 08:56:33 +00:00
|
|
|
|
2014-09-01 03:50:23 +00:00
|
|
|
explicit GMPStorageChild(GMPChild* aPlugin);
|
2014-08-19 08:56:33 +00:00
|
|
|
|
|
|
|
GMPErr CreateRecord(const nsCString& aRecordName,
|
|
|
|
GMPRecord** aOutRecord,
|
|
|
|
GMPRecordClient* aClient);
|
|
|
|
|
|
|
|
GMPErr Open(GMPRecordImpl* aRecord);
|
|
|
|
|
|
|
|
GMPErr Read(GMPRecordImpl* aRecord);
|
|
|
|
|
|
|
|
GMPErr Write(GMPRecordImpl* aRecord,
|
|
|
|
const uint8_t* aData,
|
|
|
|
uint32_t aDataSize);
|
|
|
|
|
2014-11-27 23:34:00 +00:00
|
|
|
GMPErr Close(const nsCString& aRecordName);
|
2014-08-19 08:56:33 +00:00
|
|
|
|
2014-11-20 23:25:12 +00:00
|
|
|
GMPErr EnumerateRecords(RecvGMPRecordIteratorPtr aRecvIteratorFunc,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2014-11-27 23:34:00 +00:00
|
|
|
private:
|
|
|
|
bool HasRecord(const nsCString& aRecordName);
|
|
|
|
already_AddRefed<GMPRecordImpl> GetRecord(const nsCString& aRecordName);
|
|
|
|
|
2014-08-19 08:56:33 +00:00
|
|
|
protected:
|
|
|
|
~GMPStorageChild() {}
|
|
|
|
|
|
|
|
// PGMPStorageChild
|
|
|
|
virtual bool RecvOpenComplete(const nsCString& aRecordName,
|
2015-03-21 16:28:04 +00:00
|
|
|
const GMPErr& aStatus) override;
|
2014-08-19 08:56:33 +00:00
|
|
|
virtual bool RecvReadComplete(const nsCString& aRecordName,
|
|
|
|
const GMPErr& aStatus,
|
2015-03-21 16:28:04 +00:00
|
|
|
InfallibleTArray<uint8_t>&& aBytes) override;
|
2014-08-19 08:56:33 +00:00
|
|
|
virtual bool RecvWriteComplete(const nsCString& aRecordName,
|
2015-03-21 16:28:04 +00:00
|
|
|
const GMPErr& aStatus) override;
|
2015-01-16 19:58:52 +00:00
|
|
|
virtual bool RecvRecordNames(InfallibleTArray<nsCString>&& aRecordNames,
|
2015-03-21 16:28:04 +00:00
|
|
|
const GMPErr& aStatus) override;
|
|
|
|
virtual bool RecvShutdown() override;
|
2014-08-19 08:56:33 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-27 23:34:00 +00:00
|
|
|
Monitor mMonitor;
|
2014-08-19 08:56:33 +00:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, GMPRecordImpl> mRecords;
|
|
|
|
GMPChild* mPlugin;
|
2014-11-20 23:25:12 +00:00
|
|
|
|
|
|
|
struct RecordIteratorContext {
|
|
|
|
explicit RecordIteratorContext(RecvGMPRecordIteratorPtr aFunc,
|
|
|
|
void* aUserArg)
|
|
|
|
: mFunc(aFunc)
|
|
|
|
, mUserArg(aUserArg)
|
|
|
|
{}
|
2014-11-27 23:34:00 +00:00
|
|
|
RecordIteratorContext() {}
|
2014-11-20 23:25:12 +00:00
|
|
|
RecvGMPRecordIteratorPtr mFunc;
|
|
|
|
void* mUserArg;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::queue<RecordIteratorContext> mPendingRecordIterators;
|
2014-08-19 08:56:33 +00:00
|
|
|
bool mShutdown;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gmp
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // GMPStorageChild_h_
|