@@ -145,14 +145,14 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation
145
145
GUID taskClsid = details.TaskClsid ();
146
146
THROW_HR_IF (E_INVALIDARG, taskClsid == GUID_NULL);
147
147
148
- auto registrationOption = details.Option ();
149
- THROW_HR_IF (E_INVALIDARG, WI_AreAllFlagsClear (registrationOption, PushNotificationRegistrationOption ::PushTrigger | PushNotificationRegistrationOption ::ComActivator));
148
+ auto registrationOptions = details.Options ();
149
+ THROW_HR_IF (E_INVALIDARG, WI_AreAllFlagsClear (registrationOptions, PushNotificationRegistrationOptions ::PushTrigger | PushNotificationRegistrationOptions ::ComActivator));
150
150
151
151
DWORD cookie = 0 ;
152
152
IBackgroundTaskRegistration registeredTask = nullptr ;
153
153
BackgroundTaskBuilder builder = nullptr ;
154
154
155
- if (WI_IsFlagSet (registrationOption, PushNotificationRegistrationOption ::PushTrigger))
155
+ if (WI_IsFlagSet (registrationOptions, PushNotificationRegistrationOptions ::PushTrigger))
156
156
{
157
157
winrt::hstring taskClsidStr = winrt::to_hstring (taskClsid);
158
158
winrt::hstring backgroundTaskFullName = backgroundTaskName + taskClsidStr;
@@ -201,28 +201,28 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation
201
201
}
202
202
}
203
203
204
- bool registeredWithCom = false ;
205
- bool registeredWithBackgroundTask = false ;
204
+ BackgroundTaskRegistration registeredTaskFromBuilder = nullptr ;
206
205
207
206
auto scopeExitToCleanRegistrations = wil::scope_exit (
208
207
[&]()
209
208
{
210
- if (registeredWithCom )
209
+ if (cookie > 0 )
211
210
{
212
211
LOG_IF_FAILED (::CoRevokeClassObject (cookie));
213
212
}
214
213
215
214
// Clean the task registration only if it was created during this call
216
- if (registeredWithBackgroundTask )
215
+ if (registeredTaskFromBuilder )
217
216
{
218
217
registeredTask.Unregister (true );
219
218
}
220
219
221
220
}
222
221
);
223
222
224
- if (WI_IsFlagSet (registrationOption, PushNotificationRegistrationOption ::ComActivator))
223
+ if (WI_IsFlagSet (registrationOptions, PushNotificationRegistrationOptions ::ComActivator))
225
224
{
225
+ g_waitHandleForArgs.create ();
226
226
THROW_HR_IF_NULL (E_UNEXPECTED, g_waitHandleForArgs);
227
227
228
228
THROW_IF_FAILED (::CoRegisterClassObject (
@@ -231,34 +231,31 @@ namespace winrt::Microsoft::Windows::PushNotifications::implementation
231
231
CLSCTX_LOCAL_SERVER,
232
232
REGCLS_MULTIPLEUSE,
233
233
&cookie));
234
-
235
- registeredWithCom = true ;
236
234
}
237
235
238
236
if (builder)
239
237
{
240
- auto registeredTaskFromBuilder = builder.Register ();
241
- registeredTask = registeredTaskFromBuilder.as <IBackgroundTaskRegistration>();
242
- registeredWithBackgroundTask = true ;
238
+ registeredTaskFromBuilder = builder.Register ();
243
239
}
244
240
245
- PushNotificationRegistrationToken token = { cookie, registeredTask };
241
+ PushNotificationRegistrationToken token = { cookie, registeredTaskFromBuilder };
246
242
scopeExitToCleanRegistrations.release ();
247
243
248
244
return token;
249
245
}
250
246
251
- void PushNotificationManager::UnregisterActivator (PushNotificationRegistrationToken const & token, PushNotificationRegistrationOption const & option )
247
+ void PushNotificationManager::UnregisterActivator (PushNotificationRegistrationToken const & token, PushNotificationRegistrationOptions const & options )
252
248
{
253
249
THROW_HR_IF_NULL (E_INVALIDARG, token);
254
- if (WI_IsFlagSet (option, PushNotificationRegistrationOption ::PushTrigger))
250
+ if (WI_IsFlagSet (options, PushNotificationRegistrationOptions ::PushTrigger))
255
251
{
256
252
auto taskRegistration = token.TaskRegistration ();
257
253
THROW_HR_IF_NULL (HRESULT_FROM_WIN32 (ERROR_NOT_FOUND), taskRegistration);
258
254
taskRegistration.Unregister (true );
259
255
}
260
256
261
- if (WI_IsFlagSet (option, PushNotificationRegistrationOption::ComActivator) && token.Cookie ())
257
+ // Check for COM flag, a valid cookie and if there are outstanding locks on the PushNotificationBackgroundTask class factory
258
+ if (WI_IsFlagSet (options, PushNotificationRegistrationOptions::ComActivator) && token.Cookie () && winrt::get_module_lock () == 0 )
262
259
{
263
260
LOG_IF_FAILED (::CoRevokeClassObject (static_cast <DWORD>(token.Cookie ())));
264
261
}
0 commit comments