Commit 2ce4166d authored by sky's avatar sky Committed by Commit bot

Makes ScreenDimmer deal with the shell going away

Chrome may end up using ScreenDimmer in such a way that the ScreenDimmer is destroyed after the shell. This change makes ~ScreenDimmer deal with the shell having been destroyed so that it doesn't crash.

BUG=648723
TEST=covered by test
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2359633003
Cr-Commit-Position: refs/heads/master@{#419909}
parent 3ee68aaf
......@@ -32,7 +32,9 @@ ScreenDimmer::ScreenDimmer(Container container)
}
ScreenDimmer::~ScreenDimmer() {
WmShell::Get()->RemoveShellObserver(this);
// Usage in chrome results in ScreenDimmer outliving the shell.
if (WmShell::HasInstance())
WmShell::Get()->RemoveShellObserver(this);
}
void ScreenDimmer::SetDimming(bool should_dim) {
......
......@@ -120,5 +120,27 @@ TEST_F(ScreenDimmerTest, DimAtBottom) {
EXPECT_EQ(*dim_iter, *root_window->children().begin());
}
// See description above TEST_F for details.
class ScreenDimmerShellDestructionTest : public AshTestBase {
public:
ScreenDimmerShellDestructionTest() {}
~ScreenDimmerShellDestructionTest() override {}
void TearDown() override {
ScreenDimmer screen_dimmer(ScreenDimmer::Container::ROOT);
AshTestBase::TearDown();
// ScreenDimmer is destroyed *after* the shell.
}
private:
DISALLOW_COPY_AND_ASSIGN(ScreenDimmerShellDestructionTest);
};
// This test verifies ScreenDimmer can be destroyed after the shell. The
// interesting part of this test is in TearDown(), which creates a ScreenDimmer
// that is deleted after WmShell.
TEST_F(ScreenDimmerShellDestructionTest, DontCrashIfScreenDimmerOutlivesShell) {
}
} // namespace test
} // namespace ash
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