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"
17 // BrowserProcessSubThread
20 // Friendly names for the well-known threads.
21 static const char* kBrowserThreadNames
[BrowserProcessSubThread::ID_COUNT
] = {
22 "IPC I/O Parent", // IO
26 StaticMutex
BrowserProcessSubThread::sLock
;
27 BrowserProcessSubThread
* BrowserProcessSubThread::sBrowserThreads
[ID_COUNT
] = {
31 BrowserProcessSubThread::BrowserProcessSubThread(ID aId
)
32 : base::Thread(kBrowserThreadNames
[aId
]), mIdentifier(aId
) {
33 StaticMutexAutoLock
lock(sLock
);
34 DCHECK(aId
>= 0 && aId
< ID_COUNT
);
35 DCHECK(sBrowserThreads
[aId
] == nullptr);
36 sBrowserThreads
[aId
] = this;
39 BrowserProcessSubThread::~BrowserProcessSubThread() {
42 StaticMutexAutoLock
lock(sLock
);
43 sBrowserThreads
[mIdentifier
] = nullptr;
47 void BrowserProcessSubThread::Init() {
49 // Initializes the COM library on the current thread.
50 CoInitialize(nullptr);
54 void BrowserProcessSubThread::CleanUp() {
56 // Closes the COM library on the current thread. CoInitialize must
57 // be balanced by a corresponding call to CoUninitialize.
63 MessageLoop
* BrowserProcessSubThread::GetMessageLoop(ID aId
) {
64 StaticMutexAutoLock
lock(sLock
);
65 DCHECK(aId
>= 0 && aId
< ID_COUNT
);
67 if (sBrowserThreads
[aId
]) return sBrowserThreads
[aId
]->message_loop();
73 } // namespace mozilla