Commit 7fa507bf authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

ChromeShellDelegate: Cleanup: move initial focus code to ash

This change makes mru_window_tracker.cc a SessionObserver and
moves the initial focus logic there.

Bug: 665064
Change-Id: I5c125e0bbe62b9d2c8d809d519d3ccfeade76f8f
Reviewed-on: https://chromium-review.googlesource.com/1070854
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561886}
parent 90f3b266
......@@ -8,6 +8,7 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/wm/focus_rules.h"
#include "ash/wm/switchable_windows.h"
......@@ -102,11 +103,13 @@ MruWindowTracker::WindowList BuildWindowListInternal(
//////////////////////////////////////////////////////////////////////////////
// MruWindowTracker, public:
MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) {
MruWindowTracker::MruWindowTracker() {
Shell::Get()->activation_client()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this);
}
MruWindowTracker::~MruWindowTracker() {
Shell::Get()->session_controller()->RemoveObserver(this);
Shell::Get()->activation_client()->RemoveObserver(this);
for (auto* window : mru_windows_)
window->RemoveObserver(this);
......@@ -156,6 +159,20 @@ void MruWindowTracker::SetIgnoreActivations(bool ignore) {
SetActiveWindow(wm::GetActiveWindow());
}
// SessionObserver
// Restore focus after the user session has started. This is needed because some
// windows can be opened in the background while the login UI is still active
// since we currently restore browser windows before login UI is deleted.
void MruWindowTracker::OnUserSessionAdded(const AccountId& account_id) {
if (user_session_focus_restored_)
return;
user_session_focus_restored_ = true;
aura::Window::Windows mru_list = BuildMruWindowList();
if (!mru_list.empty())
mru_list.front()->Focus();
}
//////////////////////////////////////////////////////////////////////////////
// MruWindowTracker, private:
......
......@@ -9,6 +9,7 @@
#include <vector>
#include "ash/ash_export.h"
#include "ash/session/session_observer.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
#include "ui/wm/public/activation_change_observer.h"
......@@ -18,7 +19,8 @@ namespace ash {
// Maintains a most recently used list of windows. This is used for window
// cycling using Alt+Tab and overview mode.
class ASH_EXPORT MruWindowTracker : public ::wm::ActivationChangeObserver,
public aura::WindowObserver {
public aura::WindowObserver,
public SessionObserver {
public:
using WindowList = std::vector<aura::Window*>;
......@@ -45,6 +47,9 @@ class ASH_EXPORT MruWindowTracker : public ::wm::ActivationChangeObserver,
// windows to the front of the MRU window list.
void SetIgnoreActivations(bool ignore);
// SessionObserver
void OnUserSessionAdded(const AccountId& account_id) override;
private:
// Updates the mru_windows_ list to insert/move |active_window| at/to the
// front.
......@@ -62,7 +67,8 @@ class ASH_EXPORT MruWindowTracker : public ::wm::ActivationChangeObserver,
// through, sorted by most recently used.
std::list<aura::Window*> mru_windows_;
bool ignore_window_activations_;
bool ignore_window_activations_ = false;
bool user_session_focus_restored_ = false;
DISALLOW_COPY_AND_ASSIGN(MruWindowTracker);
};
......
......@@ -60,7 +60,11 @@ specific_include_rules = {
],
# https://crbug.com/665064
"chrome_shell_delegate.*": [
"+ash",
# https://crbug.com/756054
"+ash/accessibility/accessibility_delegate.h",
# https://crbug.com/557397
"+ash/screenshot_delegate.h",
"+ash/shell_delegate.h",
],
# https://crbug.com/672277
"session_util\.cc": [
......
......@@ -11,8 +11,7 @@
#include "ash/accessibility/accessibility_delegate.h"
#include "ash/public/cpp/accessibility_types.h"
#include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/screenshot_delegate.h"
#include "base/command_line.h"
#include "base/macros.h"
#include "build/build_config.h"
......@@ -69,16 +68,6 @@ namespace {
const char kKeyboardShortcutHelpPageUrl[] =
"https://support.google.com/chromebook/answer/183101";
void InitAfterFirstSessionStart() {
// Restore focus after the user session is started. It's needed because some
// windows can be opened in background while login UI is still active because
// we currently restore browser windows before login UI is deleted.
aura::Window::Windows mru_list =
ash::Shell::Get()->mru_window_tracker()->BuildMruWindowList();
if (!mru_list.empty())
mru_list.front()->Focus();
}
class AccessibilityDelegateImpl : public ash::AccessibilityDelegate {
public:
AccessibilityDelegateImpl() = default;
......@@ -247,12 +236,6 @@ void ChromeShellDelegate::Observe(int type,
}
break;
}
case chrome::NOTIFICATION_SESSION_STARTED:
// InitAfterFirstSessionStart() should only be called once upon system
// start.
if (user_manager::UserManager::Get()->GetLoggedInUsers().size() < 2)
InitAfterFirstSessionStart();
break;
default:
NOTREACHED() << "Unexpected notification " << type;
}
......@@ -261,6 +244,4 @@ void ChromeShellDelegate::Observe(int type,
void ChromeShellDelegate::PlatformInit() {
registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
}
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