ipc/glue/BrowserProcessSubThread.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=8 et :
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include "mozilla/ipc/BrowserProcessSubThread.h"
michael@0 9 #include "chrome/common/notification_service.h"
michael@0 10
michael@0 11 #if defined(OS_WIN)
michael@0 12 #include <objbase.h>
michael@0 13 #endif
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace ipc {
michael@0 17
michael@0 18 //
michael@0 19 // BrowserProcessSubThread
michael@0 20 //
michael@0 21
michael@0 22 // Friendly names for the well-known threads.
michael@0 23 static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
michael@0 24 "Gecko_IOThread", // IO
michael@0 25 // "Chrome_FileThread", // FILE
michael@0 26 // "Chrome_DBThread", // DB
michael@0 27 // "Chrome_HistoryThread", // HISTORY
michael@0 28 #if defined(OS_LINUX)
michael@0 29 "Gecko_Background_X11Thread", // BACKGROUND_X11
michael@0 30 #endif
michael@0 31 };
michael@0 32
michael@0 33 Lock BrowserProcessSubThread::sLock;
michael@0 34 BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
michael@0 35 nullptr, // IO
michael@0 36 // nullptr, // FILE
michael@0 37 // nullptr, // DB
michael@0 38 // nullptr, // HISTORY
michael@0 39 #if defined(OS_LINUX)
michael@0 40 nullptr, // BACKGROUND_X11
michael@0 41 #endif
michael@0 42 };
michael@0 43
michael@0 44 BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
michael@0 45 base::Thread(kBrowserThreadNames[aId]),
michael@0 46 mIdentifier(aId),
michael@0 47 mNotificationService(nullptr)
michael@0 48 {
michael@0 49 AutoLock lock(sLock);
michael@0 50 DCHECK(aId >= 0 && aId < ID_COUNT);
michael@0 51 DCHECK(sBrowserThreads[aId] == nullptr);
michael@0 52 sBrowserThreads[aId] = this;
michael@0 53 }
michael@0 54
michael@0 55 BrowserProcessSubThread::~BrowserProcessSubThread()
michael@0 56 {
michael@0 57 Stop();
michael@0 58 {AutoLock lock(sLock);
michael@0 59 sBrowserThreads[mIdentifier] = nullptr;
michael@0 60 }
michael@0 61
michael@0 62 }
michael@0 63
michael@0 64 void
michael@0 65 BrowserProcessSubThread::Init()
michael@0 66 {
michael@0 67 #if defined(OS_WIN)
michael@0 68 // Initializes the COM library on the current thread.
michael@0 69 CoInitialize(nullptr);
michael@0 70 #endif
michael@0 71 mNotificationService = new NotificationService();
michael@0 72 }
michael@0 73
michael@0 74 void
michael@0 75 BrowserProcessSubThread::CleanUp()
michael@0 76 {
michael@0 77 delete mNotificationService;
michael@0 78 mNotificationService = nullptr;
michael@0 79
michael@0 80 #if defined(OS_WIN)
michael@0 81 // Closes the COM library on the current thread. CoInitialize must
michael@0 82 // be balanced by a corresponding call to CoUninitialize.
michael@0 83 CoUninitialize();
michael@0 84 #endif
michael@0 85 }
michael@0 86
michael@0 87 // static
michael@0 88 MessageLoop*
michael@0 89 BrowserProcessSubThread::GetMessageLoop(ID aId)
michael@0 90 {
michael@0 91 AutoLock lock(sLock);
michael@0 92 DCHECK(aId >= 0 && aId < ID_COUNT);
michael@0 93
michael@0 94 if (sBrowserThreads[aId])
michael@0 95 return sBrowserThreads[aId]->message_loop();
michael@0 96
michael@0 97 return nullptr;
michael@0 98 }
michael@0 99
michael@0 100 } // namespace ipc
michael@0 101 } // namespace mozilla

mercurial