diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-01 18:20:17 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-01 18:20:17 +0000 |
commit | 00d60fa690f04d37f7cc34688b8511cd3397fc3b (patch) | |
tree | c2eab34e6bed1a6786db15c78db4d1f66859ade3 /printing | |
parent | 39e537e316d35c2dd5181deb445f0420d4dc23b1 (diff) | |
download | chromium_src-00d60fa690f04d37f7cc34688b8511cd3397fc3b.zip chromium_src-00d60fa690f04d37f7cc34688b8511cd3397fc3b.tar.gz chromium_src-00d60fa690f04d37f7cc34688b8511cd3397fc3b.tar.bz2 |
Miscellaneous tiny cleanups done while converting files to use ScopedCOMInitializer, pulled out separately to make review easier.
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/10991052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/backend/win_helper.cc | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/printing/backend/win_helper.cc b/printing/backend/win_helper.cc index 5980291..071ef54 100644 --- a/printing/backend/win_helper.cc +++ b/printing/backend/win_helper.cc @@ -239,29 +239,29 @@ HRESULT XPSModule::CloseProvider(HPTPROVIDER provider) { } ScopedXPSInitializer::ScopedXPSInitializer() : initialized_(false) { - if (XPSModule::Init()) { - // Calls to XPS APIs typically require the XPS provider to be opened with - // PTOpenProvider. PTOpenProvider calls CoInitializeEx with - // COINIT_MULTITHREADED. We have seen certain buggy HP printer driver DLLs - // that call CoInitializeEx with COINIT_APARTMENTTHREADED in the context of - // PTGetPrintCapabilities. This call fails but the printer driver calls - // CoUninitialize anyway. This results in the apartment being torn down too - // early and the msxml DLL being unloaded which in turn causes code in - // unidrvui.dll to have a dangling pointer to an XML document which causes a - // crash. To protect ourselves from such drivers we make sure we always have - // an extra CoInitialize (calls to CoInitialize/CoUninitialize are - // refcounted). - HRESULT coinit_ret = CoInitializeEx(NULL, COINIT_MULTITHREADED); - // If this succeeded we are done because the PTOpenProvider call will - // provide the extra refcount on the apartment. If it failed because someone - // already called CoInitializeEx with COINIT_APARTMENTTHREADED, we try - // the other model to provide the additional refcount (since we don't know - // which model buggy printer drivers will use). - if (coinit_ret == RPC_E_CHANGED_MODE) - coinit_ret = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - DCHECK(SUCCEEDED(coinit_ret)); - initialized_ = true; - } + if (!XPSModule::Init()) + return; + // Calls to XPS APIs typically require the XPS provider to be opened with + // PTOpenProvider. PTOpenProvider calls CoInitializeEx with + // COINIT_MULTITHREADED. We have seen certain buggy HP printer driver DLLs + // that call CoInitializeEx with COINIT_APARTMENTTHREADED in the context of + // PTGetPrintCapabilities. This call fails but the printer driver calls + // CoUninitialize anyway. This results in the apartment being torn down too + // early and the msxml DLL being unloaded which in turn causes code in + // unidrvui.dll to have a dangling pointer to an XML document which causes a + // crash. To protect ourselves from such drivers we make sure we always have + // an extra CoInitialize (calls to CoInitialize/CoUninitialize are + // refcounted). + HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + // If this succeeded we are done because the PTOpenProvider call will provide + // the extra refcount on the apartment. If it failed because someone already + // called CoInitializeEx with COINIT_APARTMENTTHREADED, we try the other model + // to provide the additional refcount (since we don't know which model buggy + // printer drivers will use). + if (!SUCCEEDED(hr)) + hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); + DCHECK(SUCCEEDED(hr)); + initialized_ = true; } ScopedXPSInitializer::~ScopedXPSInitializer() { |