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