Simplify ImageBridgeChild asynchronous initialization. (bug 1298938 part 2, r=mattwoodrow)

--HG--
extra : rebase_source : 1bdb57079ca7f3b4c2be6d1bcd5dd3f0ee0c92c1
This commit is contained in:
David Anderson 2016-09-13 16:30:56 -07:00
Родитель 82339b2d66
Коммит d1ef6f2696
2 изменённых файлов: 35 добавлений и 41 удалений

Просмотреть файл

@ -521,13 +521,6 @@ ImageBridgeChild::CreateCanvasClientSync(SynchronousTask* aTask,
*outResult = CreateCanvasClientNow(aType, aFlags); *outResult = CreateCanvasClientNow(aType, aFlags);
} }
static void ConnectImageBridge(ImageBridgeChild * child, ImageBridgeParent * parent)
{
MessageLoop *parentMsgLoop = parent->GetMessageLoop();
ipc::MessageChannel *parentChannel = parent->GetIPCChannel();
child->Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide);
}
ImageBridgeChild::ImageBridgeChild() ImageBridgeChild::ImageBridgeChild()
: mShuttingDown(false) : mShuttingDown(false)
, mFwdTransactionId(0) , mFwdTransactionId(0)
@ -872,16 +865,10 @@ void
ImageBridgeChild::SendImageBridgeThreadId() ImageBridgeChild::SendImageBridgeThreadId()
{ {
#ifdef MOZ_WIDGET_GONK #ifdef MOZ_WIDGET_GONK
SendImageBridgeThreadId(gettid()); PImageBridgeChild::SendImageBridgeThreadId(gettid());
#endif #endif
} }
static void CallSendImageBridgeThreadId(ImageBridgeChild* aImageBridgeChild)
{
MOZ_ASSERT(InImageBridgeChildThread());
aImageBridgeChild->SendImageBridgeThreadId();
}
bool bool
ImageBridgeChild::InitForContent(Endpoint<PImageBridgeChild>&& aEndpoint) ImageBridgeChild::InitForContent(Endpoint<PImageBridgeChild>&& aEndpoint)
{ {
@ -894,22 +881,37 @@ ImageBridgeChild::InitForContent(Endpoint<PImageBridgeChild>&& aEndpoint)
return false; return false;
} }
sImageBridgeChildSingleton = new ImageBridgeChild(); RefPtr<ImageBridgeChild> child = new ImageBridgeChild();
MessageLoop* loop = sImageBridgeChildSingleton->GetMessageLoop(); sImageBridgeChildSingleton = child;
loop->PostTask(NewRunnableMethod<Endpoint<PImageBridgeChild>&&>( RefPtr<Runnable> runnable = NewRunnableMethod<Endpoint<PImageBridgeChild>&&>(
sImageBridgeChildSingleton, &ImageBridgeChild::Bind, Move(aEndpoint))); child,
loop->PostTask(NewRunnableFunction( &ImageBridgeChild::Bind,
CallSendImageBridgeThreadId, sImageBridgeChildSingleton.get())); Move(aEndpoint));
child->GetMessageLoop()->PostTask(runnable.forget());
return sImageBridgeChildSingleton; return true;
} }
void void
ImageBridgeChild::Bind(Endpoint<PImageBridgeChild>&& aEndpoint) ImageBridgeChild::Bind(Endpoint<PImageBridgeChild>&& aEndpoint)
{ {
aEndpoint.Bind(this); if (!aEndpoint.Bind(this)) {
return;
}
SendImageBridgeThreadId();
}
void
ImageBridgeChild::BindSameProcess(RefPtr<ImageBridgeParent> aParent)
{
MessageLoop *parentMsgLoop = aParent->GetMessageLoop();
ipc::MessageChannel *parentChannel = aParent->GetIPCChannel();
Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide);
SendImageBridgeThreadId();
} }
void ImageBridgeChild::ShutDown() void ImageBridgeChild::ShutDown()
@ -959,13 +961,16 @@ ImageBridgeChild::InitSameProcess()
sImageBridgeChildThread->Start(); sImageBridgeChildThread->Start();
} }
sImageBridgeChildSingleton = new ImageBridgeChild(); RefPtr<ImageBridgeChild> child = new ImageBridgeChild();
RefPtr<ImageBridgeParent> parent = ImageBridgeParent::CreateSameProcess(); RefPtr<ImageBridgeParent> parent = ImageBridgeParent::CreateSameProcess();
sImageBridgeChildSingleton->ConnectAsync(parent); sImageBridgeChildSingleton = child;
sImageBridgeChildSingleton->GetMessageLoop()->PostTask(
NewRunnableFunction(CallSendImageBridgeThreadId, RefPtr<Runnable> runnable = WrapRunnable(
sImageBridgeChildSingleton.get())); child,
&ImageBridgeChild::BindSameProcess,
parent);
child->GetMessageLoop()->PostTask(runnable.forget());
} }
/* static */ void /* static */ void
@ -998,12 +1003,6 @@ MessageLoop * ImageBridgeChild::GetMessageLoop() const
return sImageBridgeChildThread ? sImageBridgeChildThread->message_loop() : nullptr; return sImageBridgeChildThread ? sImageBridgeChildThread->message_loop() : nullptr;
} }
void ImageBridgeChild::ConnectAsync(ImageBridgeParent* aParent)
{
GetMessageLoop()->PostTask(NewRunnableFunction(&ConnectImageBridge,
this, aParent));
}
void void
ImageBridgeChild::IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier) ImageBridgeChild::IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier)
{ {

Просмотреть файл

@ -160,14 +160,6 @@ public:
static ImageBridgeChild* GetSingleton(); static ImageBridgeChild* GetSingleton();
/**
* Dispatches a task to the ImageBridgeChild thread to do the connection
*/
void ConnectAsync(ImageBridgeParent* aParent);
using PImageBridgeChild::SendImageBridgeThreadId;
void SendImageBridgeThreadId();
static void IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier); static void IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier);
void BeginTransaction(); void BeginTransaction();
@ -402,6 +394,9 @@ protected:
bool aUnsafe); bool aUnsafe);
void Bind(Endpoint<PImageBridgeChild>&& aEndpoint); void Bind(Endpoint<PImageBridgeChild>&& aEndpoint);
void BindSameProcess(RefPtr<ImageBridgeParent> aParent);
void SendImageBridgeThreadId();
private: private:
CompositableTransaction* mTxn; CompositableTransaction* mTxn;