Bug 1657874 - Avoid some duplicate patterns to init cups shim. r=jwatt

Depends on D86336

Differential Revision: https://phabricator.services.mozilla.com/D86341
This commit is contained in:
Emilio Cobos Álvarez 2020-08-07 12:07:48 +00:00
Родитель 05e2ab2186
Коммит 63ad13457c
2 изменённых файлов: 10 добавлений и 10 удалений

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
/* 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/. */
@ -30,6 +30,10 @@ class nsCUPSShim {
*/
bool IsInitialized() const { return mInited; }
bool EnsureInitialized() {
return IsInitialized() || Init();
}
/**
* Function pointers for supported functions. These are only
* valid after successful initialization.

Просмотреть файл

@ -13,10 +13,8 @@ static nsCUPSShim sCupsShim;
NS_IMETHODIMP
nsPrinterListCUPS::GetPrinters(nsTArray<RefPtr<nsIPrinter>>& aPrinters) {
if (!sCupsShim.IsInitialized()) {
if (!sCupsShim.Init()) {
return NS_ERROR_FAILURE;
}
if (!sCupsShim.EnsureInitialized()) {
return NS_ERROR_FAILURE;
}
mozilla::CUPSPrinterList cupsPrinterList(sCupsShim);
@ -39,10 +37,8 @@ nsPrinterListCUPS::GetPrinters(nsTArray<RefPtr<nsIPrinter>>& aPrinters) {
NS_IMETHODIMP
nsPrinterListCUPS::GetSystemDefaultPrinterName(nsAString& aName) {
if (!sCupsShim.IsInitialized()) {
if (!sCupsShim.Init()) {
return NS_ERROR_FAILURE;
}
if (!sCupsShim.EnsureInitialized()) {
return NS_ERROR_FAILURE;
}
mozilla::CUPSPrinterList cupsPrinterList(sCupsShim);