Bug 1708422: part 16) Rename `mozInlineSpellChecker::SpellCheckerTimeSlice` to `mozIn...
[gecko.git] / dom / media / PrincipalHandle.h
blobb1cc83ae1840e31d7e41ae8e88166aea1e21c89f
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 file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef DOM_MEDIA_PRINCIPALHANDLE_H_
7 #define DOM_MEDIA_PRINCIPALHANDLE_H_
9 #include "nsIPrincipal.h"
10 #include "nsProxyRelease.h"
12 namespace mozilla {
13 /**
14 * We pass the principal through the MediaTrackGraph by wrapping it in a thread
15 * safe nsMainThreadPtrHandle, since it cannot be used directly off the main
16 * thread. We can compare two PrincipalHandles to each other on any thread, but
17 * they can only be created and converted back to nsIPrincipal* on main thread.
19 typedef nsMainThreadPtrHandle<nsIPrincipal> PrincipalHandle;
21 inline PrincipalHandle MakePrincipalHandle(nsIPrincipal* aPrincipal) {
22 RefPtr<nsMainThreadPtrHolder<nsIPrincipal>> holder =
23 new nsMainThreadPtrHolder<nsIPrincipal>(
24 "MakePrincipalHandle::nsIPrincipal", aPrincipal);
25 return PrincipalHandle(holder);
28 #define PRINCIPAL_HANDLE_NONE nullptr
30 inline nsIPrincipal* GetPrincipalFromHandle(
31 const PrincipalHandle& aPrincipalHandle) {
32 MOZ_ASSERT(NS_IsMainThread());
33 return aPrincipalHandle.get();
36 inline bool PrincipalHandleMatches(const PrincipalHandle& aPrincipalHandle,
37 nsIPrincipal* aOther) {
38 if (!aOther) {
39 return false;
42 nsIPrincipal* principal = GetPrincipalFromHandle(aPrincipalHandle);
43 if (!principal) {
44 return false;
47 bool result;
48 if (NS_FAILED(principal->Equals(aOther, &result))) {
49 NS_ERROR("Principal check failed");
50 return false;
53 return result;
55 } // namespace mozilla
57 #endif // DOM_MEDIA_PRINCIPALHANDLE_H_