0

mojo: Reset ReceiverSet's dispatch context after dispatching a message.

This should make it easier to catch code trying to access the dispatch
context outside of the context of dispatching a message.

I confirmed by manual testing that this does in fact make the (manual)
font access API web platform tests hit a DCHECK for its incorrect usage
of ReceiverSet::current_context.

Bug: 1228510, 1229481
Change-Id: Ibeb498a297de2f709bbffa561ea9458958fedfe9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3025524
Reviewed-by: Thanh Nguyen <thanhdng@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Auto-Submit: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#901880}
This commit is contained in:
Marijn Kruisselbrink
2021-07-15 08:44:19 +00:00
committed by Chromium LUCI CQ
parent d300d690a2
commit 2ba7477709
3 changed files with 13 additions and 2 deletions
chrome/browser/ash/power/auto_screen_brightness
mojo/public/cpp/bindings

@ -60,6 +60,8 @@ class LightSamplesObserverTest : public testing::Test {
}
void DisableIlluminanceChannel() {
// TODO(https://crbug.com/1229481): SetChannelsEnabled assumes it is only
// called via a mojo pipe, as such this call is not valid and will DCHECK.
sensor_device_->SetChannelsEnabled(
{0}, false,
base::BindOnce(&LightSamplesObserverTest::SetChannelsEnabledCallback,
@ -121,7 +123,9 @@ TEST_F(LightSamplesObserverTest, StartReadingTwiceError) {
EXPECT_EQ(fake_observer_.num_received_ambient_lights(), 0);
}
TEST_F(LightSamplesObserverTest, GetSamplesWithoutColorChannels) {
// TODO(https://crbug.com/1229481): This test hits a DCHECK in the
// DisableIlluminanceChannel call.
TEST_F(LightSamplesObserverTest, DISABLED_GetSamplesWithoutColorChannels) {
SetChannels(false);
mojo::Remote<chromeos::sensors::mojom::SensorDevice> light;

@ -29,7 +29,9 @@ class ReceiverSetState::Entry::DispatchFilter : public MessageFilter {
return true;
}
void DidDispatchOrReject(Message* message, bool accepted) override {}
void DidDispatchOrReject(Message* message, bool accepted) override {
entry_.DidDispatchOrReject();
}
Entry& entry_;
};
@ -50,6 +52,10 @@ void ReceiverSetState::Entry::WillDispatch() {
state_.SetDispatchContext(receiver_->GetContext(), id_);
}
void ReceiverSetState::Entry::DidDispatchOrReject() {
state_.SetDispatchContext(nullptr, 0);
}
void ReceiverSetState::Entry::OnDisconnect(uint32_t custom_reason_code,
const std::string& description) {
WillDispatch();

@ -80,6 +80,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ReceiverSetState {
class DispatchFilter;
void WillDispatch();
void DidDispatchOrReject();
void OnDisconnect(uint32_t custom_reason_code,
const std::string& description);