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.

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

mercurial