Backed out 8 changesets (bug 1873776) for causing vendor failures. CLOSED TREE
[gecko.git] / ipc / glue / BrowserProcessSubThread.cpp
blob6c2ba6a48ce892ae8d845912a0f3bb90a03a44f9
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/ipc/BrowserProcessSubThread.h"
8 #include "mozilla/ipc/NodeController.h"
10 #if defined(XP_WIN)
11 # include <objbase.h>
12 #endif
14 namespace mozilla {
15 namespace ipc {
18 // BrowserProcessSubThread
21 // Friendly names for the well-known threads.
22 static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
23 "IPC I/O Parent", // IO
26 /* static */
27 StaticMutex BrowserProcessSubThread::sLock;
28 BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
29 nullptr, // IO
32 BrowserProcessSubThread::BrowserProcessSubThread(ID aId)
33 : base::Thread(kBrowserThreadNames[aId]), mIdentifier(aId) {
34 StaticMutexAutoLock lock(sLock);
35 DCHECK(aId >= 0 && aId < ID_COUNT);
36 DCHECK(sBrowserThreads[aId] == nullptr);
37 sBrowserThreads[aId] = this;
40 BrowserProcessSubThread::~BrowserProcessSubThread() {
41 Stop();
43 StaticMutexAutoLock lock(sLock);
44 sBrowserThreads[mIdentifier] = nullptr;
48 void BrowserProcessSubThread::Init() {
49 #if defined(XP_WIN)
50 // Initializes the COM library on the current thread.
51 CoInitialize(nullptr);
52 #endif
54 // Initialize the ports library in the current thread.
55 if (mIdentifier == IO) {
56 NodeController::InitBrokerProcess();
60 void BrowserProcessSubThread::CleanUp() {
61 if (mIdentifier == IO) {
62 NodeController::CleanUp();
65 #if defined(XP_WIN)
66 // Closes the COM library on the current thread. CoInitialize must
67 // be balanced by a corresponding call to CoUninitialize.
68 CoUninitialize();
69 #endif
72 // static
73 MessageLoop* BrowserProcessSubThread::GetMessageLoop(ID aId) {
74 StaticMutexAutoLock lock(sLock);
75 DCHECK(aId >= 0 && aId < ID_COUNT);
77 if (sBrowserThreads[aId]) return sBrowserThreads[aId]->message_loop();
79 return nullptr;
82 } // namespace ipc
83 } // namespace mozilla