|
26 | 26 | #endif |
27 | 27 |
|
28 | 28 | #if defined(__Fuchsia__) |
29 | | -#include <fuchsia/intl/cpp/fidl.h> |
| 29 | +#include <fidl/fuchsia.intl/cpp/fidl.h> |
30 | 30 | #include <lib/async-loop/cpp/loop.h> |
31 | 31 | #include <lib/fdio/directory.h> |
32 | 32 | #include <zircon/types.h> |
@@ -219,32 +219,29 @@ time_zone local_time_zone() { |
219 | 219 | // Note: We can't use the synchronous FIDL API here because it doesn't |
220 | 220 | // allow timeouts; if the FIDL call failed, local_time_zone() would never |
221 | 221 | // return. |
222 | | - |
223 | 222 | const zx::duration kTimeout = zx::msec(500); |
224 | 223 |
|
225 | 224 | // Don't attach to the thread because otherwise the thread's dispatcher |
226 | 225 | // would be set to null when the loop is destroyed, causing any other FIDL |
227 | 226 | // code running on the same thread to crash. |
228 | 227 | async::Loop loop(&kAsyncLoopConfigNeverAttachToThread); |
229 | | - |
230 | | - fuchsia::intl::PropertyProviderHandle handle; |
| 228 | + auto endpoints = fidl::Endpoints<fuchsia_intl::PropertyProvider>::Create(); |
231 | 229 | zx_status_t status = fdio_service_connect_by_name( |
232 | | - fuchsia::intl::PropertyProvider::Name_, |
233 | | - handle.NewRequest().TakeChannel().release()); |
| 230 | + fidl::DiscoverableProtocolName<fuchsia_intl::PropertyProvider>, |
| 231 | + endpoints.server.TakeChannel().release()); |
234 | 232 | if (status != ZX_OK) { |
235 | 233 | return; |
236 | 234 | } |
237 | | - |
238 | | - fuchsia::intl::PropertyProviderPtr intl_provider; |
239 | | - status = intl_provider.Bind(std::move(handle), loop.dispatcher()); |
240 | | - if (status != ZX_OK) { |
241 | | - return; |
242 | | - } |
243 | | - |
244 | | - intl_provider->GetProfile( |
245 | | - [&loop, &primary_tz](fuchsia::intl::Profile profile) { |
246 | | - if (!profile.time_zones().empty()) { |
247 | | - primary_tz = profile.time_zones()[0].id; |
| 235 | + fidl::Client intl_provider(std::move(endpoints.client), loop.dispatcher()); |
| 236 | + |
| 237 | + // Attempt to initialize the time zone only once, and fail quietly. |
| 238 | + // The end result of an error is an empty time zone string. |
| 239 | + intl_provider->GetProfile().Then( |
| 240 | + [&loop, &primary_tz]( |
| 241 | + fidl::Result<fuchsia_intl::PropertyProvider::GetProfile>& result) { |
| 242 | + if (result.is_ok()) { |
| 243 | + const auto& response = result.value(); |
| 244 | + primary_tz = response.profile().time_zones().value()[0].id(); |
248 | 245 | } |
249 | 246 | loop.Quit(); |
250 | 247 | }); |
|
0 commit comments