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 https://mozilla.org/MPL/2.0/. */
6 
7 #include "mozilla/WinDllServices.h"
8 
9 #include "mozilla/ClearOnShutdown.h"
10 #include "mozilla/Services.h"
11 #include "nsIObserverService.h"
12 #include "nsString.h"
13 
14 namespace mozilla {
15 
16 const char* DllServices::kTopicDllLoadedMainThread = "dll-loaded-main-thread";
17 const char* DllServices::kTopicDllLoadedNonMainThread =
18     "dll-loaded-non-main-thread";
19 
20 static StaticRefPtr<DllServices> sInstance;
21 
Get()22 DllServices* DllServices::Get() {
23   if (sInstance) {
24     return sInstance;
25   }
26 
27   sInstance = new DllServices();
28   ClearOnShutdown(&sInstance);
29   return sInstance;
30 }
31 
DllServices()32 DllServices::DllServices() { Enable(); }
33 
NotifyDllLoad(const bool aIsMainThread,const nsString & aDllName)34 void DllServices::NotifyDllLoad(const bool aIsMainThread,
35                                 const nsString& aDllName) {
36   const char* topic;
37 
38   if (aIsMainThread) {
39     topic = kTopicDllLoadedMainThread;
40   } else {
41     topic = kTopicDllLoadedNonMainThread;
42   }
43 
44   nsCOMPtr<nsIObserverService> obsServ(mozilla::services::GetObserverService());
45   obsServ->NotifyObservers(nullptr, topic, aDllName.get());
46 }
47 
48 }  // namespace mozilla
49