Bug 1321244 - Lazily init global variables that could implicitly initialize NSPR. r=froydnj, a=jcristau
MozReview-Commit-ID: IPU9Qc8lr50
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -19112,17 +19112,17 @@ DatabaseMaintenance::DetermineMaintenanc
// track the values needed for the heuristics below.
if (schemaVersion < MakeSchemaVersion(18, 0)) {
*aMaintenanceAction = MaintenanceAction::Nothing;
return NS_OK;
}
bool lowDiskSpace = IndexedDatabaseManager::InLowDiskSpaceMode();
- if (QuotaManager::kRunningXPCShellTests) {
+ if (QuotaManager::IsRunningXPCShellTests()) {
// If we're running XPCShell then we want to test both the low disk space
// and normal disk space code paths so pick semi-randomly based on the
// current time.
lowDiskSpace = ((PR_Now() / PR_USEC_PER_MSEC) % 2) == 0;
}
// If we're low on disk space then the best we can hope for is that an
// incremental vacuum might free some space. That is a journaled operation so
--- a/dom/quota/ActorsParent.cpp
+++ b/dom/quota/ActorsParent.cpp
@@ -101,18 +101,16 @@
#define GB * 1024ULL MB
namespace mozilla {
namespace dom {
namespace quota {
using namespace mozilla::ipc;
-const bool QuotaManager::kRunningXPCShellTests = !!PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR");
-
// We want profiles to be platform-independent so we always need to replace
// the same characters on every platform. Windows has the most extensive set
// of illegal characters so we use its FILE_ILLEGAL_CHARACTERS and
// FILE_PATH_SEPARATOR.
const char QuotaManager::kReplaceChars[] = CONTROL_CHARACTERS "/:*?\"<>|\\";
namespace {
--- a/dom/quota/QuotaManager.h
+++ b/dom/quota/QuotaManager.h
@@ -14,16 +14,18 @@
#include "mozilla/Mutex.h"
#include "nsClassHashtable.h"
#include "nsRefPtrHashtable.h"
#include "Client.h"
#include "PersistenceType.h"
+#include "prenv.h"
+
#define QUOTA_MANAGER_CONTRACTID "@mozilla.org/dom/quota/manager;1"
class mozIStorageConnection;
class nsIEventTarget;
class nsIPrincipal;
class nsIThread;
class nsITimer;
class nsIURI;
@@ -108,17 +110,21 @@ public:
private:
class ShutdownRunnable;
class ShutdownObserver;
public:
NS_INLINE_DECL_REFCOUNTING(QuotaManager)
- static const bool kRunningXPCShellTests;
+ static bool IsRunningXPCShellTests()
+ {
+ static bool kRunningXPCShellTests = !!PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR");
+ return kRunningXPCShellTests;
+ }
static const char kReplaceChars[];
static void
GetOrCreate(nsIRunnable* aCallback);
// Returns a non-owning reference.
static QuotaManager*
--- a/dom/quota/QuotaManagerService.cpp
+++ b/dom/quota/QuotaManagerService.cpp
@@ -433,34 +433,34 @@ QuotaManagerService::PerformIdleMaintena
// If we're running on battery power then skip all idle maintenance since we
// would otherwise be doing lots of disk I/O.
BatteryInformation batteryInfo;
#ifdef MOZ_WIDGET_ANDROID
// Android XPCShell doesn't load the AndroidBridge that is needed to make
// GetCurrentBatteryInformation work...
- if (!QuotaManager::kRunningXPCShellTests)
+ if (!QuotaManager::IsRunningXPCShellTests())
#endif
{
GetCurrentBatteryInformation(&batteryInfo);
}
// If we're running XPCShell because we always want to be able to test this
// code so pretend that we're always charging.
- if (QuotaManager::kRunningXPCShellTests) {
+ if (QuotaManager::IsRunningXPCShellTests()) {
batteryInfo.level() = 100;
batteryInfo.charging() = true;
}
if (NS_WARN_IF(!batteryInfo.charging())) {
return;
}
- if (QuotaManager::kRunningXPCShellTests) {
+ if (QuotaManager::IsRunningXPCShellTests()) {
// We don't want user activity to impact this code if we're running tests.
Unused << Observe(nullptr, OBSERVER_TOPIC_IDLE, nullptr);
} else if (!mIdleObserverRegistered) {
nsCOMPtr<nsIIdleService> idleService =
do_GetService(kIdleServiceContractId);
MOZ_ASSERT(idleService);
MOZ_ALWAYS_SUCCEEDS(
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -54,17 +54,17 @@
#ifdef NS_ENABLE_TSF
#include <textstor.h>
#include "TSFTextStore.h"
#endif // #ifdef NS_ENABLE_TSF
#include <shlwapi.h>
-PRLogModuleInfo* gWindowsLog = nullptr;
+mozilla::LazyLogModule gWindowsLog("Widget");
using namespace mozilla::gfx;
namespace mozilla {
namespace widget {
#define ENTRY(_msg) { #_msg, _msg }
EventMsgInfo gAllEvents[] = {
@@ -457,19 +457,16 @@ typedef NTSTATUS (NTAPI* NtTestAlertPtr)
static NtTestAlertPtr sNtTestAlert = nullptr;
#endif
/* static */
void
WinUtils::Initialize()
{
- if (!gWindowsLog) {
- gWindowsLog = PR_NewLogModule("Widget");
- }
if (!sDwmDll && IsVistaOrLater()) {
sDwmDll = ::LoadLibraryW(kDwmLibraryName);
if (sDwmDll) {
dwmExtendFrameIntoClientAreaPtr = (DwmExtendFrameIntoClientAreaProc)::GetProcAddress(sDwmDll, "DwmExtendFrameIntoClientArea");
dwmIsCompositionEnabledPtr = (DwmIsCompositionEnabledProc)::GetProcAddress(sDwmDll, "DwmIsCompositionEnabled");
dwmSetIconicThumbnailPtr = (DwmSetIconicThumbnailProc)::GetProcAddress(sDwmDll, "DwmSetIconicThumbnail");
dwmSetIconicLivePreviewBitmapPtr = (DwmSetIconicLivePreviewBitmapProc)::GetProcAddress(sDwmDll, "DwmSetIconicLivePreviewBitmap");
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -3,16 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDeviceContextSpecWin.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/gfx/PrintTargetPDF.h"
#include "mozilla/gfx/PrintTargetWindows.h"
+#include "mozilla/Logging.h"
#include "mozilla/Preferences.h"
#include "mozilla/RefPtr.h"
#include "prmem.h"
#include <winspool.h>
#include "nsIWidget.h"
@@ -31,17 +32,17 @@
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "mozilla/Services.h"
#include "nsWindowsHelpers.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/Logging.h"
-PRLogModuleInfo * kWidgetPrintingLogMod = PR_NewLogModule("printing-widget");
+static mozilla::LazyLogModule kWidgetPrintingLogMod("printing-widget");
#define PR_PL(_p1) MOZ_LOG(kWidgetPrintingLogMod, mozilla::LogLevel::Debug, _p1)
using namespace mozilla;
using namespace mozilla::gfx;
static const wchar_t kDriverName[] = L"WINSPOOL";
//----------------------------------------------------------------------------------
--- a/widget/windows/nsNativeThemeWin.cpp
+++ b/widget/windows/nsNativeThemeWin.cpp
@@ -1,16 +1,17 @@
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsNativeThemeWin.h"
#include "mozilla/EventStates.h"
+#include "mozilla/Logging.h"
#include "mozilla/WindowsVersion.h"
#include "nsDeviceContext.h"
#include "nsRenderingContext.h"
#include "nsRect.h"
#include "nsSize.h"
#include "nsTransform2D.h"
#include "nsThemeConstants.h"
#include "nsIPresShell.h"
@@ -37,17 +38,17 @@
#include "nsUXThemeData.h"
#include "nsUXThemeConstants.h"
#include <algorithm>
using mozilla::IsVistaOrLater;
using namespace mozilla;
using namespace mozilla::widget;
-extern PRLogModuleInfo* gWindowsLog;
+extern mozilla::LazyLogModule gWindowsLog;
NS_IMPL_ISUPPORTS_INHERITED(nsNativeThemeWin, nsNativeTheme, nsITheme)
nsNativeThemeWin::nsNativeThemeWin() :
mProgressDeterminateTimeStamp(TimeStamp::Now()),
mProgressIndeterminateTimeStamp(TimeStamp::Now())
{
// If there is a relevant change in forms.css for windows platform,
--- a/widget/windows/nsWinGesture.cpp
+++ b/widget/windows/nsWinGesture.cpp
@@ -7,26 +7,27 @@
* nsWinGesture - Touch input handling for tablet displays.
*/
#include "nscore.h"
#include "nsWinGesture.h"
#include "nsUXThemeData.h"
#include "nsIDOMSimpleGestureEvent.h"
#include "nsIDOMWheelEvent.h"
+#include "mozilla/Logging.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/TouchEvents.h"
#include <cmath>
using namespace mozilla;
using namespace mozilla::widget;
-extern PRLogModuleInfo* gWindowsLog;
+extern mozilla::LazyLogModule gWindowsLog;
const wchar_t nsWinGesture::kGestureLibraryName[] = L"user32.dll";
HMODULE nsWinGesture::sLibraryHandle = nullptr;
nsWinGesture::GetGestureInfoPtr nsWinGesture::getGestureInfo = nullptr;
nsWinGesture::CloseGestureInfoHandlePtr nsWinGesture::closeGestureInfoHandle = nullptr;
nsWinGesture::GetGestureExtraArgsPtr nsWinGesture::getGestureExtraArgs = nullptr;
nsWinGesture::SetGestureConfigPtr nsWinGesture::setGestureConfig = nullptr;
nsWinGesture::GetGestureConfigPtr nsWinGesture::getGestureConfig = nullptr;
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -53,16 +53,17 @@
**
**************************************************************
**************************************************************/
#include "gfx2DGlue.h"
#include "gfxEnv.h"
#include "gfxPlatform.h"
#include "gfxPrefs.h"
+#include "mozilla/Logging.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/MiscEvents.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/TouchEvents.h"
#include "mozilla/ipc/MessageChannel.h"
#include <algorithm>
#include <limits>
@@ -334,17 +335,17 @@ DWORD CurrentWindowsTimeGetter::sLastPos
/**************************************************************
*
* SECTION: globals variables
*
**************************************************************/
static const char *sScreenManagerContractID = "@mozilla.org/gfx/screenmanager;1";
-extern PRLogModuleInfo* gWindowsLog;
+extern mozilla::LazyLogModule gWindowsLog;
// Global used in Show window enumerations.
static bool gWindowsVisible = false;
// True if we have sent a notification that we are suspending/sleeping.
static bool gIsSleepMode = false;
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
--- a/widget/windows/nsWindowDbg.cpp
+++ b/widget/windows/nsWindowDbg.cpp
@@ -2,22 +2,23 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* nsWindowDbg - Debug related utilities for nsWindow.
*/
+#include "mozilla/Logging.h"
#include "nsWindowDbg.h"
#include "WinUtils.h"
using namespace mozilla::widget;
-extern PRLogModuleInfo* gWindowsLog;
+extern mozilla::LazyLogModule gWindowsLog;
#if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
MSGFEventMsgInfo gMSGFEvents[] = {
"MSGF_DIALOGBOX", 0,
"MSGF_MESSAGEBOX", 1,
"MSGF_MENU", 2,
"MSGF_SCROLLBAR", 5,
"MSGF_NEXTWINDOW", 6,