Commit dd34c463 authored by sammc's avatar sammc Committed by Commit bot

Use a ThreadChecker in DeviceSensorHost instead of DCHECK_CURRENTLY_ON.

BrowserThreads forget their identity during shutdown, causing
nonsensical errors like
"Check failed: ::content::BrowserThread::CurrentlyOn(BrowserThread::IO).
Must be called on Chrome_IOThread; actually called on Chrome_IOThread."
if DCHECK_CURRENTLY_ON is used in something that is called from a
MessageLoop shutdown observer.

This CL fixes this problem in DeviceSensorHost by using a ThreadChecker
instead.

BUG=625988

Review-Url: https://codereview.chromium.org/2160913005
Cr-Commit-Position: refs/heads/master@{#406995}
parent 10e0d5f6
...@@ -226,14 +226,7 @@ class DeviceSensorBrowserTest : public ContentBrowserTest { ...@@ -226,14 +226,7 @@ class DeviceSensorBrowserTest : public ContentBrowserTest {
base::WaitableEvent io_loop_finished_event_; base::WaitableEvent io_loop_finished_event_;
}; };
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationTest) {
#if defined(ADDRESS_SANITIZER) && defined(OS_LINUX)
#define MAYBE_OrientationTest DISABLED_OrientationTest
#else
#define MAYBE_OrientationTest OrientationTest
#endif
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest,
MAYBE_OrientationTest) {
// The test page will register an event handler for orientation events, // The test page will register an event handler for orientation events,
// expects to get an event with fake values, then removes the event // expects to get an event with fake values, then removes the event
// handler and navigates to #pass. // handler and navigates to #pass.
...@@ -245,8 +238,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, ...@@ -245,8 +238,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest,
fetcher_->stopped_orientation_.Wait(); fetcher_->stopped_orientation_.Wait();
} }
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightTest) {
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_LightTest) {
// The test page will register an event handler for light events, // The test page will register an event handler for light events,
// expects to get an event with fake values, then removes the event // expects to get an event with fake values, then removes the event
// handler and navigates to #pass. // handler and navigates to #pass.
...@@ -259,8 +251,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_LightTest) { ...@@ -259,8 +251,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_LightTest) {
fetcher_->stopped_light_.Wait(); fetcher_->stopped_light_.Wait();
} }
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionTest) {
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionTest) {
// The test page will register an event handler for motion events, // The test page will register an event handler for motion events,
// expects to get an event with fake values, then removes the event // expects to get an event with fake values, then removes the event
// handler and navigates to #pass. // handler and navigates to #pass.
...@@ -272,9 +263,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionTest) { ...@@ -272,9 +263,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionTest) {
fetcher_->stopped_motion_.Wait(); fetcher_->stopped_motion_.Wait();
} }
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, LightOneOffInfintyTest) {
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest,
DISABLED_LightOneOffInfintyTest) {
// The test page registers an event handler for light events and expects // The test page registers an event handler for light events and expects
// to get an event with value equal to infinity, because no sensor data can // to get an event with value equal to infinity, because no sensor data can
// be provided. // be provided.
...@@ -289,8 +278,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, ...@@ -289,8 +278,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest,
fetcher_->stopped_light_.Wait(); fetcher_->stopped_light_.Wait();
} }
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, OrientationNullTest) {
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_OrientationNullTest) {
// The test page registers an event handler for orientation events and // The test page registers an event handler for orientation events and
// expects to get an event with null values, because no sensor data can be // expects to get an event with null values, because no sensor data can be
// provided. // provided.
...@@ -304,8 +292,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_OrientationNullTest) { ...@@ -304,8 +292,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_OrientationNullTest) {
fetcher_->stopped_orientation_.Wait(); fetcher_->stopped_orientation_.Wait();
} }
// Flaky test. See http://crbug.com/628527. IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, MotionNullTest) {
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionNullTest) {
// The test page registers an event handler for motion events and // The test page registers an event handler for motion events and
// expects to get an event with null values, because no sensor data can be // expects to get an event with null values, because no sensor data can be
// provided. // provided.
...@@ -318,7 +305,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionNullTest) { ...@@ -318,7 +305,7 @@ IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_MotionNullTest) {
fetcher_->stopped_motion_.Wait(); fetcher_->stopped_motion_.Wait();
} }
IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, DISABLED_NullTestWithAlert) { IN_PROC_BROWSER_TEST_F(DeviceSensorBrowserTest, NullTestWithAlert) {
// The test page registers an event handlers for motion/orientation events // The test page registers an event handlers for motion/orientation events
// and expects to get events with null values. The test raises a modal alert // and expects to get events with null values. The test raises a modal alert
// dialog with a delay to test that the one-off null-events still propagate // dialog with a delay to test that the one-off null-events still propagate
......
...@@ -18,11 +18,13 @@ void DeviceSensorHost<MojoInterface, consumer_type>::Create( ...@@ -18,11 +18,13 @@ void DeviceSensorHost<MojoInterface, consumer_type>::Create(
template <typename MojoInterface, ConsumerType consumer_type> template <typename MojoInterface, ConsumerType consumer_type>
DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost( DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost(
mojo::InterfaceRequest<MojoInterface> request) mojo::InterfaceRequest<MojoInterface> request)
: is_started_(false), binding_(this, std::move(request)) {} : is_started_(false), binding_(this, std::move(request)) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
}
template <typename MojoInterface, ConsumerType consumer_type> template <typename MojoInterface, ConsumerType consumer_type>
DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(thread_checker_.CalledOnValidThread());
if (is_started_) if (is_started_)
DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type); DeviceSensorService::GetInstance()->RemoveConsumer(consumer_type);
} }
...@@ -30,7 +32,7 @@ DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() { ...@@ -30,7 +32,7 @@ DeviceSensorHost<MojoInterface, consumer_type>::~DeviceSensorHost() {
template <typename MojoInterface, ConsumerType consumer_type> template <typename MojoInterface, ConsumerType consumer_type>
void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost::
StartPolling(const typename MojoInterface::StartPollingCallback& callback) { StartPolling(const typename MojoInterface::StartPollingCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(!is_started_); DCHECK(!is_started_);
if (is_started_) if (is_started_)
return; return;
...@@ -43,7 +45,7 @@ void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost:: ...@@ -43,7 +45,7 @@ void DeviceSensorHost<MojoInterface, consumer_type>::DeviceSensorHost::
template <typename MojoInterface, ConsumerType consumer_type> template <typename MojoInterface, ConsumerType consumer_type>
void DeviceSensorHost<MojoInterface, void DeviceSensorHost<MojoInterface,
consumer_type>::DeviceSensorHost::StopPolling() { consumer_type>::DeviceSensorHost::StopPolling() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(is_started_); DCHECK(is_started_);
if (!is_started_) if (!is_started_)
return; return;
......
...@@ -36,6 +36,8 @@ class DeviceSensorHost : public MojoInterface { ...@@ -36,6 +36,8 @@ class DeviceSensorHost : public MojoInterface {
mojo::StrongBinding<MojoInterface> binding_; mojo::StrongBinding<MojoInterface> binding_;
base::ThreadChecker thread_checker_;
DISALLOW_COPY_AND_ASSIGN(DeviceSensorHost); DISALLOW_COPY_AND_ASSIGN(DeviceSensorHost);
}; };
......
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