tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GMPStorageChild.h (2794B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GMPStorageChild_h_
      7 #define GMPStorageChild_h_
      8 
      9 #include <queue>
     10 
     11 #include "gmp-platform.h"
     12 #include "gmp-storage.h"
     13 #include "mozilla/gmp/PGMPStorageChild.h"
     14 #include "nsRefPtrHashtable.h"
     15 #include "nsTHashtable.h"
     16 
     17 namespace mozilla::gmp {
     18 
     19 class GMPChild;
     20 class GMPStorageChild;
     21 
     22 class GMPRecordImpl : public GMPRecord {
     23 public:
     24  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPRecordImpl)
     25 
     26  GMPRecordImpl(GMPStorageChild* aOwner, const nsCString& aName,
     27                GMPRecordClient* aClient);
     28 
     29  // GMPRecord.
     30  GMPErr Open() override;
     31  GMPErr Read() override;
     32  GMPErr Write(const uint8_t* aData, uint32_t aDataSize) override;
     33  GMPErr Close() override;
     34 
     35  const nsCString& Name() const { return mName; }
     36 
     37  void OpenComplete(GMPErr aStatus);
     38  void ReadComplete(GMPErr aStatus, const uint8_t* aBytes, uint32_t aLength);
     39  void WriteComplete(GMPErr aStatus);
     40 
     41 private:
     42  ~GMPRecordImpl() = default;
     43  const nsCString mName;
     44  GMPRecordClient* const mClient;
     45  GMPStorageChild* const mOwner;
     46 };
     47 
     48 class GMPStorageChild : public PGMPStorageChild {
     49  friend class PGMPStorageChild;
     50 
     51 public:
     52  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPStorageChild)
     53 
     54  explicit GMPStorageChild(GMPChild* aPlugin);
     55 
     56  GMPErr CreateRecord(const nsCString& aRecordName, GMPRecord** aOutRecord,
     57                      GMPRecordClient* aClient);
     58 
     59  GMPErr Open(GMPRecordImpl* aRecord);
     60 
     61  GMPErr Read(GMPRecordImpl* aRecord);
     62 
     63  GMPErr Write(GMPRecordImpl* aRecord, const uint8_t* aData,
     64               uint32_t aDataSize);
     65 
     66  GMPErr Close(const nsCString& aRecordName);
     67 
     68 private:
     69  bool HasRecord(const nsCString& aRecordName);
     70  already_AddRefed<GMPRecordImpl> GetRecord(const nsCString& aRecordName);
     71 
     72 protected:
     73  ~GMPStorageChild() = default;
     74 
     75  // PGMPStorageChild
     76  mozilla::ipc::IPCResult RecvOpenComplete(const nsCString& aRecordName,
     77                                           const GMPErr& aStatus);
     78  mozilla::ipc::IPCResult RecvReadComplete(const nsCString& aRecordName,
     79                                           const GMPErr& aStatus,
     80                                           nsTArray<uint8_t>&& aBytes);
     81  mozilla::ipc::IPCResult RecvWriteComplete(const nsCString& aRecordName,
     82                                            const GMPErr& aStatus);
     83  mozilla::ipc::IPCResult RecvShutdown();
     84 
     85 private:
     86  Monitor mMonitor MOZ_UNANNOTATED;
     87  nsRefPtrHashtable<nsCStringHashKey, GMPRecordImpl> mRecords;
     88  GMPChild* mPlugin;
     89  bool mShutdown;
     90 };
     91 
     92 }  // namespace mozilla::gmp
     93 
     94 #endif  // GMPStorageChild_h_