|
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/. */ |
|
7 |
|
8 #include "mozilla/ipc/BrowserProcessSubThread.h" |
|
9 #include "chrome/common/notification_service.h" |
|
10 |
|
11 #if defined(OS_WIN) |
|
12 #include <objbase.h> |
|
13 #endif |
|
14 |
|
15 namespace mozilla { |
|
16 namespace ipc { |
|
17 |
|
18 // |
|
19 // BrowserProcessSubThread |
|
20 // |
|
21 |
|
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 }; |
|
32 |
|
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 }; |
|
43 |
|
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 } |
|
54 |
|
55 BrowserProcessSubThread::~BrowserProcessSubThread() |
|
56 { |
|
57 Stop(); |
|
58 {AutoLock lock(sLock); |
|
59 sBrowserThreads[mIdentifier] = nullptr; |
|
60 } |
|
61 |
|
62 } |
|
63 |
|
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 } |
|
73 |
|
74 void |
|
75 BrowserProcessSubThread::CleanUp() |
|
76 { |
|
77 delete mNotificationService; |
|
78 mNotificationService = nullptr; |
|
79 |
|
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 } |
|
86 |
|
87 // static |
|
88 MessageLoop* |
|
89 BrowserProcessSubThread::GetMessageLoop(ID aId) |
|
90 { |
|
91 AutoLock lock(sLock); |
|
92 DCHECK(aId >= 0 && aId < ID_COUNT); |
|
93 |
|
94 if (sBrowserThreads[aId]) |
|
95 return sBrowserThreads[aId]->message_loop(); |
|
96 |
|
97 return nullptr; |
|
98 } |
|
99 |
|
100 } // namespace ipc |
|
101 } // namespace mozilla |