chromeos: Update browser window placement for out-of-process ash

WindowSizerAsh needs synchronous access to the target display for each
new browser window.

* Create ash::ShellState and move root_window_for_new_windows_ there
* Introduce mojom::ShellState interface in ash
* Create a ShellStateClient in chrome to cache the target display id
  for new windows

The interface is not implemented by ash::Shell because ash::Shell
is already massive (1500 lines). Also, shell.h is included in 900
places in the code base and I don't want to add mojo generated headers
to shell.h.

Windows still don't appear on the secondary display with
--enable-features=Mash, but chrome is getting the correct display
id and setting the window bounds properly. I think ash needs to be
fixed to support top-level bounds on the secondary display, but that
will need to be a follow-up CL.

Bug: 764009, 768908
Test: ash_unittests, unit_tests for WindowSizer
Change-Id: Ib77834f8ed5dc4e65f02ff83ab81acbf3331db61
Reviewed-on: https://chromium-review.googlesource.com/1067591
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Scott Violet <[email protected]>
Reviewed-by: Evan Stade <[email protected]>
Commit-Queue: James Cook <[email protected]>
Cr-Commit-Position: refs/heads/master@{#561950}
diff --git a/ash/shell.cc b/ash/shell.cc
index 76dfbe8..6a1e14e 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -84,6 +84,7 @@
 #include "ash/shell_observer.h"
 #include "ash/shell_port.h"
 #include "ash/shell_port_classic.h"
+#include "ash/shell_state.h"
 #include "ash/shutdown_controller.h"
 #include "ash/sticky_keys/sticky_keys_controller.h"
 #include "ash/system/bluetooth/bluetooth_notification_controller.h"
@@ -339,11 +340,7 @@
 
 // static
 aura::Window* Shell::GetRootWindowForNewWindows() {
-  CHECK(Shell::HasInstance());
-  Shell* shell = Shell::Get();
-  if (shell->scoped_root_window_for_new_windows_)
-    return shell->scoped_root_window_for_new_windows_;
-  return shell->root_window_for_new_windows_;
+  return Shell::Get()->shell_state_->GetRootWindowForNewWindows();
 }
 
 // static
@@ -697,6 +694,7 @@
           shell_delegate->GetShellConnector())),
       note_taking_controller_(std::make_unique<NoteTakingController>()),
       shell_delegate_(std::move(shell_delegate)),
+      shell_state_(std::make_unique<ShellState>()),
       shutdown_controller_(std::make_unique<ShutdownController>()),
       system_tray_controller_(std::make_unique<SystemTrayController>()),
       system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
@@ -1087,7 +1085,7 @@
   time_to_first_present_recorder_ =
       std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
 
-  root_window_for_new_windows_ = GetPrimaryRootWindow();
+  shell_state_->SetRootWindowForNewWindows(GetPrimaryRootWindow());
 
   resolution_notification_controller_ =
       std::make_unique<ResolutionNotificationController>();
@@ -1455,8 +1453,10 @@
     ::wm::ActivationChangeObserver::ActivationReason reason,
     aura::Window* gained_active,
     aura::Window* lost_active) {
-  if (gained_active)
-    root_window_for_new_windows_ = gained_active->GetRootWindow();
+  if (!gained_active)
+    return;
+
+  shell_state_->SetRootWindowForNewWindows(gained_active->GetRootWindow());
 }
 
 void Shell::OnFirstSessionStarted() {