2017-11-09 08:19:59 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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 _mozilla_dom_ClientManager_h
|
|
|
|
#define _mozilla_dom_ClientManager_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/ClientOpPromise.h"
|
|
|
|
#include "mozilla/dom/ClientThing.h"
|
2017-11-16 21:15:10 +03:00
|
|
|
|
|
|
|
class nsIPrincipal;
|
2017-11-09 08:19:59 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
class PBackgroundChild;
|
2017-11-16 21:15:10 +03:00
|
|
|
class PrincipalInfo;
|
2017-11-09 08:19:59 +03:00
|
|
|
} // namespace ipc
|
|
|
|
namespace dom {
|
|
|
|
|
2017-11-09 08:20:00 +03:00
|
|
|
class ClientHandle;
|
|
|
|
class ClientInfo;
|
2017-11-09 08:19:59 +03:00
|
|
|
class ClientManagerChild;
|
|
|
|
class ClientOpConstructorArgs;
|
2017-11-09 08:19:59 +03:00
|
|
|
class ClientSource;
|
|
|
|
enum class ClientType : uint8_t;
|
2017-11-09 08:19:59 +03:00
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerPrivate;
|
|
|
|
} // workers namespace
|
|
|
|
|
|
|
|
// The ClientManager provides a per-thread singleton interface workering
|
|
|
|
// with the client subsystem. It allows globals to create ClientSource
|
|
|
|
// objects. It allows other parts of the system to attach to this globals
|
|
|
|
// by creating ClientHandle objects. The ClientManager also provides
|
|
|
|
// methods for querying the list of clients active in the system.
|
|
|
|
class ClientManager final : public ClientThing<ClientManagerChild>
|
|
|
|
{
|
|
|
|
friend class ClientManagerChild;
|
|
|
|
|
|
|
|
ClientManager();
|
|
|
|
~ClientManager();
|
|
|
|
|
|
|
|
// Utility method to trigger a shutdown of the ClientManager. This
|
|
|
|
// is called in various error conditions or when the last reference
|
|
|
|
// is dropped.
|
|
|
|
void
|
|
|
|
Shutdown();
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
UniquePtr<ClientSource>
|
|
|
|
CreateSourceInternal(ClientType aType,
|
2017-11-16 21:15:10 +03:00
|
|
|
nsISerialEventTarget* aEventTarget,
|
2017-11-09 08:19:59 +03:00
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipal);
|
|
|
|
|
2017-11-09 08:20:00 +03:00
|
|
|
already_AddRefed<ClientHandle>
|
|
|
|
CreateHandleInternal(const ClientInfo& aClientInfo,
|
|
|
|
nsISerialEventTarget* aSerialEventTarget);
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
// Utility method to perform an IPC operation. This will create a
|
|
|
|
// PClientManagerOp actor tied to a MozPromise. The promise will
|
|
|
|
// resolve or reject with the result of the remote operation.
|
|
|
|
already_AddRefed<ClientOpPromise>
|
|
|
|
StartOp(const ClientOpConstructorArgs& aArgs,
|
|
|
|
nsISerialEventTarget* aSerialEventTarget);
|
|
|
|
|
|
|
|
// Get or create the TLS singleton. Currently this is only used
|
|
|
|
// internally and external code indirectly calls it by invoking
|
|
|
|
// static methods.
|
|
|
|
static already_AddRefed<ClientManager>
|
|
|
|
GetOrCreateForCurrentThread();
|
|
|
|
|
|
|
|
// Private methods called by ClientSource
|
|
|
|
mozilla::dom::workers::WorkerPrivate*
|
|
|
|
GetWorkerPrivate() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Initialize the ClientManager at process start. This
|
|
|
|
// does book-keeping like creating a TLS identifier, etc.
|
|
|
|
// This should only be called by process startup code.
|
|
|
|
static void
|
|
|
|
Startup();
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
static UniquePtr<ClientSource>
|
2017-11-16 21:15:10 +03:00
|
|
|
CreateSource(ClientType aType, nsISerialEventTarget* aEventTarget,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2017-11-09 08:19:59 +03:00
|
|
|
|
|
|
|
static UniquePtr<ClientSource>
|
2017-11-16 21:15:10 +03:00
|
|
|
CreateSource(ClientType aType, nsISerialEventTarget* aEventTarget,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipal);
|
2017-11-09 08:19:59 +03:00
|
|
|
|
2017-11-09 08:20:00 +03:00
|
|
|
static already_AddRefed<ClientHandle>
|
|
|
|
CreateHandle(const ClientInfo& aClientInfo,
|
|
|
|
nsISerialEventTarget* aSerialEventTarget);
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::ClientManager)
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _mozilla_dom_ClientManager_h
|