ipc/glue/BrowserProcessSubThread.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/glue/BrowserProcessSubThread.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=8 et :
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "mozilla/ipc/BrowserProcessSubThread.h"
    1.12 +#include "chrome/common/notification_service.h"
    1.13 +
    1.14 +#if defined(OS_WIN)
    1.15 +#include <objbase.h>
    1.16 +#endif
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace ipc {
    1.20 +
    1.21 +//
    1.22 +// BrowserProcessSubThread
    1.23 +//
    1.24 +
    1.25 +// Friendly names for the well-known threads.
    1.26 +static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
    1.27 +  "Gecko_IOThread",  // IO
    1.28 +//  "Chrome_FileThread",  // FILE
    1.29 +//  "Chrome_DBThread",  // DB
    1.30 +//  "Chrome_HistoryThread",  // HISTORY
    1.31 +#if defined(OS_LINUX)
    1.32 +  "Gecko_Background_X11Thread",  // BACKGROUND_X11
    1.33 +#endif
    1.34 +};
    1.35 +
    1.36 +Lock BrowserProcessSubThread::sLock;
    1.37 +BrowserProcessSubThread* BrowserProcessSubThread::sBrowserThreads[ID_COUNT] = {
    1.38 +  nullptr,  // IO
    1.39 +//  nullptr,  // FILE
    1.40 +//  nullptr,  // DB
    1.41 +//  nullptr,  // HISTORY
    1.42 +#if defined(OS_LINUX)
    1.43 +  nullptr,  // BACKGROUND_X11
    1.44 +#endif
    1.45 +};
    1.46 +
    1.47 +BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
    1.48 +  base::Thread(kBrowserThreadNames[aId]),
    1.49 +  mIdentifier(aId),
    1.50 +  mNotificationService(nullptr)
    1.51 +{
    1.52 +  AutoLock lock(sLock);
    1.53 +  DCHECK(aId >= 0 && aId < ID_COUNT);
    1.54 +  DCHECK(sBrowserThreads[aId] == nullptr);
    1.55 +  sBrowserThreads[aId] = this;
    1.56 +}
    1.57 +
    1.58 +BrowserProcessSubThread::~BrowserProcessSubThread()
    1.59 +{
    1.60 +  Stop();
    1.61 +  {AutoLock lock(sLock);
    1.62 +    sBrowserThreads[mIdentifier] = nullptr;
    1.63 +  }
    1.64 +
    1.65 +}
    1.66 +
    1.67 +void
    1.68 +BrowserProcessSubThread::Init()
    1.69 +{
    1.70 +#if defined(OS_WIN)
    1.71 +  // Initializes the COM library on the current thread.
    1.72 +  CoInitialize(nullptr);
    1.73 +#endif
    1.74 +  mNotificationService = new NotificationService();
    1.75 +}
    1.76 +
    1.77 +void
    1.78 +BrowserProcessSubThread::CleanUp()
    1.79 +{
    1.80 +  delete mNotificationService;
    1.81 +  mNotificationService = nullptr;
    1.82 +
    1.83 +#if defined(OS_WIN)
    1.84 +  // Closes the COM library on the current thread. CoInitialize must
    1.85 +  // be balanced by a corresponding call to CoUninitialize.
    1.86 +  CoUninitialize();
    1.87 +#endif
    1.88 +}
    1.89 +
    1.90 +// static
    1.91 +MessageLoop*
    1.92 +BrowserProcessSubThread::GetMessageLoop(ID aId)
    1.93 +{
    1.94 +  AutoLock lock(sLock);
    1.95 +  DCHECK(aId >= 0 && aId < ID_COUNT);
    1.96 +
    1.97 +  if (sBrowserThreads[aId])
    1.98 +    return sBrowserThreads[aId]->message_loop();
    1.99 +
   1.100 +  return nullptr;
   1.101 +}
   1.102 +
   1.103 +} // namespace ipc
   1.104 +} // namespace mozilla

mercurial