Skip to content

Commit 2296ff3

Browse files
smilesa-maurice
authored andcommitted
Removed use of deprecated FutureHandle in Remote Config
Also: - Removed use of deprecated activate method in FIRRemoteConfig - Changed Android activate method to pass a couple of the future handle class rather than type punning to a void*. PiperOrigin-RevId: 264714930
1 parent 590361b commit 2296ff3

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

remote_config/src/desktop/remote_config_desktop.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ const ConfigInfo& RemoteConfigDesktop::GetInfo() const {
364364

365365
void RemoteConfigDesktop::AsyncFetch() {
366366
fetch_thread_ = std::thread([this]() {
367-
FutureHandle handle;
367+
SafeFutureHandle<void> handle;
368368
while (fetch_channel_.Get()) {
369369
RemoteConfigREST* rest = nullptr;
370370

@@ -425,7 +425,7 @@ Future<void> RemoteConfigDesktop::Fetch(uint64_t cache_expiration_in_seconds) {
425425
((cache_expiration_in_seconds == 0) ||
426426
(cache_expiration_timestamp < milliseconds_since_epoch))) {
427427
ReferenceCountedFutureImpl* api = FutureData::Get()->api();
428-
fetch_handle_ = api->Alloc<void>(kRemoteConfigFnFetch);
428+
fetch_handle_ = api->SafeAlloc<void>(kRemoteConfigFnFetch);
429429
is_fetch_process_have_task_ = true;
430430
fetch_channel_.Put();
431431
cache_expiration_in_seconds_ = cache_expiration_in_seconds;

remote_config/src/desktop/remote_config_desktop.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <string>
2020
#include <thread> // NOLINT
2121

22+
#include "app/src/reference_counted_future_impl.h"
2223
#include "firebase/app.h"
2324
#include "firebase/future.h"
2425
#include "remote_config/src/desktop/config_data.h"
@@ -178,7 +179,7 @@ class RemoteConfigDesktop {
178179

179180
// Create new FutureHandle when it's possible to start fetching and complete
180181
// future with `fetch_handle_` after fetching.
181-
FutureHandle fetch_handle_;
182+
firebase::SafeFutureHandle<void> fetch_handle_;
182183

183184
// Last value of `Fetch` function argument. Update only if we will fetch.
184185
uint64_t cache_expiration_in_seconds_;

remote_config/src/remote_config_android.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,30 +665,32 @@ static void FutureCallback(JNIEnv* env, jobject result,
665665
}
666666
// If the API has being shut down this will be nullptr.
667667
FutureData* future_data = FutureData::Get();
668+
auto* future_handle =
669+
reinterpret_cast<SafeFutureHandle<void>*>(callback_data);
668670
if (future_data) {
669-
future_data->api()->Complete(reinterpret_cast<FutureHandle>(callback_data),
671+
future_data->api()->Complete(*future_handle,
670672
success ? kFetchFutureStatusSuccess
671673
: kFetchFutureStatusFailure);
672674
}
675+
delete future_handle;
673676
}
674677

675678
Future<void> Fetch(uint64_t cache_expiration_in_seconds) {
676679
FIREBASE_ASSERT_RETURN(FetchLastResult(), internal::IsInitialized());
677680
// Create the future.
678681
ReferenceCountedFutureImpl* api = FutureData::Get()->api();
679-
const FutureHandle handle = api->Alloc<void>(kRemoteConfigFnFetch);
682+
const auto handle = api->SafeAlloc<void>(kRemoteConfigFnFetch);
680683
JNIEnv* env = g_app->GetJNIEnv();
681684
jobject task = env->CallObjectMethod(
682685
g_remote_config_class_instance, config::GetMethodId(config::kFetch),
683686
static_cast<jlong>(cache_expiration_in_seconds));
684687

685-
util::RegisterCallbackOnTask(env, task, FutureCallback,
686-
*(reinterpret_cast<void* const*>(&handle)),
687-
kApiIdentifier);
688+
util::RegisterCallbackOnTask(
689+
env, task, FutureCallback, new SafeFutureHandle<void>(handle),
690+
kApiIdentifier);
688691

689692
env->DeleteLocalRef(task);
690-
return static_cast<const Future<void>&>(
691-
api->LastResult(kRemoteConfigFnFetch));
693+
return MakeFuture<void>(api, handle);
692694
}
693695

694696
Future<void> FetchLastResult() {

remote_config/src/remote_config_ios.mm

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ void SetDefaults(const ConfigKeyValueVariant *defaults, size_t number_of_default
151151
FIREBASE_ASSERT_RETURN(std::string(), internal::IsInitialized());
152152
switch (setting) {
153153
case kConfigSettingDeveloperMode:
154-
return g_remote_config_instance.configSettings.isDeveloperModeEnabled ? "1" : "0";
154+
// This setting is deprecated.
155+
LogWarning("Remote Config: Developer mode setting is deprecated.");
156+
return "1";
155157
default:
156158
LogError("Remote Config: GetConfigSetting called with unknown setting: %d", setting);
157159
return std::string();
@@ -161,8 +163,7 @@ void SetDefaults(const ConfigKeyValueVariant *defaults, size_t number_of_default
161163
void SetConfigSetting(ConfigSetting setting, const char *value) {
162164
switch (setting) {
163165
case kConfigSettingDeveloperMode:
164-
g_remote_config_instance.configSettings =
165-
[[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:@(value).boolValue];
166+
LogWarning("Remote Config: Developer mode setting is deprecated.");
166167
break;
167168
default:
168169
LogError("Remote Config: SetConfigSetting called with unknown setting: %d", setting);
@@ -309,7 +310,7 @@ static void CheckDoubleConversion(FIRRemoteConfigValue *value, ValueInfo *info)
309310
Future<void> Fetch(uint64_t cache_expiration_in_seconds) {
310311
FIREBASE_ASSERT_RETURN(FetchLastResult(), internal::IsInitialized());
311312
ReferenceCountedFutureImpl *api = FutureData::Get()->api();
312-
const FutureHandle handle = api->Alloc<void>(kRemoteConfigFnFetch);
313+
const auto handle = api->SafeAlloc<void>(kRemoteConfigFnFetch);
313314

314315
FIRRemoteConfigFetchCompletion completion = ^(FIRRemoteConfigFetchStatus status, NSError *error) {
315316
if (error) {
@@ -327,13 +328,13 @@ static void CheckDoubleConversion(FIRRemoteConfigValue *value, ValueInfo *info)
327328
"Fetch encountered an error.");
328329
} else {
329330
// Everything worked!
330-
api->Complete(handle, kFetchFutureStatusSuccess, nullptr);
331+
api->Complete(handle, kFetchFutureStatusSuccess);
331332
}
332333
};
333334
[g_remote_config_instance fetchWithExpirationDuration:cache_expiration_in_seconds
334335
completionHandler:completion];
335336

336-
return static_cast<const Future<void> &>(api->LastResult(kRemoteConfigFnFetch));
337+
return MakeFuture<void>(api, handle);
337338
}
338339

339340
Future<void> FetchLastResult() {
@@ -344,7 +345,14 @@ static void CheckDoubleConversion(FIRRemoteConfigValue *value, ValueInfo *info)
344345

345346
bool ActivateFetched() {
346347
FIREBASE_ASSERT_RETURN(false, internal::IsInitialized());
347-
return static_cast<bool>([g_remote_config_instance activateFetched]);
348+
__block bool succeeded = true;
349+
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
350+
[g_remote_config_instance activateWithCompletionHandler:^(NSError *_Nullable error) {
351+
if (error) succeeded = false;
352+
dispatch_semaphore_signal(semaphore);
353+
}];
354+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
355+
return succeeded;
348356
}
349357

350358
const ConfigInfo &GetInfo() {

0 commit comments

Comments
 (0)