Skip to content

Commit

Permalink
Bug 1707954: Part 4 - Build fixes to reflect EnsureMTA changes; r=Jamie
Browse files Browse the repository at this point in the history
Now that we always have an MTA active, we don't need to explicitly try to
start it anymore. These locations in our source were doing so, which is now
not only redundant, but fails (since `EnsureMTA`'s default constructor is now
`private`).

We also fix a spot in `JumpListBuilder` where we need a lambda to capture by
reference to fix a static analysis issue.

Differential Revision: https://phabricator.services.mozilla.com/D113563
  • Loading branch information
dblohm7 committed Jun 14, 2021
1 parent 93f41e2 commit bacaa52
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
1 change: 0 additions & 1 deletion dom/media/webrtc/CubebDeviceEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ CubebDeviceEnumerator::CubebDeviceEnumerator()
// Ensure the MTA thread exists and gets instantiated before the
// CubebDeviceEnumerator so that this instance will always gets destructed
// before the MTA thread gets shutdown.
mozilla::mscom::EnsureMTA();
mozilla::mscom::EnsureMTA([&]() -> void {
#endif
int rv = cubeb_register_device_collection_changed(
Expand Down
9 changes: 9 additions & 0 deletions js/xpconnect/src/XPCShellImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#endif

#ifdef XP_WIN
# include "mozilla/mscom/ProcessRuntime.h"
# include "mozilla/ScopeExit.h"
# include "mozilla/widget/AudioSession.h"
# include "mozilla/WinDllServices.h"
Expand Down Expand Up @@ -1099,6 +1100,14 @@ int XRE_XPCShellMain(int argc, char** argv, char** envp,
"*** You are running in chaos test mode. See ChaosMode.h. ***\n");
}

#ifdef XP_WIN
// Some COM settings are global to the process and must be set before any non-
// trivial COM is run in the application. Since these settings may affect
// stability, we should instantiate COM ASAP so that we can ensure that these
// global settings are configured before anything can interfere.
mscom::ProcessRuntime mscom;
#endif

// The provider needs to outlive the call to shutting down XPCOM.
XPCShellDirProvider dirprovider;

Expand Down
2 changes: 1 addition & 1 deletion widget/windows/JumpListBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ JumpListBuilder::JumpListBuilder()
// Instantiate mJumpListMgr in the multithreaded apartment so that proxied
// calls on that object do not need to interact with the main thread's message
// pump.
mscom::EnsureMTA([this]() {
mscom::EnsureMTA([&]() {
RefPtr<ICustomDestinationList> jumpListMgr;
HRESULT hr = ::CoCreateInstance(
CLSID_DestinationList, nullptr, CLSCTX_INPROC_SERVER,
Expand Down
20 changes: 0 additions & 20 deletions widget/windows/nsFilePicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cderr.h>

#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/mscom/EnsureMTA.h"
#include "mozilla/ProfilerLabels.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WindowsVersion.h"
Expand All @@ -28,7 +27,6 @@
using mozilla::IsWin8OrLater;
using mozilla::MakeUnique;
using mozilla::UniquePtr;
using mozilla::mscom::EnsureMTA;

using namespace mozilla::widget;

Expand Down Expand Up @@ -110,15 +108,6 @@ NS_IMETHODIMP nsFilePicker::Init(mozIDOMWindowProxy* aParent,
* @return true if a file was selected successfully.
*/
bool nsFilePicker::ShowFolderPicker(const nsString& aInitialDir) {
if (!IsWin8OrLater()) {
// Some Windows 7 users are experiencing a race condition when some dlls
// that are loaded by the file picker cause a crash while attempting to shut
// down the COM multithreaded apartment. By instantiating EnsureMTA, we hold
// an additional reference to the MTA that should prevent this race, since
// the MTA will remain alive until shutdown.
EnsureMTA ensureMTA;
}

RefPtr<IFileOpenDialog> dialog;
if (FAILED(CoCreateInstance(CLSID_FileOpenDialog, nullptr,
CLSCTX_INPROC_SERVER, IID_IFileOpenDialog,
Expand Down Expand Up @@ -206,15 +195,6 @@ bool nsFilePicker::ShowFolderPicker(const nsString& aInitialDir) {
bool nsFilePicker::ShowFilePicker(const nsString& aInitialDir) {
AUTO_PROFILER_LABEL("nsFilePicker::ShowFilePicker", OTHER);

if (!IsWin8OrLater()) {
// Some Windows 7 users are experiencing a race condition when some dlls
// that are loaded by the file picker cause a crash while attempting to shut
// down the COM multithreaded apartment. By instantiating EnsureMTA, we hold
// an additional reference to the MTA that should prevent this race, since
// the MTA will remain alive until shutdown.
EnsureMTA ensureMTA;
}

RefPtr<IFileDialog> dialog;
if (mMode != modeSave) {
if (FAILED(CoCreateInstance(CLSID_FileOpenDialog, nullptr,
Expand Down

0 comments on commit bacaa52

Please sign in to comment.