@@ -33,23 +33,29 @@ Future<std::string> InstanceId::GetId() const {
33
33
const auto future_handle = instance_id_internal_->FutureAlloc <std::string>(
34
34
InstanceIdInternal::kApiFunctionGetId );
35
35
36
- const auto internal_future = instance_id_internal_->impl ()->GetId ();
37
- InstanceIdInternal::InternalRef& internal_ref =
38
- instance_id_internal_->safe_ref ();
39
- internal_future.OnCompletion (
40
- [&internal_ref, future_handle](const Future<std::string>& result) {
41
- InstanceIdInternal::InternalRefLock lock (&internal_ref);
42
- if (lock.GetReference () == nullptr ) {
43
- return ; // deleted.
44
- }
45
- if (result.error () == 0 ) {
46
- lock.GetReference ()->future_api ().CompleteWithResult (
47
- future_handle, kErrorNone , " " , std::string (*result.result ()));
48
- } else {
49
- lock.GetReference ()->future_api ().Complete (
50
- future_handle, kErrorUnknown , result.error_message ());
51
- }
52
- });
36
+ if (instance_id_internal_->impl ()) {
37
+ const auto internal_future = instance_id_internal_->impl ()->GetId ();
38
+ InstanceIdInternal::InternalRef& internal_ref =
39
+ instance_id_internal_->safe_ref ();
40
+ internal_future.OnCompletion (
41
+ [&internal_ref, future_handle](const Future<std::string>& result) {
42
+ InstanceIdInternal::InternalRefLock lock (&internal_ref);
43
+ if (lock.GetReference () == nullptr ) {
44
+ return ; // deleted.
45
+ }
46
+ if (result.error () == 0 ) {
47
+ lock.GetReference ()->future_api ().CompleteWithResult (
48
+ future_handle, kErrorNone , " " , std::string (*result.result ()));
49
+ } else {
50
+ lock.GetReference ()->future_api ().Complete (
51
+ future_handle, kErrorUnknown , result.error_message ());
52
+ }
53
+ });
54
+ } else {
55
+ // If there is no InstanceIdDesktopImpl, run as a stub.
56
+ instance_id_internal_->future_api ().CompleteWithResult (
57
+ future_handle, kErrorNone , " " , std::string (" FakeId" ));
58
+ }
53
59
return MakeFuture (&instance_id_internal_->future_api (), future_handle);
54
60
}
55
61
@@ -59,24 +65,29 @@ Future<void> InstanceId::DeleteId() {
59
65
const auto future_handle = instance_id_internal_->FutureAlloc <void >(
60
66
InstanceIdInternal::kApiFunctionDeleteId );
61
67
62
- const auto internal_future = instance_id_internal_->impl ()->DeleteId ();
63
-
64
- InstanceIdInternal::InternalRef& internal_ref =
65
- instance_id_internal_->safe_ref ();
66
- internal_future.OnCompletion ([&internal_ref,
67
- future_handle](const Future<void >& result) {
68
- InstanceIdInternal::InternalRefLock lock (&internal_ref);
69
- if (lock.GetReference () == nullptr ) {
70
- return ; // deleted.
71
- }
72
- if (result.error () == 0 ) {
73
- lock.GetReference ()->future_api ().Complete (future_handle, kErrorNone , " " );
74
- } else {
75
- lock.GetReference ()->future_api ().Complete (future_handle, kErrorUnknown ,
76
- result.error_message ());
77
- }
78
- });
79
-
68
+ if (instance_id_internal_->impl ()) {
69
+ const auto internal_future = instance_id_internal_->impl ()->DeleteId ();
70
+
71
+ InstanceIdInternal::InternalRef& internal_ref =
72
+ instance_id_internal_->safe_ref ();
73
+ internal_future.OnCompletion (
74
+ [&internal_ref, future_handle](const Future<void >& result) {
75
+ InstanceIdInternal::InternalRefLock lock (&internal_ref);
76
+ if (lock.GetReference () == nullptr ) {
77
+ return ; // deleted.
78
+ }
79
+ if (result.error () == 0 ) {
80
+ lock.GetReference ()->future_api ().Complete (future_handle,
81
+ kErrorNone , " " );
82
+ } else {
83
+ lock.GetReference ()->future_api ().Complete (
84
+ future_handle, kErrorUnknown , result.error_message ());
85
+ }
86
+ });
87
+ } else {
88
+ // If there is no InstanceIdDesktopImpl, run as a stub.
89
+ instance_id_internal_->future_api ().Complete (future_handle, kErrorNone , " " );
90
+ }
80
91
return MakeFuture (&instance_id_internal_->future_api (), future_handle);
81
92
}
82
93
@@ -87,24 +98,30 @@ Future<std::string> InstanceId::GetToken(const char* entity,
87
98
const auto future_handle = instance_id_internal_->FutureAlloc <std::string>(
88
99
InstanceIdInternal::kApiFunctionGetToken );
89
100
90
- const auto internal_future = instance_id_internal_->impl ()->GetToken (scope);
91
-
92
- InstanceIdInternal::InternalRef& internal_ref =
93
- instance_id_internal_->safe_ref ();
94
- internal_future.OnCompletion (
95
- [&internal_ref, future_handle](const Future<std::string>& result) {
96
- InstanceIdInternal::InternalRefLock lock (&internal_ref);
97
- if (lock.GetReference () == nullptr ) {
98
- return ; // deleted.
99
- }
100
- if (result.error () == 0 ) {
101
- lock.GetReference ()->future_api ().CompleteWithResult (
102
- future_handle, kErrorNone , " " , std::string (*result.result ()));
103
- } else {
104
- lock.GetReference ()->future_api ().Complete (
105
- future_handle, kErrorUnknown , result.error_message ());
106
- }
107
- });
101
+ if (instance_id_internal_->impl ()) {
102
+ const auto internal_future = instance_id_internal_->impl ()->GetToken (scope);
103
+
104
+ InstanceIdInternal::InternalRef& internal_ref =
105
+ instance_id_internal_->safe_ref ();
106
+ internal_future.OnCompletion (
107
+ [&internal_ref, future_handle](const Future<std::string>& result) {
108
+ InstanceIdInternal::InternalRefLock lock (&internal_ref);
109
+ if (lock.GetReference () == nullptr ) {
110
+ return ; // deleted.
111
+ }
112
+ if (result.error () == 0 ) {
113
+ lock.GetReference ()->future_api ().CompleteWithResult (
114
+ future_handle, kErrorNone , " " , std::string (*result.result ()));
115
+ } else {
116
+ lock.GetReference ()->future_api ().Complete (
117
+ future_handle, kErrorUnknown , result.error_message ());
118
+ }
119
+ });
120
+ } else {
121
+ // If there is no InstanceIdDesktopImpl, run as a stub.
122
+ instance_id_internal_->future_api ().CompleteWithResult (
123
+ future_handle, kErrorNone , " " , std::string (" FakeToken" ));
124
+ }
108
125
return MakeFuture (&instance_id_internal_->future_api (), future_handle);
109
126
}
110
127
@@ -114,24 +131,30 @@ Future<void> InstanceId::DeleteToken(const char* entity, const char* scope) {
114
131
const auto future_handle = instance_id_internal_->FutureAlloc <void >(
115
132
InstanceIdInternal::kApiFunctionDeleteToken );
116
133
117
- const auto internal_future =
118
- instance_id_internal_->impl ()->DeleteToken (scope);
119
- InstanceIdInternal::InternalRef& internal_ref =
120
- instance_id_internal_->safe_ref ();
121
-
122
- internal_future.OnCompletion ([&internal_ref,
123
- future_handle](const Future<void >& result) {
124
- InstanceIdInternal::InternalRefLock lock (&internal_ref);
125
- if (lock.GetReference () == nullptr ) {
126
- return ; // deleted.
127
- }
128
- if (result.error () == 0 ) {
129
- lock.GetReference ()->future_api ().Complete (future_handle, kErrorNone , " " );
130
- } else {
131
- lock.GetReference ()->future_api ().Complete (future_handle, kErrorUnknown ,
132
- result.error_message ());
133
- }
134
- });
134
+ if (instance_id_internal_->impl ()) {
135
+ const auto internal_future =
136
+ instance_id_internal_->impl ()->DeleteToken (scope);
137
+ InstanceIdInternal::InternalRef& internal_ref =
138
+ instance_id_internal_->safe_ref ();
139
+
140
+ internal_future.OnCompletion (
141
+ [&internal_ref, future_handle](const Future<void >& result) {
142
+ InstanceIdInternal::InternalRefLock lock (&internal_ref);
143
+ if (lock.GetReference () == nullptr ) {
144
+ return ; // deleted.
145
+ }
146
+ if (result.error () == 0 ) {
147
+ lock.GetReference ()->future_api ().Complete (future_handle,
148
+ kErrorNone , " " );
149
+ } else {
150
+ lock.GetReference ()->future_api ().Complete (
151
+ future_handle, kErrorUnknown , result.error_message ());
152
+ }
153
+ });
154
+ } else {
155
+ // If there is no InstanceIdDesktopImpl, run as a stub.
156
+ instance_id_internal_->future_api ().Complete (future_handle, kErrorNone , " " );
157
+ }
135
158
return MakeFuture (&instance_id_internal_->future_api (), future_handle);
136
159
}
137
160
0 commit comments