Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fuchsia] Updates the FIDL bindings in Fuchsia-specific code #302

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/time_zone_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#endif

#if defined(__Fuchsia__)
#include <fuchsia/intl/cpp/fidl.h>
#include <fidl/fuchsia.intl/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/fdio/directory.h>
#include <zircon/types.h>
Expand Down Expand Up @@ -218,32 +218,31 @@ time_zone local_time_zone() {
// Note: We can't use the synchronous FIDL API here because it doesn't
// allow timeouts; if the FIDL call failed, local_time_zone() would never
// return.

const zx::duration kTimeout = zx::msec(500);

// Don't attach to the thread because otherwise the thread's dispatcher
// would be set to null when the loop is destroyed, causing any other FIDL
// code running on the same thread to crash.
async::Loop loop(&kAsyncLoopConfigNeverAttachToThread);

fuchsia::intl::PropertyProviderHandle handle;
auto endpoints =
fidl::Endpoints<fuchsia_intl::PropertyProvider>::Create();
zx_status_t status = fdio_service_connect_by_name(
fuchsia::intl::PropertyProvider::Name_,
handle.NewRequest().TakeChannel().release());
fidl::DiscoverableProtocolName<fuchsia_intl::PropertyProvider>,
endpoints.server.TakeChannel().release());
if (status != ZX_OK) {
return;
}

fuchsia::intl::PropertyProviderPtr intl_provider;
status = intl_provider.Bind(std::move(handle), loop.dispatcher());
if (status != ZX_OK) {
return;
}

intl_provider->GetProfile(
[&loop, &primary_tz](fuchsia::intl::Profile profile) {
if (!profile.time_zones().empty()) {
primary_tz = profile.time_zones()[0].id;
fidl::Client intl_provider(
std::move(endpoints.client), loop.dispatcher());

// Attempt to initialize the time zone only once, and fail quietly.
// The end result of an error is an empty time zone string.
intl_provider->GetProfile().Then(
[&loop, &primary_tz](
fidl::Result<fuchsia_intl::PropertyProvider::GetProfile>& result) {
if (result.is_ok()) {
const auto& response = result.value();
primary_tz = response.profile().time_zones().value()[0].id();
}
loop.Quit();
});
Expand Down