Skip to content

Commit c603f63

Browse files
committed
Bug 1489317: Part 4 - Add asssertion that COM is initialized on the thread that is resolving an agile reference; r=mhowell
Depends on D5321 Differential Revision: https://phabricator.services.mozilla.com/D5323 --HG-- extra : moz-landing-system : lando
1 parent 543d327 commit c603f63

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

ipc/mscom/AgileReference.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
#include "mozilla/mscom/AgileReference.h"
88

9+
#include "mozilla/Assertions.h"
910
#include "mozilla/DebugOnly.h"
1011
#include "mozilla/DynamicallyLinkedFunctionPtr.h"
11-
#include "mozilla/Assertions.h"
1212
#include "mozilla/Move.h"
13+
#include "mozilla/mscom/Utils.h"
1314

1415
#if NTDDI_VERSION < NTDDI_WINBLUE
1516

@@ -137,6 +138,7 @@ AgileReference::Resolve(REFIID aIid, void** aOutInterface) const
137138
{
138139
MOZ_ASSERT(aOutInterface);
139140
MOZ_ASSERT(mAgileRef || mGitCookie);
141+
MOZ_ASSERT(IsCOMInitializedOnCurrentThread());
140142

141143
if (!aOutInterface) {
142144
return E_INVALIDARG;

ipc/mscom/Utils.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
3232
namespace mozilla {
3333
namespace mscom {
3434

35+
bool
36+
IsCOMInitializedOnCurrentThread()
37+
{
38+
APTTYPE aptType;
39+
APTTYPEQUALIFIER aptTypeQualifier;
40+
HRESULT hr = CoGetApartmentType(&aptType, &aptTypeQualifier);
41+
return hr != CO_E_NOTINITIALIZED;
42+
}
43+
3544
bool
3645
IsCurrentThreadMTA()
3746
{

ipc/mscom/Utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct IUnknown;
2020
namespace mozilla {
2121
namespace mscom {
2222

23+
bool IsCOMInitializedOnCurrentThread();
2324
bool IsCurrentThreadMTA();
2425
bool IsProxy(IUnknown* aUnknown);
2526
bool IsValidGUID(REFGUID aCheckGuid);

widget/windows/JumpListBuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ NS_IMETHODIMP JumpListBuilder::InitListBuild(JSContext* aCx,
229229

230230
void JumpListBuilder::DoInitListBuild(RefPtr<Promise>&& aPromise)
231231
{
232+
// Since we're invoking COM interfaces to talk to the shell on a background
233+
// thread, we need to be running inside a single-threaded apartment.
232234
mscom::STARegion sta;
233235
MOZ_ASSERT(sta.IsValid());
234236

@@ -515,6 +517,8 @@ NS_IMETHODIMP JumpListBuilder::CommitListBuild(nsIJumpListCommittedCallback* aCa
515517

516518
void JumpListBuilder::DoCommitListBuild(RefPtr<detail::DoneCommitListBuildCallback> aCallback)
517519
{
520+
// Since we're invoking COM interfaces to talk to the shell on a background
521+
// thread, we need to be running inside a single-threaded apartment.
518522
mscom::STARegion sta;
519523
MOZ_ASSERT(sta.IsValid());
520524

0 commit comments

Comments
 (0)