Skip to content

Instantly share code, notes, and snippets.

@ferjm
Created March 29, 2016 13:48
Show Gist options
  • Save ferjm/aad123979e9e11017b06 to your computer and use it in GitHub Desktop.
Save ferjm/aad123979e9e11017b06 to your computer and use it in GitHub Desktop.
/* -*- 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 "SyncManagerParent.h"
#include "SyncService.h"
#include "mozilla/unused.h"
#include "mozilla/ipc/BackgroundParent.h"
namespace mozilla {
using namespace ipc;
namespace dom {
namespace {
uint64_t sSyncManagerParentId = 0;
}
SyncManagerParent::SyncManagerParent()
: mService(SyncService::GetOrCreate())
, mId(++sSyncManagerParentId)
, mActorDestroyed(false)
{
AssertIsOnBackgroundThread();
mService->RegisterActor(this);
}
SyncManagerParent::~SyncManagerParent()
{
AssertIsOnBackgroundThread();
}
void
SyncManagerParent::ActorDestroy(ActorDestroyReason aWhy)
{
printf_stderr("SyncManagerParent::ActorDestroy\n");
AssertIsOnBackgroundThread();
mActorDestroyed = true;
if (mService) {
mService->UnregisterActor(this);
}
}
bool
SyncManagerParent::RecvRequest(const nsID& aRequestId,
const SyncOp& aOp)
{
AssertIsOnBackgroundThread();
if (NS_WARN_IF(!mService)) {
return false;
}
mService->Request(mId, aRequestId, aOp);
return true;
}
bool
SyncManagerParent::RecvShutdown()
{
printf_stderr("SyncManagerParent::RecvShutdown\n");
AssertIsOnBackgroundThread();
if (NS_WARN_IF(!mService)) {
return false;
}
mService->UnregisterActor(this);
mService = nullptr;
if (!mActorDestroyed) {
Unused << Send__delete__(this);
}
return true;
}
void
SyncManagerParent::NotifyResponse(const nsID& aRequestId,
const SyncOpResponse& aResponse)
{
AssertIsOnBackgroundThread();
if (!mActorDestroyed) {
Unused << SendResponse(aRequestId, aResponse);
}
}
} // namespace dom
} // namespace mozilla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment