2020#include < sstream>
2121
2222#include " firebase/app.h"
23+ #ifdef FIREBASE_EARLY_ACCESS_PREVIEW
2324#include " app/instance_id/instance_id_desktop_impl.h"
25+ #endif
2426#include " app/meta/move.h"
2527#include " app/rest/request_binary.h"
2628#include " app/rest/response_binary.h"
@@ -50,6 +52,35 @@ const int SDK_PATCH_VERSION = 0;
5052
5153const char kTokenScope [] = " *" ;
5254
55+ namespace {
56+ #ifdef FIREBASE_EARLY_ACCESS_PREVIEW
57+ void WaitForInstanceIdFuture (const Future<std::string>& future,
58+ Semaphore* future_sem, std::string* result, const char * action_name) {
59+ // Block and wait until Future is complete.
60+ future.OnCompletion (
61+ [](const firebase::Future<std::string>& result, void * data) {
62+ Semaphore* sem = static_cast <Semaphore*>(data);
63+ sem->Post ();
64+ },
65+ future_sem);
66+ future_sem->Wait ();
67+
68+ if (future.status () == firebase::kFutureStatusComplete &&
69+ future.error () ==
70+ firebase::instance_id::internal::InstanceIdDesktopImpl::kErrorNone ) {
71+ *result = *future.result ();
72+ } else if (future.status () != firebase::kFutureStatusComplete ) {
73+ // It is fine if timeout
74+ LogWarning (" Remote Config Fetch: %s timeout" , action_name);
75+ } else {
76+ // It is fine if failed
77+ LogWarning (" Remote Config Fetch: Failed to %s. Error %d: %s" , action_name,
78+ future.error (), future.error_message ());
79+ }
80+ }
81+ #endif
82+ } // namespace
83+
5384RemoteConfigREST::RemoteConfigREST (const firebase::AppOptions& app_options,
5485 const LayeredConfigs& configs,
5586 uint64_t cache_expiration_in_seconds)
@@ -74,32 +105,8 @@ void RemoteConfigREST::Fetch(const App& app) {
74105 ParseRestResponse ();
75106}
76107
77- void WaitForFuture (const Future<std::string>& future, Semaphore* future_sem,
78- std::string* result, const char * action_name) {
79- // Block and wait until Future is complete.
80- future.OnCompletion (
81- [](const firebase::Future<std::string>& result, void * data) {
82- Semaphore* sem = static_cast <Semaphore*>(data);
83- sem->Post ();
84- },
85- future_sem);
86- future_sem->Wait ();
87-
88- if (future.status () == firebase::kFutureStatusComplete &&
89- future.error () ==
90- firebase::instance_id::internal::InstanceIdDesktopImpl::kErrorNone ) {
91- *result = *future.result ();
92- } else if (future.status () != firebase::kFutureStatusComplete ) {
93- // It is fine if timeout
94- LogWarning (" Remote Config Fetch: %s timeout" , action_name);
95- } else {
96- // It is fine if failed
97- LogWarning (" Remote Config Fetch: Failed to %s. Error %d: %s" , action_name,
98- future.error (), future.error_message ());
99- }
100- }
101-
102108void RemoteConfigREST::TryGetInstanceIdAndToken (const App& app) {
109+ #ifdef FIREBASE_EARLY_ACCESS_PREVIEW
103110 // Convert the app reference stored in RemoteConfigDesktop
104111 // pointer for InstanceIdDesktopImpl.
105112 App* non_const_app = const_cast <App*>(&app);
@@ -111,14 +118,15 @@ void RemoteConfigREST::TryGetInstanceIdAndToken(const App& app) {
111118 return ;
112119 }
113120
114- WaitForFuture (iid_impl->GetId (), &fetch_future_sem_, &app_instance_id_ ,
115- " Get Instance Id" );
121+ WaitForInstanceIdFuture (iid_impl->GetId (), &fetch_future_sem_,
122+ &app_instance_id_, " Get Instance Id" );
116123
117124 // Only get token if instance id is retrieved.
118125 if (!app_instance_id_.empty ()) {
119- WaitForFuture (iid_impl->GetToken (kTokenScope ), &fetch_future_sem_,
120- &app_instance_id_token_, " Get Instance Id Token" );
126+ WaitForInstanceIdFuture (iid_impl->GetToken (kTokenScope ), &fetch_future_sem_,
127+ &app_instance_id_token_, " Get Instance Id Token" );
121128 }
129+ #endif
122130}
123131
124132void RemoteConfigREST::SetupRestRequest () {
0 commit comments