Only unsubscribe from specified parentId

PiperOrigin-RevId: 422331961
This commit is contained in:
jaewan 2022-01-17 12:10:36 +00:00 committed by Ian Baker
parent cd56084b3e
commit 86fdbd6f6b

View file

@ -183,9 +183,7 @@ import java.util.concurrent.Future;
() -> {
@Nullable LibraryResult<Void> result = tryGetFutureResult(future);
if (result == null || result.resultCode != RESULT_SUCCESS) {
synchronized (lock) {
subscriptions.remove(checkStateNotNull(browser.getControllerCb()));
}
removeSubscription(controller, parentId);
}
},
MoreExecutors.directExecutor());
@ -203,11 +201,7 @@ import java.util.concurrent.Future;
"onUnsubscribe must return non-null future");
future.addListener(
() -> {
synchronized (lock) {
subscriptions.remove(checkStateNotNull(browser.getControllerCb()));
}
},
() -> removeSubscription(checkStateNotNull(browser.getControllerCb()), parentId),
MoreExecutors.directExecutor());
return future;
@ -307,4 +301,16 @@ import java.util.concurrent.Future;
}
}
}
private void removeSubscription(ControllerCb controllerCb, String parentId) {
synchronized (lock) {
@Nullable Set<String> subscription = subscriptions.get(controllerCb);
if (subscription != null) {
subscription.remove(parentId);
if (subscription.isEmpty()) {
subscriptions.remove(controllerCb);
}
}
}
}
}