2010-02-03 22:17:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
2012-05-21 11:12:37 +00: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 18:38:29 +00:00
|
|
|
|
2010-02-03 22:17:09 +00:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2009-06-29 18:38:29 +00:00
|
|
|
#include "chrome/common/notification_service.h"
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include <objbase.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-03 22:17:09 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
2009-06-29 18:38:29 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// BrowserProcessSubThread
|
|
|
|
//
|
|
|
|
|
|
|
|
// Friendly names for the well-known threads.
|
|
|
|
static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
|
|
|
|
"Gecko_IOThread", // IO
|
|
|
|
// "Chrome_FileThread", // FILE
|
|
|
|
// "Chrome_DBThread", // DB
|
|
|
|
// "Chrome_HistoryThread", // HISTORY
|
|
|
|
#if defined(OS_LINUX)
|
|
|
|
"Gecko_Background_X11Thread", // BACKGROUND_X11
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
Lock BrowserProcessSubThread::sLock;
|
|
|
|
BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
|
2013-08-23 19:51:58 +00:00
|
|
|
nullptr, // IO
|
|
|
|
// nullptr, // FILE
|
|
|
|
// nullptr, // DB
|
|
|
|
// nullptr, // HISTORY
|
2009-06-29 18:38:29 +00:00
|
|
|
#if defined(OS_LINUX)
|
2013-08-23 19:51:58 +00:00
|
|
|
nullptr, // BACKGROUND_X11
|
2009-06-29 18:38:29 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
|
2010-02-03 22:17:09 +00:00
|
|
|
base::Thread(kBrowserThreadNames[aId]),
|
|
|
|
mIdentifier(aId),
|
2013-08-23 19:51:58 +00:00
|
|
|
mNotificationService(nullptr)
|
2009-06-29 18:38:29 +00:00
|
|
|
{
|
2010-02-03 22:17:09 +00:00
|
|
|
AutoLock lock(sLock);
|
|
|
|
DCHECK(aId >= 0 && aId < ID_COUNT);
|
2013-08-23 19:51:58 +00:00
|
|
|
DCHECK(sBrowserThreads[aId] == nullptr);
|
2010-02-03 22:17:09 +00:00
|
|
|
sBrowserThreads[aId] = this;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserProcessSubThread::~BrowserProcessSubThread()
|
|
|
|
{
|
2010-02-03 22:17:09 +00:00
|
|
|
Stop();
|
|
|
|
{AutoLock lock(sLock);
|
2013-08-23 19:51:58 +00:00
|
|
|
sBrowserThreads[mIdentifier] = nullptr;
|
2010-02-03 22:17:09 +00:00
|
|
|
}
|
2009-06-29 18:38:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BrowserProcessSubThread::Init()
|
|
|
|
{
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Initializes the COM library on the current thread.
|
2013-08-23 19:51:58 +00:00
|
|
|
CoInitialize(nullptr);
|
2009-06-29 18:38:29 +00:00
|
|
|
#endif
|
|
|
|
mNotificationService = new NotificationService();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BrowserProcessSubThread::CleanUp()
|
|
|
|
{
|
|
|
|
delete mNotificationService;
|
2013-08-23 19:51:58 +00:00
|
|
|
mNotificationService = nullptr;
|
2009-06-29 18:38:29 +00: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
|
|
|
|
MessageLoop*
|
2010-02-03 22:17:09 +00:00
|
|
|
BrowserProcessSubThread::GetMessageLoop(ID aId)
|
|
|
|
{
|
2009-06-29 18:38:29 +00:00
|
|
|
AutoLock lock(sLock);
|
|
|
|
DCHECK(aId >= 0 && aId < ID_COUNT);
|
|
|
|
|
|
|
|
if (sBrowserThreads[aId])
|
|
|
|
return sBrowserThreads[aId]->message_loop();
|
|
|
|
|
2013-08-23 19:51:58 +00:00
|
|
|
return nullptr;
|
2009-06-29 18:38:29 +00:00
|
|
|
}
|
2010-02-03 22:17:09 +00:00
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|