зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1454998 - Break out PrincipalHandle into its own file. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D46764 --HG-- rename : dom/media/MediaSegment.h => dom/media/PrincipalHandle.h extra : moz-landing-system : lando
This commit is contained in:
Родитель
9ed4e1aa58
Коммит
3b58432d88
|
@ -6,9 +6,8 @@
|
|||
#ifndef MOZILLA_MEDIASEGMENT_H_
|
||||
#define MOZILLA_MEDIASEGMENT_H_
|
||||
|
||||
#include "PrincipalHandle.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
# include "mozilla/TimeStamp.h"
|
||||
#endif
|
||||
|
@ -65,49 +64,6 @@ const GraphTime GRAPH_TIME_MAX = MEDIA_TIME_MAX;
|
|||
*/
|
||||
const size_t DEFAULT_SEGMENT_CAPACITY = 16;
|
||||
|
||||
/**
|
||||
* We pass the principal through the MediaStreamGraph by wrapping it in a thread
|
||||
* safe nsMainThreadPtrHandle, since it cannot be used directly off the main
|
||||
* thread. We can compare two PrincipalHandles to each other on any thread, but
|
||||
* they can only be created and converted back to nsIPrincipal* on main thread.
|
||||
*/
|
||||
typedef nsMainThreadPtrHandle<nsIPrincipal> PrincipalHandle;
|
||||
|
||||
inline PrincipalHandle MakePrincipalHandle(nsIPrincipal* aPrincipal) {
|
||||
RefPtr<nsMainThreadPtrHolder<nsIPrincipal>> holder =
|
||||
new nsMainThreadPtrHolder<nsIPrincipal>(
|
||||
"MakePrincipalHandle::nsIPrincipal", aPrincipal);
|
||||
return PrincipalHandle(holder);
|
||||
}
|
||||
|
||||
#define PRINCIPAL_HANDLE_NONE nullptr
|
||||
|
||||
inline nsIPrincipal* GetPrincipalFromHandle(
|
||||
const PrincipalHandle& aPrincipalHandle) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return aPrincipalHandle.get();
|
||||
}
|
||||
|
||||
inline bool PrincipalHandleMatches(const PrincipalHandle& aPrincipalHandle,
|
||||
nsIPrincipal* aOther) {
|
||||
if (!aOther) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsIPrincipal* principal = GetPrincipalFromHandle(aPrincipalHandle);
|
||||
if (!principal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result;
|
||||
if (NS_FAILED(principal->Equals(aOther, &result))) {
|
||||
NS_ERROR("Principal check failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A MediaSegment is a chunk of media data sequential in time. Different
|
||||
* types of data have different subclasses of MediaSegment, all inheriting
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- 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 DOM_MEDIA_PRINCIPALHANDLE_H_
|
||||
#define DOM_MEDIA_PRINCIPALHANDLE_H_
|
||||
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
||||
namespace mozilla {
|
||||
/**
|
||||
* We pass the principal through the MediaStreamGraph by wrapping it in a thread
|
||||
* safe nsMainThreadPtrHandle, since it cannot be used directly off the main
|
||||
* thread. We can compare two PrincipalHandles to each other on any thread, but
|
||||
* they can only be created and converted back to nsIPrincipal* on main thread.
|
||||
*/
|
||||
typedef nsMainThreadPtrHandle<nsIPrincipal> PrincipalHandle;
|
||||
|
||||
inline PrincipalHandle MakePrincipalHandle(nsIPrincipal* aPrincipal) {
|
||||
RefPtr<nsMainThreadPtrHolder<nsIPrincipal>> holder =
|
||||
new nsMainThreadPtrHolder<nsIPrincipal>(
|
||||
"MakePrincipalHandle::nsIPrincipal", aPrincipal);
|
||||
return PrincipalHandle(holder);
|
||||
}
|
||||
|
||||
#define PRINCIPAL_HANDLE_NONE nullptr
|
||||
|
||||
inline nsIPrincipal* GetPrincipalFromHandle(
|
||||
const PrincipalHandle& aPrincipalHandle) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return aPrincipalHandle.get();
|
||||
}
|
||||
|
||||
inline bool PrincipalHandleMatches(const PrincipalHandle& aPrincipalHandle,
|
||||
nsIPrincipal* aOther) {
|
||||
if (!aOther) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsIPrincipal* principal = GetPrincipalFromHandle(aPrincipalHandle);
|
||||
if (!principal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result;
|
||||
if (NS_FAILED(principal->Equals(aOther, &result))) {
|
||||
NS_ERROR("Principal check failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // DOM_MEDIA_PRINCIPALHANDLE_H_
|
|
@ -165,6 +165,7 @@ EXPORTS += [
|
|||
'MemoryBlockCache.h',
|
||||
'nsIDocumentActivity.h',
|
||||
'PrincipalChangeObserver.h',
|
||||
'PrincipalHandle.h',
|
||||
'QueueObject.h',
|
||||
'SeekJob.h',
|
||||
'SeekTarget.h',
|
||||
|
|
Загрузка…
Ссылка в новой задаче