/* -*- 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 GMPService_h_ #define GMPService_h_ #include "nsString.h" #include "mozIGeckoMediaPluginService.h" #include "nsIObserver.h" #include "nsTArray.h" #include "mozilla/Attributes.h" #include "mozilla/Monitor.h" #include "nsString.h" #include "nsCOMPtr.h" #include "nsIThread.h" #include "nsThreadUtils.h" #include "nsITimer.h" template struct already_AddRefed; namespace mozilla { namespace gmp { class GMPParent; class GeckoMediaPluginService MOZ_FINAL : public mozIGeckoMediaPluginService , public nsIObserver { public: static already_AddRefed GetGeckoMediaPluginService(); GeckoMediaPluginService(); nsresult Init(); NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_MOZIGECKOMEDIAPLUGINSERVICE NS_DECL_NSIOBSERVER void AsyncShutdownNeeded(GMPParent* aParent); void AsyncShutdownComplete(GMPParent* aParent); void AbortAsyncShutdown(); private: ~GeckoMediaPluginService(); GMPParent* SelectPluginForAPI(const nsACString& aNodeId, const nsCString& aAPI, const nsTArray& aTags, bool aCloneCrossNodeIds = true); void UnloadPlugins(); void CrashPlugins(); void SetAsyncShutdownComplete(); void LoadFromEnvironment(); void ProcessPossiblePlugin(nsIFile* aDir); void AddOnGMPThread(const nsAString& aSearchDir); void RemoveOnGMPThread(const nsAString& aSearchDir); nsresult SetAsyncShutdownTimeout(); protected: friend class GMPParent; void ReAddOnGMPThread(nsRefPtr& aOld); private: GMPParent* ClonePlugin(const GMPParent* aOriginal); class PathRunnable : public nsRunnable { public: PathRunnable(GeckoMediaPluginService* service, const nsAString& path, bool add) : mService(service) , mPath(path) , mAdd(add) { } NS_DECL_NSIRUNNABLE private: nsRefPtr mService; nsString mPath; bool mAdd; }; Mutex mMutex; // Protects mGMPThread and mShuttingDown and mPlugins nsTArray> mPlugins; nsCOMPtr mGMPThread; bool mShuttingDown; bool mShuttingDownOnGMPThread; template class MainThreadOnly { public: MOZ_IMPLICIT MainThreadOnly(T aValue) : mValue(aValue) {} operator T&() { MOZ_ASSERT(NS_IsMainThread()); return mValue; } private: T mValue; }; MainThreadOnly mWaitingForPluginsAsyncShutdown; nsTArray> mAsyncShutdownPlugins; // GMP Thread only. nsCOMPtr mAsyncShutdownTimeout; // GMP Thread only. nsCOMPtr mStorageBaseDir; }; } // namespace gmp } // namespace mozilla #endif // GMPService_h_