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"
18 // BrowserProcessSubThread
21 // Friendly names for the well-known threads.
22 static const char* kBrowserThreadNames
[BrowserProcessSubThread::ID_COUNT
] = {
23 "IPC I/O Parent", // IO
27 StaticMutex
BrowserProcessSubThread::sLock
;
28 BrowserProcessSubThread
* BrowserProcessSubThread::sBrowserThreads
[ID_COUNT
] = {
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() {
43 StaticMutexAutoLock
lock(sLock
);
44 sBrowserThreads
[mIdentifier
] = nullptr;
48 void BrowserProcessSubThread::Init() {
50 // Initializes the COM library on the current thread.
51 CoInitialize(nullptr);
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();
66 // Closes the COM library on the current thread. CoInitialize must
67 // be balanced by a corresponding call to CoUninitialize.
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();
83 } // namespace mozilla