2016-05-28 00:54:31 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2009-06-29 22:38:29 +04:00
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2021-06-22 21:17:22 +03:00
|
|
|
#include "mozilla/ipc/NodeController.h"
|
2009-06-29 22:38:29 +04:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
# include <objbase.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-04 01:17:09 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
2009-06-29 22:38:29 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// BrowserProcessSubThread
|
|
|
|
//
|
|
|
|
|
|
|
|
// Friendly names for the well-known threads.
|
|
|
|
static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
|
2020-12-03 03:06:02 +03:00
|
|
|
"IPC I/O Parent", // IO
|
2009-06-29 22:38:29 +04:00
|
|
|
};
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
StaticMutex BrowserProcessSubThread::sLock;
|
2009-06-29 22:38:29 +04:00
|
|
|
BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
|
2013-08-23 23:51:58 +04:00
|
|
|
nullptr, // IO
|
2009-06-29 22:38:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
BrowserProcessSubThread::BrowserProcessSubThread(ID aId)
|
2010-02-04 01:17:09 +03:00
|
|
|
: base::Thread(kBrowserThreadNames[aId]), mIdentifier(aId) {
|
2015-05-13 11:59:52 +03:00
|
|
|
StaticMutexAutoLock lock(sLock);
|
2010-02-04 01:17:09 +03:00
|
|
|
DCHECK(aId >= 0 && aId < ID_COUNT);
|
2013-08-23 23:51:58 +04:00
|
|
|
DCHECK(sBrowserThreads[aId] == nullptr);
|
2010-02-04 01:17:09 +03:00
|
|
|
sBrowserThreads[aId] = this;
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserProcessSubThread::~BrowserProcessSubThread() {
|
2010-02-04 01:17:09 +03:00
|
|
|
Stop();
|
2015-05-13 11:59:52 +03:00
|
|
|
{
|
|
|
|
StaticMutexAutoLock lock(sLock);
|
2013-08-23 23:51:58 +04:00
|
|
|
sBrowserThreads[mIdentifier] = nullptr;
|
2010-02-04 01:17:09 +03:00
|
|
|
}
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserProcessSubThread::Init() {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Initializes the COM library on the current thread.
|
2013-08-23 23:51:58 +04:00
|
|
|
CoInitialize(nullptr);
|
2009-06-29 22:38:29 +04:00
|
|
|
#endif
|
2021-06-22 21:17:22 +03:00
|
|
|
|
|
|
|
// Initialize the ports library in the current thread.
|
|
|
|
if (mIdentifier == IO) {
|
|
|
|
NodeController::InitBrokerProcess();
|
|
|
|
}
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserProcessSubThread::CleanUp() {
|
2021-06-22 21:17:22 +03:00
|
|
|
if (mIdentifier == IO) {
|
|
|
|
NodeController::CleanUp();
|
|
|
|
}
|
|
|
|
|
2009-06-29 22:38:29 +04:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Closes the COM library on the current thread. CoInitialize must
|
|
|
|
// be balanced by a corresponding call to CoUninitialize.
|
|
|
|
CoUninitialize();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2010-02-04 01:17:09 +03:00
|
|
|
MessageLoop* BrowserProcessSubThread::GetMessageLoop(ID aId) {
|
2015-05-13 11:59:52 +03:00
|
|
|
StaticMutexAutoLock lock(sLock);
|
2009-06-29 22:38:29 +04:00
|
|
|
DCHECK(aId >= 0 && aId < ID_COUNT);
|
|
|
|
|
|
|
|
if (sBrowserThreads[aId]) return sBrowserThreads[aId]->message_loop();
|
|
|
|
|
2013-08-23 23:51:58 +04:00
|
|
|
return nullptr;
|
2009-06-29 22:38:29 +04:00
|
|
|
}
|
2010-02-04 01:17:09 +03:00
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|