Skip to content

Commit 1f56a6a

Browse files
Resolves Comments
1 parent 97fc25d commit 1f56a6a

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

appcheck/firebase-appcheck-recaptchaenterprise/src/main/java/com/google/firebase/appcheck/recaptchaenterprise/RecaptchaEnterpriseAppCheckProviderFactory.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ private RecaptchaEnterpriseAppCheckProviderFactory(@NonNull String siteKey) {
4242
/** Gets an instance of this class for installation into a {@link FirebaseAppCheck} instance. */
4343
@NonNull
4444
public static RecaptchaEnterpriseAppCheckProviderFactory getInstance(@NonNull String siteKey) {
45-
return factoryInstances.computeIfAbsent(
46-
siteKey, RecaptchaEnterpriseAppCheckProviderFactory::new);
45+
RecaptchaEnterpriseAppCheckProviderFactory factory = factoryInstances.get(siteKey);
46+
if (factory == null) {
47+
synchronized (factoryInstances) {
48+
factory = factoryInstances.get(siteKey);
49+
if (factory == null) {
50+
factory = new RecaptchaEnterpriseAppCheckProviderFactory(siteKey);
51+
factoryInstances.put(siteKey, factory);
52+
}
53+
}
54+
}
55+
return factory;
4756
}
4857

4958
@NonNull
@@ -56,6 +65,7 @@ public AppCheckProvider create(@NonNull FirebaseApp firebaseApp) {
5665
ProviderMultiResourceComponent component =
5766
firebaseApp.get(ProviderMultiResourceComponent.class);
5867
provider = component.get(siteKey);
68+
provider.initializeRecaptchaClient();
5969
}
6070
}
6171
}

appcheck/firebase-appcheck-recaptchaenterprise/src/main/java/com/google/firebase/appcheck/recaptchaenterprise/internal/ProviderMultiResourceComponent.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ public final class ProviderMultiResourceComponent {
3737

3838
@NonNull
3939
public RecaptchaEnterpriseAppCheckProvider get(@NonNull String siteKey) {
40-
return instances.computeIfAbsent(siteKey, providerFactory::create);
40+
RecaptchaEnterpriseAppCheckProvider provider = instances.get(siteKey);
41+
if (provider == null) {
42+
synchronized (instances) {
43+
provider = instances.get(siteKey);
44+
if (provider == null) {
45+
provider = providerFactory.create(siteKey);
46+
instances.put(siteKey, provider);
47+
}
48+
}
49+
}
50+
return provider;
4151
}
4252

4353
@AssistedFactory

appcheck/firebase-appcheck-recaptchaenterprise/src/main/java/com/google/firebase/appcheck/recaptchaenterprise/internal/RecaptchaEnterpriseAppCheckProvider.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ public RecaptchaEnterpriseAppCheckProvider(
8989
this.recaptchaTasksClientTask = Tasks.forResult(recaptchaTasksClient);
9090
}
9191

92+
public void initializeRecaptchaClient() {
93+
if (recaptchaTasksClientTask == null) {
94+
synchronized (this) {
95+
if (recaptchaTasksClientTask == null) {
96+
Log.d(TAG, "Initializing RecaptchaTasksClient for siteKey: " + siteKey);
97+
recaptchaTasksClientTask = Recaptcha.fetchTaskClient(application, siteKey);
98+
}
99+
}
100+
}
101+
}
102+
92103
@NonNull
93104
@Override
94105
public Task<AppCheckToken> getToken() {
@@ -116,13 +127,6 @@ public Task<AppCheckToken> getToken() {
116127

117128
@NonNull
118129
private Task<String> getRecaptchaEnterpriseAttestation() {
119-
if (recaptchaTasksClientTask == null) {
120-
synchronized (this) {
121-
if (recaptchaTasksClientTask == null) {
122-
recaptchaTasksClientTask = Recaptcha.fetchTaskClient(application, siteKey);
123-
}
124-
}
125-
}
126130
return recaptchaTasksClientTask.continueWithTask(
127131
blockingExecutor,
128132
task -> {

0 commit comments

Comments
 (0)