LCOV - code coverage report
Current view: top level - dom/media/gmp - GMPStorageParent.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 87 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include "GMPStorageParent.h"
       7             : #include "GMPParent.h"
       8             : #include "gmp-storage.h"
       9             : #include "mozilla/SizePrintfMacros.h"
      10             : #include "mozilla/Unused.h"
      11             : #include "mozIGeckoMediaPluginService.h"
      12             : 
      13             : namespace mozilla {
      14             : 
      15             : #ifdef LOG
      16             : #undef LOG
      17             : #endif
      18             : 
      19             : extern LogModule* GetGMPLog();
      20             : 
      21             : #define LOGD(msg) MOZ_LOG(GetGMPLog(), mozilla::LogLevel::Debug, msg)
      22             : #define LOG(level, msg) MOZ_LOG(GetGMPLog(), (level), msg)
      23             : 
      24             : namespace gmp {
      25             : 
      26           0 : GMPStorageParent::GMPStorageParent(const nsCString& aNodeId,
      27           0 :                                    GMPParent* aPlugin)
      28             :   : mNodeId(aNodeId)
      29             :   , mPlugin(aPlugin)
      30           0 :   , mShutdown(true)
      31             : {
      32           0 : }
      33             : 
      34             : nsresult
      35           0 : GMPStorageParent::Init()
      36             : {
      37           0 :   LOGD(("GMPStorageParent[%p]::Init()", this));
      38             : 
      39           0 :   if (NS_WARN_IF(mNodeId.IsEmpty())) {
      40           0 :     return NS_ERROR_FAILURE;
      41             :   }
      42           0 :   RefPtr<GeckoMediaPluginServiceParent> mps(GeckoMediaPluginServiceParent::GetSingleton());
      43           0 :   if (NS_WARN_IF(!mps)) {
      44           0 :     return NS_ERROR_FAILURE;
      45             :   }
      46             : 
      47           0 :   bool persistent = false;
      48           0 :   if (NS_WARN_IF(NS_FAILED(mps->IsPersistentStorageAllowed(mNodeId, &persistent)))) {
      49           0 :     return NS_ERROR_FAILURE;
      50             :   }
      51           0 :   if (persistent) {
      52           0 :     mStorage = CreateGMPDiskStorage(mNodeId, mPlugin->GetPluginBaseName());
      53             :   } else {
      54           0 :     mStorage = mps->GetMemoryStorageFor(mNodeId);
      55             :   }
      56           0 :   if (!mStorage) {
      57           0 :     return NS_ERROR_FAILURE;
      58             :   }
      59             : 
      60           0 :   mShutdown = false;
      61           0 :   return NS_OK;
      62             : }
      63             : 
      64             : mozilla::ipc::IPCResult
      65           0 : GMPStorageParent::RecvOpen(const nsCString& aRecordName)
      66             : {
      67           0 :   LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s')",
      68             :        this, aRecordName.get()));
      69             : 
      70           0 :   if (mShutdown) {
      71           0 :     return IPC_FAIL_NO_REASON(this);
      72             :   }
      73             : 
      74           0 :   if (mNodeId.EqualsLiteral("null")) {
      75             :     // Refuse to open storage if the page is opened from local disk,
      76             :     // or shared across origin.
      77           0 :     LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; null nodeId",
      78             :           this, aRecordName.get()));
      79           0 :     Unused << SendOpenComplete(aRecordName, GMPGenericErr);
      80           0 :     return IPC_OK();
      81             :   }
      82             : 
      83           0 :   if (aRecordName.IsEmpty()) {
      84           0 :     LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; record name empty",
      85             :           this, aRecordName.get()));
      86           0 :     Unused << SendOpenComplete(aRecordName, GMPGenericErr);
      87           0 :     return IPC_OK();
      88             :   }
      89             : 
      90           0 :   if (mStorage->IsOpen(aRecordName)) {
      91           0 :     LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') failed; record in use",
      92             :           this, aRecordName.get()));
      93           0 :     Unused << SendOpenComplete(aRecordName, GMPRecordInUse);
      94           0 :     return IPC_OK();
      95             :   }
      96             : 
      97           0 :   auto err = mStorage->Open(aRecordName);
      98           0 :   MOZ_ASSERT(GMP_FAILED(err) || mStorage->IsOpen(aRecordName));
      99           0 :   LOGD(("GMPStorageParent[%p]::RecvOpen(record='%s') complete; rv=%d",
     100             :         this, aRecordName.get(), err));
     101           0 :   Unused << SendOpenComplete(aRecordName, err);
     102             : 
     103           0 :   return IPC_OK();
     104             : }
     105             : 
     106             : mozilla::ipc::IPCResult
     107           0 : GMPStorageParent::RecvRead(const nsCString& aRecordName)
     108             : {
     109           0 :   LOGD(("GMPStorageParent[%p]::RecvRead(record='%s')",
     110             :        this, aRecordName.get()));
     111             : 
     112           0 :   if (mShutdown) {
     113           0 :     return IPC_FAIL_NO_REASON(this);
     114             :   }
     115             : 
     116           0 :   nsTArray<uint8_t> data;
     117           0 :   if (!mStorage->IsOpen(aRecordName)) {
     118           0 :     LOGD(("GMPStorageParent[%p]::RecvRead(record='%s') failed; record not open",
     119             :          this, aRecordName.get()));
     120           0 :     Unused << SendReadComplete(aRecordName, GMPClosedErr, data);
     121             :   } else {
     122           0 :     GMPErr rv = mStorage->Read(aRecordName, data);
     123           0 :     LOGD(("GMPStorageParent[%p]::RecvRead(record='%s') read %" PRIuSIZE " bytes rv=%" PRIu32,
     124             :           this, aRecordName.get(), data.Length(), static_cast<uint32_t>(rv)));
     125           0 :     Unused << SendReadComplete(aRecordName, rv, data);
     126             :   }
     127             : 
     128           0 :   return IPC_OK();
     129             : }
     130             : 
     131             : mozilla::ipc::IPCResult
     132           0 : GMPStorageParent::RecvWrite(const nsCString& aRecordName,
     133             :                             InfallibleTArray<uint8_t>&& aBytes)
     134             : {
     135           0 :   LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') %" PRIuSIZE " bytes",
     136             :         this, aRecordName.get(), aBytes.Length()));
     137             : 
     138           0 :   if (mShutdown) {
     139           0 :     return IPC_FAIL_NO_REASON(this);
     140             :   }
     141             : 
     142           0 :   if (!mStorage->IsOpen(aRecordName)) {
     143           0 :     LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') failed record not open",
     144             :           this, aRecordName.get()));
     145           0 :     Unused << SendWriteComplete(aRecordName, GMPClosedErr);
     146           0 :     return IPC_OK();
     147             :   }
     148             : 
     149           0 :   if (aBytes.Length() > GMP_MAX_RECORD_SIZE) {
     150           0 :     LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') failed record too big",
     151             :           this, aRecordName.get()));
     152           0 :     Unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr);
     153           0 :     return IPC_OK();
     154             :   }
     155             : 
     156           0 :   GMPErr rv = mStorage->Write(aRecordName, aBytes);
     157           0 :   LOGD(("GMPStorageParent[%p]::RecvWrite(record='%s') write complete rv=%d",
     158             :         this, aRecordName.get(), rv));
     159             : 
     160           0 :   Unused << SendWriteComplete(aRecordName, rv);
     161             : 
     162           0 :   return IPC_OK();
     163             : }
     164             : 
     165             : mozilla::ipc::IPCResult
     166           0 : GMPStorageParent::RecvClose(const nsCString& aRecordName)
     167             : {
     168           0 :   LOGD(("GMPStorageParent[%p]::RecvClose(record='%s')",
     169             :         this, aRecordName.get()));
     170             : 
     171           0 :   if (mShutdown) {
     172           0 :     return IPC_OK();
     173             :   }
     174             : 
     175           0 :   mStorage->Close(aRecordName);
     176             : 
     177           0 :   return IPC_OK();
     178             : }
     179             : 
     180             : void
     181           0 : GMPStorageParent::ActorDestroy(ActorDestroyReason aWhy)
     182             : {
     183           0 :   LOGD(("GMPStorageParent[%p]::ActorDestroy(reason=%d)", this, aWhy));
     184           0 :   Shutdown();
     185           0 : }
     186             : 
     187             : void
     188           0 : GMPStorageParent::Shutdown()
     189             : {
     190           0 :   LOGD(("GMPStorageParent[%p]::Shutdown()", this));
     191             : 
     192           0 :   if (mShutdown) {
     193           0 :     return;
     194             :   }
     195           0 :   mShutdown = true;
     196           0 :   Unused << SendShutdown();
     197             : 
     198           0 :   mStorage = nullptr;
     199             : 
     200             : }
     201             : 
     202             : } // namespace gmp
     203             : } // namespace mozilla

Generated by: LCOV version 1.13