michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/ipc/BrowserProcessSubThread.h" michael@0: #include "chrome/common/notification_service.h" michael@0: michael@0: #if defined(OS_WIN) michael@0: #include michael@0: #endif michael@0: michael@0: namespace mozilla { michael@0: namespace ipc { michael@0: michael@0: // michael@0: // BrowserProcessSubThread michael@0: // michael@0: michael@0: // Friendly names for the well-known threads. michael@0: static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = { michael@0: "Gecko_IOThread", // IO michael@0: // "Chrome_FileThread", // FILE michael@0: // "Chrome_DBThread", // DB michael@0: // "Chrome_HistoryThread", // HISTORY michael@0: #if defined(OS_LINUX) michael@0: "Gecko_Background_X11Thread", // BACKGROUND_X11 michael@0: #endif michael@0: }; michael@0: michael@0: Lock BrowserProcessSubThread::sLock; michael@0: BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = { michael@0: nullptr, // IO michael@0: // nullptr, // FILE michael@0: // nullptr, // DB michael@0: // nullptr, // HISTORY michael@0: #if defined(OS_LINUX) michael@0: nullptr, // BACKGROUND_X11 michael@0: #endif michael@0: }; michael@0: michael@0: BrowserProcessSubThread::BrowserProcessSubThread(ID aId) : michael@0: base::Thread(kBrowserThreadNames[aId]), michael@0: mIdentifier(aId), michael@0: mNotificationService(nullptr) michael@0: { michael@0: AutoLock lock(sLock); michael@0: DCHECK(aId >= 0 && aId < ID_COUNT); michael@0: DCHECK(sBrowserThreads[aId] == nullptr); michael@0: sBrowserThreads[aId] = this; michael@0: } michael@0: michael@0: BrowserProcessSubThread::~BrowserProcessSubThread() michael@0: { michael@0: Stop(); michael@0: {AutoLock lock(sLock); michael@0: sBrowserThreads[mIdentifier] = nullptr; michael@0: } michael@0: michael@0: } michael@0: michael@0: void michael@0: BrowserProcessSubThread::Init() michael@0: { michael@0: #if defined(OS_WIN) michael@0: // Initializes the COM library on the current thread. michael@0: CoInitialize(nullptr); michael@0: #endif michael@0: mNotificationService = new NotificationService(); michael@0: } michael@0: michael@0: void michael@0: BrowserProcessSubThread::CleanUp() michael@0: { michael@0: delete mNotificationService; michael@0: mNotificationService = nullptr; michael@0: michael@0: #if defined(OS_WIN) michael@0: // Closes the COM library on the current thread. CoInitialize must michael@0: // be balanced by a corresponding call to CoUninitialize. michael@0: CoUninitialize(); michael@0: #endif michael@0: } michael@0: michael@0: // static michael@0: MessageLoop* michael@0: BrowserProcessSubThread::GetMessageLoop(ID aId) michael@0: { michael@0: AutoLock lock(sLock); michael@0: DCHECK(aId >= 0 && aId < ID_COUNT); michael@0: michael@0: if (sBrowserThreads[aId]) michael@0: return sBrowserThreads[aId]->message_loop(); michael@0: michael@0: return nullptr; michael@0: } michael@0: michael@0: } // namespace ipc michael@0: } // namespace mozilla