Commit 18f6ea3c authored by Jeremy Manson's avatar Jeremy Manson Committed by Commit Bot

[Fuchsia] Migrate Chromium to new epitaph-friendly error handlers.

R=kmarshall@chromium.org, sky@chromium.org, wez@google.com

Bug: FIDL-319
Change-Id: I536f7cbaa670b439be621bcda8439a9d4597ee41
Reviewed-on: https://chromium-review.googlesource.com/c/1324918
Commit-Queue: Jeremy Manson <jeremymanson@google.com>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607740}
parent 357bef2f
......@@ -33,7 +33,7 @@ TEST_F(FilteredServiceDirectoryTest, Connect) {
auto stub =
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, false);
VerifyTestInterface(&stub, ZX_OK);
}
// Verify that multiple connections to the same service work properly.
......@@ -44,15 +44,15 @@ TEST_F(FilteredServiceDirectoryTest, ConnectMultiple) {
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
auto stub2 =
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub1, false);
VerifyTestInterface(&stub2, false);
VerifyTestInterface(&stub1, ZX_OK);
VerifyTestInterface(&stub2, ZX_OK);
}
// Verify that non-whitelisted services are blocked.
TEST_F(FilteredServiceDirectoryTest, ServiceBlocked) {
auto stub =
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, true);
VerifyTestInterface(&stub, ZX_ERR_PEER_CLOSED);
}
// Verify that FilteredServiceDirectory handles the case when the target service
......@@ -64,7 +64,7 @@ TEST_F(FilteredServiceDirectoryTest, NoService) {
auto stub =
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, true);
VerifyTestInterface(&stub, ZX_ERR_PEER_CLOSED);
}
// Verify that FilteredServiceDirectory handles the case when the underlying
......@@ -77,7 +77,7 @@ TEST_F(FilteredServiceDirectoryTest, NoServiceDir) {
auto stub =
filtered_client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, true);
VerifyTestInterface(&stub, ZX_ERR_PEER_CLOSED);
}
} // namespace fuchsia
......
......@@ -54,13 +54,13 @@ void ServiceDirectoryTestBase::ConnectClientContextToDirectory(
void ServiceDirectoryTestBase::VerifyTestInterface(
fidl::InterfacePtr<testfidl::TestInterface>* stub,
bool expect_error) {
zx_status_t expected_error) {
// Call the service and wait for response.
base::RunLoop run_loop;
bool error = false;
zx_status_t actual_error = ZX_OK;
stub->set_error_handler([&run_loop, &error]() {
error = true;
stub->set_error_handler([&run_loop, &actual_error](zx_status_t status) {
actual_error = status;
run_loop.Quit();
});
......@@ -71,11 +71,11 @@ void ServiceDirectoryTestBase::VerifyTestInterface(
run_loop.Run();
EXPECT_EQ(error, expect_error);
EXPECT_EQ(expected_error, actual_error);
// Reset error handler because the current one captures |run_loop| and
// |error| references which are about to be destroyed.
stub->set_error_handler([]() {});
stub->set_error_handler(nullptr);
}
} // namespace fuchsia
......
......@@ -32,7 +32,7 @@ class ServiceDirectoryTestBase : public testing::Test {
void ConnectClientContextToDirectory(const char* path);
void VerifyTestInterface(fidl::InterfacePtr<testfidl::TestInterface>* stub,
bool expect_error);
zx_status_t expected_error);
protected:
MessageLoopForIO message_loop_;
......
......@@ -27,7 +27,7 @@ class ServiceDirectoryTest : public ServiceDirectoryTestBase {};
// destroyed.
TEST_F(ServiceDirectoryTest, ConnectDisconnect) {
auto stub = client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, false);
VerifyTestInterface(&stub, ZX_OK);
base::RunLoop run_loop;
service_binding_->SetOnLastClientCallback(run_loop.QuitClosure());
......@@ -50,15 +50,15 @@ TEST_F(ServiceDirectoryTest, ConnectDisconnect) {
TEST_F(ServiceDirectoryTest, ConnectMulti) {
auto stub = client_context_->ConnectToService<testfidl::TestInterface>();
auto stub2 = client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, false);
VerifyTestInterface(&stub2, false);
VerifyTestInterface(&stub, ZX_OK);
VerifyTestInterface(&stub2, ZX_OK);
}
// Verify that services are also exported to the legacy flat service namespace.
TEST_F(ServiceDirectoryTest, ConnectLegacy) {
ConnectClientContextToDirectory(".");
auto stub = client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, false);
VerifyTestInterface(&stub, ZX_OK);
}
// Verify that ComponentContext can handle the case when the service directory
......@@ -72,14 +72,14 @@ TEST_F(ServiceDirectoryTest, DirectoryGone) {
client_context_->ConnectToService(FidlInterfaceRequest(&stub));
EXPECT_EQ(status, ZX_ERR_PEER_CLOSED);
VerifyTestInterface(&stub, true);
VerifyTestInterface(&stub, ZX_ERR_PEER_CLOSED);
}
// Verify that the case when the service doesn't exist is handled properly.
TEST_F(ServiceDirectoryTest, NoService) {
service_binding_.reset();
auto stub = client_context_->ConnectToService<testfidl::TestInterface>();
VerifyTestInterface(&stub, true);
VerifyTestInterface(&stub, ZX_ERR_PEER_CLOSED);
}
} // namespace fuchsia
......
......@@ -56,7 +56,7 @@ bool MixerOutputStreamFuchsia::Start(int requested_sample_rate, int channels) {
->ConnectToService<fuchsia::media::Audio>();
audio_server->CreateAudioRenderer(audio_renderer_.NewRequest());
audio_renderer_.set_error_handler(
fit::bind_member(this, &MixerOutputStreamFuchsia::OnRendererError));
[this](zx_status_t status) { this->OnRendererError(status); });
// Configure the renderer.
fuchsia::media::AudioStreamType format;
......@@ -202,8 +202,8 @@ base::TimeTicks MixerOutputStreamFuchsia::GetCurrentStreamTime() {
stream_position_samples_, sample_rate_);
}
void MixerOutputStreamFuchsia::OnRendererError() {
LOG(WARNING) << "AudioRenderer has failed.";
void MixerOutputStreamFuchsia::OnRendererError(zx_status_t status) {
LOG(WARNING) << "AudioRenderer has failed with code " << status;
Stop();
}
......
......@@ -38,7 +38,7 @@ class MixerOutputStreamFuchsia : public MixerOutputStream {
base::TimeTicks GetCurrentStreamTime();
// Event handlers for |audio_renderer_|.
void OnRendererError();
void OnRendererError(zx_status_t status);
void OnMinLeadTimeChanged(int64_t min_lead_time);
int sample_rate_ = 0;
......
......@@ -145,7 +145,7 @@ void AudioOutputStreamFuchsia::OnMinLeadTimeChanged(int64_t min_lead_time) {
}
}
void AudioOutputStreamFuchsia::OnRendererError() {
void AudioOutputStreamFuchsia::OnRendererError(zx_status_t status) {
LOG(WARNING) << "AudioRenderer has failed.";
ReportError();
}
......
......@@ -45,7 +45,7 @@ class AudioOutputStreamFuchsia : public AudioOutputStream {
void OnMinLeadTimeChanged(int64_t min_lead_time);
// Error handler for |audio_out_|.
void OnRendererError();
void OnRendererError(zx_status_t status);
// Resets internal state and reports an error to |callback_|.
void ReportError();
......
......@@ -411,8 +411,10 @@ void FuchsiaVideoDecoder::Initialize(
->ConnectToService<fuchsia::mediacodec::CodecFactory>();
codec_factory->CreateDecoder(std::move(codec_params), codec_.NewRequest());
codec_.set_error_handler([this]() {
LOG(ERROR) << "The fuchsia.mediacodec.Codec channel was terminated.";
codec_.set_error_handler(
[this](zx_status_t status) {
ZX_LOG(ERROR, status)
<< "The fuchsia.mediacodec.Codec channel was terminated.";
OnError();
});
......
......@@ -10,6 +10,7 @@
#include <vector>
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/optional.h"
#include "base/run_loop.h"
#include "net/base/network_interfaces.h"
......@@ -46,8 +47,9 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
: netstack_(std::move(netstack)) {
DCHECK(netstack_);
netstack_.set_error_handler(
[]() { LOG(ERROR) << "Lost connection to netstack."; });
netstack_.set_error_handler([](zx_status_t status) {
ZX_LOG(ERROR, status) << "Lost connection to netstack.";
});
netstack_.events().OnInterfacesChanged =
[this](fidl::VectorPtr<fuchsia::netstack::NetInterface> interfaces) {
ProcessInterfaceList(base::OnceClosure(), std::move(interfaces));
......
......@@ -28,7 +28,7 @@ InputMethodKeyboardControllerFuchsia::InputMethodKeyboardControllerFuchsia(
DCHECK(ime_service_);
DCHECK(input_method_);
ime_service_.set_error_handler([this]() {
ime_service_.set_error_handler([this](zx_status_t status) {
LOG(ERROR) << "Lost connection to IME service.";
ime_.Unbind();
ime_client_binding_.Unbind();
......
......@@ -221,8 +221,8 @@ void ScenicWindow::OnPropertiesChanged(
callback();
}
void ScenicWindow::OnScenicError() {
LOG(ERROR) << "scenic::Session failed.";
void ScenicWindow::OnScenicError(zx_status_t status) {
LOG(ERROR) << "scenic::Session failed with code " << status << ".";
delegate_->OnClosed();
}
......@@ -273,8 +273,8 @@ void ScenicWindow::OnEvent(fuchsia::ui::input::InputEvent event,
callback(result);
}
void ScenicWindow::OnViewError() {
VLOG(1) << "viewsv1::View connection was closed.";
void ScenicWindow::OnViewError(zx_status_t status) {
VLOG(1) << "viewsv1::View connection was closed with code " << status << ".";
delegate_->OnClosed();
}
......
......@@ -80,7 +80,7 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
OnEventCallback callback) override;
// Callbacks for |scenic_session_|.
void OnScenicError();
void OnScenicError(zx_status_t status);
void OnScenicEvents(fidl::VectorPtr<fuchsia::ui::scenic::Event> events);
// InputEventDispatcher::Delegate interface.
......@@ -88,7 +88,7 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
// Error handler for |view_|. This error normally indicates the View was
// destroyed (e.g. dropping ViewOwner).
void OnViewError();
void OnViewError(zx_status_t status);
void UpdateSize();
......
......@@ -23,8 +23,10 @@ fuchsia::ui::viewsv1::ViewManager* ScenicWindowManager::GetViewManager() {
if (!view_manager_) {
view_manager_ = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::viewsv1::ViewManager>();
view_manager_.set_error_handler([]() {
LOG(ERROR) << "The ViewManager channel was unexpectedly terminated.";
view_manager_.set_error_handler([](zx_status_t status) {
LOG(ERROR)
<< "The ViewManager channel was unexpectedly terminated with status "
<< status << ".";
});
}
......@@ -35,7 +37,7 @@ fuchsia::ui::scenic::Scenic* ScenicWindowManager::GetScenic() {
if (!scenic_) {
scenic_ = base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::ui::scenic::Scenic>();
scenic_.set_error_handler([]() {
scenic_.set_error_handler([](zx_status_t status) {
LOG(ERROR) << "The Scenic channel was unexpectedly terminated.";
});
}
......
......@@ -49,7 +49,7 @@ WebComponent::WebComponent(
// to destroy this component on error.
if (controller_request.is_valid()) {
controller_binding_.Bind(std::move(controller_request));
controller_binding_.set_error_handler([this] {
controller_binding_.set_error_handler([this](zx_status_t status) {
// Signal graceful process termination.
DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED);
});
......
......@@ -37,7 +37,7 @@ chromium::web::ContextPtr WebContentRunner::CreateDefaultWebContext() {
chromium::web::ContextPtr web_context;
web_context_provider->Create(std::move(create_params),
web_context.NewRequest());
web_context.set_error_handler([]() {
web_context.set_error_handler([](zx_status_t status) {
// If the browser instance died, then exit everything and do not attempt
// to recover. appmgr will relaunch the runner when it is needed again.
LOG(ERROR) << "Connection to Context lost.";
......
......@@ -161,7 +161,8 @@ FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
binding_(this, std::move(frame_request)) {
web_contents_->SetDelegate(this);
Observe(web_contents_.get());
binding_.set_error_handler([this]() { context_->DestroyFrame(this); });
binding_.set_error_handler(
[this](zx_status_t status) { context_->DestroyFrame(this); });
}
FrameImpl::~FrameImpl() {
......@@ -317,9 +318,8 @@ void FrameImpl::SetNavigationEventObserver(
if (observer) {
navigation_observer_.Bind(std::move(observer));
navigation_observer_.set_error_handler([this]() {
SetNavigationEventObserver(nullptr);
});
navigation_observer_.set_error_handler(
[this](zx_status_t status) { SetNavigationEventObserver(nullptr); });
} else {
navigation_observer_.Unbind();
}
......
......@@ -145,7 +145,7 @@ IN_PROC_BROWSER_TEST_F(FrameImplTest, ContextDeletedBeforeFrame) {
EXPECT_TRUE(frame);
base::RunLoop run_loop;
frame.set_error_handler([&run_loop]() { run_loop.Quit(); });
frame.set_error_handler([&run_loop](zx_status_t status) { run_loop.Quit(); });
context().Unbind();
run_loop.Run();
EXPECT_FALSE(frame);
......
......@@ -51,7 +51,7 @@ void WebRunnerBrowserMainParts::PreMainMessageLoopRun() {
std::move(context_channel_)));
// Quit the browser main loop when the Context connection is dropped.
context_binding_->set_error_handler([this]() {
context_binding_->set_error_handler([this](zx_status_t status) {
DLOG(WARNING) << "Client connection to Context service dropped.";
context_service_.reset();
std::move(quit_closure_).Run();
......
......@@ -56,7 +56,8 @@ class HttpServiceTest : public ::testing::Test {
void TearDown() override {
// Disconnect the client and wait for the service to shut down.
base::RunLoop run_loop;
binding_.set_error_handler([&run_loop]() { run_loop.Quit(); });
binding_.set_error_handler(
[&run_loop](zx_status_t status) { run_loop.Quit(); });
http_service_interface_.Unbind();
run_loop.Run();
binding_.set_error_handler(nullptr);
......
......@@ -124,7 +124,7 @@ URLLoaderImpl::URLLoaderImpl(std::unique_ptr<net::URLRequestContext> context,
context_(std::move(context)),
buffer_(new net::GrowableIOBuffer()),
write_watch_(FROM_HERE) {
binding_.set_error_handler([this] { delete this; });
binding_.set_error_handler([this](zx_status_t status) { delete this; });
g_active_requests++;
}
......
......@@ -44,7 +44,7 @@ class FakeFrame : public chromium::web::Frame {
public:
explicit FakeFrame(fidl::InterfaceRequest<chromium::web::Frame> request)
: binding_(this, std::move(request)) {
binding_.set_error_handler([this]() { delete this; });
binding_.set_error_handler([this](zx_status_t status) { delete this; });
}
~FakeFrame() override = default;
......@@ -157,7 +157,8 @@ MULTIPROCESS_TEST_MAIN(SpawnContextServer) {
// Quit the process when the context is destroyed.
base::RunLoop run_loop;
context_binding.set_error_handler([&run_loop]() { run_loop.Quit(); });
context_binding.set_error_handler(
[&run_loop](zx_status_t status) { run_loop.Quit(); });
run_loop.Run();
return 0;
......@@ -184,13 +185,13 @@ class ContextProviderImplTest : public base::MultiProcessTest {
fidl::InterfacePtr<chromium::web::Context>* context) {
// Call a Context method and wait for it to invoke an observer call.
base::RunLoop run_loop;
context->set_error_handler([&run_loop]() {
context->set_error_handler([&run_loop](zx_status_t status) {
ADD_FAILURE();
run_loop.Quit();
});
chromium::web::FramePtr frame_ptr;
frame_ptr.set_error_handler([&run_loop]() {
frame_ptr.set_error_handler([&run_loop](zx_status_t status) {
ADD_FAILURE();
run_loop.Quit();
});
......@@ -225,7 +226,8 @@ class ContextProviderImplTest : public base::MultiProcessTest {
void CheckContextUnresponsive(
fidl::InterfacePtr<chromium::web::Context>* context) {
base::RunLoop run_loop;
context->set_error_handler([&run_loop]() { run_loop.Quit(); });
context->set_error_handler(
[&run_loop](zx_status_t status) { run_loop.Quit(); });
chromium::web::FramePtr frame;
(*context)->CreateFrame(frame.NewRequest());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment