/src/mozilla-central/ipc/glue/BrowserProcessSubThread.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | /* 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 | | BrowserProcessSubThread::BrowserProcessSubThread(ID aId) : |
43 | | base::Thread(kBrowserThreadNames[aId]), |
44 | | mIdentifier(aId) |
45 | 3 | { |
46 | 3 | StaticMutexAutoLock lock(sLock); |
47 | 3 | DCHECK(aId >= 0 && aId < ID_COUNT); |
48 | 3 | DCHECK(sBrowserThreads[aId] == nullptr); |
49 | 3 | sBrowserThreads[aId] = this; |
50 | 3 | } |
51 | | |
52 | | BrowserProcessSubThread::~BrowserProcessSubThread() |
53 | 0 | { |
54 | 0 | Stop(); |
55 | 0 | { |
56 | 0 | StaticMutexAutoLock lock(sLock); |
57 | 0 | sBrowserThreads[mIdentifier] = nullptr; |
58 | 0 | } |
59 | 0 |
|
60 | 0 | } |
61 | | |
62 | | void |
63 | | BrowserProcessSubThread::Init() |
64 | 3 | { |
65 | | #if defined(OS_WIN) |
66 | | // Initializes the COM library on the current thread. |
67 | | CoInitialize(nullptr); |
68 | | #endif |
69 | | } |
70 | | |
71 | | void |
72 | | BrowserProcessSubThread::CleanUp() |
73 | 0 | { |
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 | | } |
80 | | |
81 | | // static |
82 | | MessageLoop* |
83 | | BrowserProcessSubThread::GetMessageLoop(ID aId) |
84 | 6 | { |
85 | 6 | StaticMutexAutoLock lock(sLock); |
86 | 6 | DCHECK(aId >= 0 && aId < ID_COUNT); |
87 | 6 | |
88 | 6 | if (sBrowserThreads[aId]) |
89 | 3 | return sBrowserThreads[aId]->message_loop(); |
90 | 3 | |
91 | 3 | return nullptr; |
92 | 3 | } |
93 | | |
94 | | } // namespace ipc |
95 | | } // namespace mozilla |