Commit 31fed68a authored by jonross's avatar jonross Committed by Commit bot

ScreenOrientationController to start observing even without an internal display.

Ozone loads display configurations asynchronously. Due to this the internal
display is not always known when Maximize Mode is triggered.

Update ScreenOrientationController to become an observer even when there is no
internal display ready yet. That way, once it becomes ready, it is able to
process accelerometer events.

TEST=ScreenOrientationControllerTest.InternalDisplayNotAvailableAtStartup
BUG=chrome-os-partner:38796

Review URL: https://codereview.chromium.org/1080553002

Cr-Commit-Position: refs/heads/master@{#325298}
parent 31a66f3e
......@@ -196,10 +196,11 @@ void ScreenOrientationController::Unlock(content::WebContents* web_contents) {
void ScreenOrientationController::OnDisplayConfigurationChanged() {
if (ignore_display_configuration_updates_)
return;
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
if (!display_manager->HasInternalDisplay())
return;
gfx::Display::Rotation user_rotation =
Shell::GetInstance()
->display_manager()
->GetDisplayInfo(gfx::Display::InternalDisplayId())
display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
.rotation();
if (user_rotation != current_rotation_) {
// A user may change other display configuration settings. When the user
......@@ -212,11 +213,14 @@ void ScreenOrientationController::OnDisplayConfigurationChanged() {
void ScreenOrientationController::OnMaximizeModeStarted() {
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
if (!display_manager->HasInternalDisplay())
return;
current_rotation_ = user_rotation_ =
display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
.rotation();
// Do not exit early, as the internal display can be determined after Maximize
// Mode has started. (chrome-os-partner:38796)
// Always start observing.
if (display_manager->HasInternalDisplay()) {
current_rotation_ = user_rotation_ =
display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId())
.rotation();
}
if (!rotation_locked_)
LoadDisplayRotationProperties();
chromeos::AccelerometerReader::GetInstance()->AddObserver(this);
......@@ -224,8 +228,6 @@ void ScreenOrientationController::OnMaximizeModeStarted() {
}
void ScreenOrientationController::OnMaximizeModeEnded() {
if (!Shell::GetInstance()->display_manager()->HasInternalDisplay())
return;
chromeos::AccelerometerReader::GetInstance()->RemoveObserver(this);
Shell::GetInstance()->display_controller()->RemoveObserver(this);
if (current_rotation_ != user_rotation_)
......
......@@ -589,4 +589,23 @@ TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
}
// Tests that when MaximizeMode is triggered before the internal display is
// ready, that ScreenOrientationController still begins listening to events,
// which require an internal display to be acted upon.
TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) {
int64 internal_display_id = gfx::Display::InternalDisplayId();
gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
EnableMaximizeMode(true);
// Should not crash, even thought there is no internal display.
SetInternalDisplayRotation(gfx::Display::ROTATE_180);
EXPECT_FALSE(RotationLocked());
// With an internal display now available, functionality should resume.
gfx::Display::SetInternalDisplayId(internal_display_id);
SetInternalDisplayRotation(gfx::Display::ROTATE_90);
EXPECT_TRUE(RotationLocked());
}
} // 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