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

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "mozilla/dom/cache/ManagerId.h"
       8             : #include "mozilla/dom/quota/QuotaManager.h"
       9             : #include "nsIPrincipal.h"
      10             : #include "nsProxyRelease.h"
      11             : #include "mozilla/RefPtr.h"
      12             : #include "nsThreadUtils.h"
      13             : 
      14             : namespace mozilla {
      15             : namespace dom {
      16             : namespace cache {
      17             : 
      18             : using mozilla::dom::quota::QuotaManager;
      19             : 
      20             : // static
      21             : nsresult
      22           0 : ManagerId::Create(nsIPrincipal* aPrincipal, ManagerId** aManagerIdOut)
      23             : {
      24           0 :   MOZ_ASSERT(NS_IsMainThread());
      25             : 
      26             :   // The QuotaManager::GetInfoFromPrincipal() has special logic for system
      27             :   // and about: principals.  We need to use the same modified origin in
      28             :   // order to interpret calls from QM correctly.
      29           0 :   nsCString quotaOrigin;
      30             :   nsresult rv = QuotaManager::GetInfoFromPrincipal(aPrincipal,
      31             :                                                    nullptr,   // suffix
      32             :                                                    nullptr,   // group
      33           0 :                                                    &quotaOrigin);
      34           0 :   if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
      35             : 
      36           0 :   RefPtr<ManagerId> ref = new ManagerId(aPrincipal, quotaOrigin);
      37           0 :   ref.forget(aManagerIdOut);
      38             : 
      39           0 :   return NS_OK;
      40             : }
      41             : 
      42             : already_AddRefed<nsIPrincipal>
      43           0 : ManagerId::Principal() const
      44             : {
      45           0 :   MOZ_ASSERT(NS_IsMainThread());
      46           0 :   nsCOMPtr<nsIPrincipal> ref = mPrincipal;
      47           0 :   return ref.forget();
      48             : }
      49             : 
      50           0 : ManagerId::ManagerId(nsIPrincipal* aPrincipal, const nsACString& aQuotaOrigin)
      51             :     : mPrincipal(aPrincipal)
      52           0 :     , mQuotaOrigin(aQuotaOrigin)
      53             : {
      54           0 :   MOZ_DIAGNOSTIC_ASSERT(mPrincipal);
      55           0 : }
      56             : 
      57           0 : ManagerId::~ManagerId()
      58             : {
      59             :   // If we're already on the main thread, then default destruction is fine
      60           0 :   if (NS_IsMainThread()) {
      61           0 :     return;
      62             :   }
      63             : 
      64             :   // Otherwise we need to proxy to main thread to do the release
      65             : 
      66             :   // The PBackground worker thread shouldn't be running after the main thread
      67             :   // is stopped.  So main thread is guaranteed to exist here.
      68             :   NS_ReleaseOnMainThread(
      69           0 :     "ManagerId::mPrincipal", mPrincipal.forget());
      70           0 : }
      71             : 
      72             : } // namespace cache
      73             : } // namespace dom
      74             : } // namespace mozilla

Generated by: LCOV version 1.13