Bug 1415779 P2 Add ClientManagerService and reference it from parent actors. r=baku

This commit is contained in:
Ben Kelly 2017-11-08 21:19:59 -08:00
parent b0316788f6
commit 4641badb26
11 changed files with 110 additions and 2 deletions

View File

@ -7,6 +7,7 @@
#include "ClientHandleParent.h"
#include "ClientHandleOpParent.h"
#include "ClientManagerService.h"
#include "ClientSourceParent.h"
#include "mozilla/dom/ClientIPCTypes.h"
#include "mozilla/Unused.h"
@ -51,6 +52,7 @@ ClientHandleParent::RecvPClientHandleOpConstructor(PClientHandleOpParent* aActor
}
ClientHandleParent::ClientHandleParent()
: mService(ClientManagerService::GetOrCreateInstance())
{
}

View File

@ -11,8 +11,12 @@
namespace mozilla {
namespace dom {
class ClientManagerService;
class ClientHandleParent final : public PClientHandleParent
{
RefPtr<ClientManagerService> mService;
// PClientHandleParent interface
mozilla::ipc::IPCResult
RecvTeardown() override;

View File

@ -14,6 +14,12 @@ ClientManagerOpParent::ActorDestroy(ActorDestroyReason aReason)
{
}
ClientManagerOpParent::ClientManagerOpParent(ClientManagerService* aService)
: mService(aService)
{
MOZ_DIAGNOSTIC_ASSERT(mService);
}
void
ClientManagerOpParent::Init(const ClientOpConstructorArgs& aArgs)
{

View File

@ -15,12 +15,14 @@ class ClientManagerService;
class ClientManagerOpParent final : public PClientManagerOpParent
{
RefPtr<ClientManagerService> mService;
// PClientManagerOpParent interface
void
ActorDestroy(ActorDestroyReason aReason) override;
public:
ClientManagerOpParent() = default;
explicit ClientManagerOpParent(ClientManagerService* aService);
~ClientManagerOpParent() = default;
void

View File

@ -8,6 +8,7 @@
#include "ClientHandleParent.h"
#include "ClientManagerOpParent.h"
#include "ClientManagerService.h"
#include "ClientSourceParent.h"
#include "mozilla/dom/PClientNavigateOpParent.h"
#include "mozilla/Unused.h"
@ -54,7 +55,7 @@ ClientManagerParent::RecvPClientHandleConstructor(PClientHandleParent* aActor,
PClientManagerOpParent*
ClientManagerParent::AllocPClientManagerOpParent(const ClientOpConstructorArgs& aArgs)
{
return new ClientManagerOpParent();
return new ClientManagerOpParent(mService);
}
bool
@ -101,6 +102,7 @@ ClientManagerParent::DeallocPClientSourceParent(PClientSourceParent* aActor)
}
ClientManagerParent::ClientManagerParent()
: mService(ClientManagerService::GetOrCreateInstance())
{
}

View File

@ -11,8 +11,12 @@
namespace mozilla {
namespace dom {
class ClientManagerService;
class ClientManagerParent final : public PClientManagerParent
{
RefPtr<ClientManagerService> mService;
// PClientManagerParent interface
mozilla::ipc::IPCResult
RecvTeardown() override;

View File

@ -0,0 +1,50 @@
/* -*- 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/. */
#include "ClientManagerService.h"
#include "mozilla/ipc/BackgroundParent.h"
namespace mozilla {
namespace dom {
using mozilla::ipc::AssertIsOnBackgroundThread;
namespace {
ClientManagerService* sClientManagerServiceInstance = nullptr;
} // anonymous namespace
ClientManagerService::ClientManagerService()
{
AssertIsOnBackgroundThread();
}
ClientManagerService::~ClientManagerService()
{
AssertIsOnBackgroundThread();
MOZ_DIAGNOSTIC_ASSERT(sClientManagerServiceInstance == this);
sClientManagerServiceInstance = nullptr;
}
// static
already_AddRefed<ClientManagerService>
ClientManagerService::GetOrCreateInstance()
{
AssertIsOnBackgroundThread();
if (!sClientManagerServiceInstance) {
sClientManagerServiceInstance = new ClientManagerService();
}
RefPtr<ClientManagerService> ref(sClientManagerServiceInstance);
return ref.forget();
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,31 @@
/* -*- 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_ClientManagerService_h
#define _mozilla_dom_ClientManagerService_h
namespace mozilla {
namespace dom {
// Define a singleton service to manage client activity throughout the
// browser. This service runs on the PBackground thread. To interact
// it with it please use the ClientManager and ClientHandle classes.
class ClientManagerService final
{
ClientManagerService();
~ClientManagerService();
public:
static already_AddRefed<ClientManagerService>
GetOrCreateInstance();
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::ClientManagerService)
};
} // namespace dom
} // namespace mozilla
#endif // _mozilla_dom_ClientManagerService_h

View File

@ -7,6 +7,7 @@
#include "ClientSourceParent.h"
#include "ClientHandleParent.h"
#include "ClientManagerService.h"
#include "ClientSourceOpParent.h"
#include "mozilla/dom/ClientIPCTypes.h"
#include "mozilla/Unused.h"
@ -44,6 +45,7 @@ ClientSourceParent::DeallocPClientSourceOpParent(PClientSourceOpParent* aActor)
}
ClientSourceParent::ClientSourceParent(const ClientSourceConstructorArgs& aArgs)
: mService(ClientManagerService::GetOrCreateInstance())
{
}

View File

@ -11,8 +11,12 @@
namespace mozilla {
namespace dom {
class ClientManagerService;
class ClientSourceParent final : public PClientSourceParent
{
RefPtr<ClientManagerService> mService;
// PClientSourceParent
IPCResult
RecvTeardown() override;

View File

@ -27,6 +27,7 @@ UNIFIED_SOURCES += [
'ClientManagerOpChild.cpp',
'ClientManagerOpParent.cpp',
'ClientManagerParent.cpp',
'ClientManagerService.cpp',
'ClientNavigateOpChild.cpp',
'ClientNavigateOpParent.cpp',
'ClientOpenWindowOpActors.cpp',