20
20
#include < sstream>
21
21
22
22
#include " firebase/app.h"
23
+ #ifdef FIREBASE_EARLY_ACCESS_PREVIEW
23
24
#include " app/instance_id/instance_id_desktop_impl.h"
25
+ #endif
24
26
#include " app/meta/move.h"
25
27
#include " app/rest/request_binary.h"
26
28
#include " app/rest/response_binary.h"
@@ -50,6 +52,35 @@ const int SDK_PATCH_VERSION = 0;
50
52
51
53
const char kTokenScope [] = " *" ;
52
54
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
+
53
84
RemoteConfigREST::RemoteConfigREST (const firebase::AppOptions& app_options,
54
85
const LayeredConfigs& configs,
55
86
uint64_t cache_expiration_in_seconds)
@@ -74,32 +105,8 @@ void RemoteConfigREST::Fetch(const App& app) {
74
105
ParseRestResponse ();
75
106
}
76
107
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
-
102
108
void RemoteConfigREST::TryGetInstanceIdAndToken (const App& app) {
109
+ #ifdef FIREBASE_EARLY_ACCESS_PREVIEW
103
110
// Convert the app reference stored in RemoteConfigDesktop
104
111
// pointer for InstanceIdDesktopImpl.
105
112
App* non_const_app = const_cast <App*>(&app);
@@ -111,14 +118,15 @@ void RemoteConfigREST::TryGetInstanceIdAndToken(const App& app) {
111
118
return ;
112
119
}
113
120
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" );
116
123
117
124
// Only get token if instance id is retrieved.
118
125
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" );
121
128
}
129
+ #endif
122
130
}
123
131
124
132
void RemoteConfigREST::SetupRestRequest () {
0 commit comments