mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1743020 - Part 5: Eliminate FakeCopyable, r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D145693
This commit is contained in:
parent
d65dcbe321
commit
2f7acc9840
30
dom/cache/CacheWorkerRef.cpp
vendored
30
dom/cache/CacheWorkerRef.cpp
vendored
@ -12,33 +12,6 @@
|
||||
|
||||
namespace mozilla::dom::cache {
|
||||
|
||||
namespace {
|
||||
// XXX Move this to mfbt, or do we already have something like this? Or remove
|
||||
// the need for that by changing StrongWorkerRef/IPCWorkerRef?
|
||||
|
||||
template <class T>
|
||||
class FakeCopyable {
|
||||
public:
|
||||
explicit FakeCopyable(T&& aTarget) : mTarget(std::forward<T>(aTarget)) {}
|
||||
|
||||
FakeCopyable(FakeCopyable&&) = default;
|
||||
|
||||
FakeCopyable(const FakeCopyable& aOther)
|
||||
: mTarget(std::move(const_cast<FakeCopyable&>(aOther).mTarget)) {
|
||||
MOZ_CRASH("Do not copy.");
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
auto operator()(Args&&... aArgs) {
|
||||
return mTarget(std::forward<Args>(aArgs)...);
|
||||
}
|
||||
|
||||
private:
|
||||
T mTarget;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// static
|
||||
SafeRefPtr<CacheWorkerRef> CacheWorkerRef::Create(WorkerPrivate* aWorkerPrivate,
|
||||
Behavior aBehavior) {
|
||||
@ -48,8 +21,7 @@ SafeRefPtr<CacheWorkerRef> CacheWorkerRef::Create(WorkerPrivate* aWorkerPrivate,
|
||||
// of CacheWorkerRef, since we can now use SafeRefPtrFromThis in the ctor
|
||||
auto workerRef =
|
||||
MakeSafeRefPtr<CacheWorkerRef>(aBehavior, ConstructorGuard{});
|
||||
auto notify =
|
||||
FakeCopyable([workerRef = workerRef.clonePtr()] { workerRef->Notify(); });
|
||||
auto notify = [workerRef = workerRef.clonePtr()] { workerRef->Notify(); };
|
||||
if (aBehavior == eStrongWorkerRef) {
|
||||
workerRef->mStrongWorkerRef = StrongWorkerRef::Create(
|
||||
aWorkerPrivate, "CacheWorkerRef-Strong", std::move(notify));
|
||||
|
@ -91,7 +91,7 @@ void WorkerRef::Notify() {
|
||||
return;
|
||||
}
|
||||
|
||||
std::function<void()> callback = std::move(mCallback);
|
||||
MoveOnlyFunction<void()> callback = std::move(mCallback);
|
||||
MOZ_ASSERT(!mCallback);
|
||||
|
||||
callback();
|
||||
@ -102,7 +102,7 @@ void WorkerRef::Notify() {
|
||||
|
||||
/* static */
|
||||
already_AddRefed<WeakWorkerRef> WeakWorkerRef::Create(
|
||||
WorkerPrivate* aWorkerPrivate, std::function<void()>&& aCallback) {
|
||||
WorkerPrivate* aWorkerPrivate, MoveOnlyFunction<void()>&& aCallback) {
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
@ -148,7 +148,7 @@ WorkerPrivate* WeakWorkerRef::GetUnsafePrivate() const {
|
||||
/* static */
|
||||
already_AddRefed<StrongWorkerRef> StrongWorkerRef::Create(
|
||||
WorkerPrivate* const aWorkerPrivate, const char* const aName,
|
||||
std::function<void()>&& aCallback) {
|
||||
MoveOnlyFunction<void()>&& aCallback) {
|
||||
if (RefPtr<StrongWorkerRef> ref =
|
||||
CreateImpl(aWorkerPrivate, aName, Canceling)) {
|
||||
ref->mCallback = std::move(aCallback);
|
||||
@ -218,7 +218,7 @@ WorkerPrivate* ThreadSafeWorkerRef::Private() const {
|
||||
/* static */
|
||||
already_AddRefed<IPCWorkerRef> IPCWorkerRef::Create(
|
||||
WorkerPrivate* aWorkerPrivate, const char* aName,
|
||||
std::function<void()>&& aCallback) {
|
||||
MoveOnlyFunction<void()>&& aCallback) {
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
aWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
#ifndef mozilla_dom_workers_WorkerRef_h
|
||||
#define mozilla_dom_workers_WorkerRef_h
|
||||
|
||||
#include <functional>
|
||||
#include "mozilla/dom/WorkerStatus.h"
|
||||
#include "mozilla/MoveOnlyFunction.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
@ -123,7 +123,7 @@ class WorkerRef {
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
|
||||
std::function<void()> mCallback;
|
||||
MoveOnlyFunction<void()> mCallback;
|
||||
const char* const mName;
|
||||
const bool mIsPreventingShutdown;
|
||||
|
||||
@ -135,7 +135,7 @@ class WeakWorkerRef final : public WorkerRef {
|
||||
public:
|
||||
static already_AddRefed<WeakWorkerRef> Create(
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
std::function<void()>&& aCallback = nullptr);
|
||||
MoveOnlyFunction<void()>&& aCallback = nullptr);
|
||||
|
||||
WorkerPrivate* GetPrivate() const;
|
||||
|
||||
@ -154,7 +154,7 @@ class StrongWorkerRef final : public WorkerRef {
|
||||
public:
|
||||
static already_AddRefed<StrongWorkerRef> Create(
|
||||
WorkerPrivate* aWorkerPrivate, const char* aName,
|
||||
std::function<void()>&& aCallback = nullptr);
|
||||
MoveOnlyFunction<void()>&& aCallback = nullptr);
|
||||
|
||||
// This function creates a StrongWorkerRef even when in the Canceling state of
|
||||
// the worker's lifecycle. It's intended to be used by system code, e.g. code
|
||||
@ -205,7 +205,7 @@ class IPCWorkerRef final : public WorkerRef {
|
||||
public:
|
||||
static already_AddRefed<IPCWorkerRef> Create(
|
||||
WorkerPrivate* aWorkerPrivate, const char* aName,
|
||||
std::function<void()>&& aCallback = nullptr);
|
||||
MoveOnlyFunction<void()>&& aCallback = nullptr);
|
||||
|
||||
WorkerPrivate* Private() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user