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