summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbartfab@google.com <bartfab@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 12:21:57 +0000
committerbartfab@google.com <bartfab@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 12:21:57 +0000
commit5b5495c70de838b40cc9e5990140fd9b2ad16987 (patch)
treeb5b02aa5e8392edd79a275ffc613c0241e396414
parentbac6ffd0f853d003e235a29d51f138ec4d70f034 (diff)
downloadchromium_src-5b5495c70de838b40cc9e5990140fd9b2ad16987.zip
chromium_src-5b5495c70de838b40cc9e5990140fd9b2ad16987.tar.gz
chromium_src-5b5495c70de838b40cc9e5990140fd9b2ad16987.tar.bz2
Add ash SessionStateDelegate
This CL refactors the ShellDelegate by adding a SessionStateDelegate to which methods dealing with the session state can be moved. This cleans up the huge ShellDelegate interface and paves the way for further Chrome OS multiprofile work which will need to add several new methods related to the session state. This CL is only the first step. Several other methods should also move to SessionStateDelegate but I do not want to overburden a single CL. BUG=None TEST=Manual and browser/unit tests TBR=sky (for c/b/idle_chromeos.cc and c/chrome_browser_ui.gypi) Review URL: https://codereview.chromium.org/14295008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194578 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/accelerators/accelerator_controller.cc11
-rw-r--r--ash/accelerators/nested_dispatcher_controller_unittest.cc6
-rw-r--r--ash/ash.gyp7
-rw-r--r--ash/desktop_background/desktop_background_view.cc5
-rw-r--r--ash/root_window_controller.cc3
-rw-r--r--ash/root_window_controller_unittest.cc14
-rw-r--r--ash/session_state_delegate.h41
-rw-r--r--ash/session_state_delegate_stub.cc45
-rw-r--r--ash/session_state_delegate_stub.h36
-rw-r--r--ash/shelf/shelf_layout_manager.cc9
-rw-r--r--ash/shelf/shelf_layout_manager_unittest.cc6
-rw-r--r--ash/shelf/shelf_widget.cc11
-rw-r--r--ash/shell.cc17
-rw-r--r--ash/shell.h13
-rw-r--r--ash/shell/app_list.cc4
-rw-r--r--ash/shell/lock_view.cc4
-rw-r--r--ash/shell/shell_delegate_impl.cc38
-rw-r--r--ash/shell/shell_delegate_impl.h9
-rw-r--r--ash/shell/window_type_launcher.cc4
-rw-r--r--ash/shell_delegate.h26
-rw-r--r--ash/shell_unittest.cc14
-rw-r--r--ash/system/date/tray_date.cc3
-rw-r--r--ash/system/tray/test_system_tray_delegate.cc9
-rw-r--r--ash/test/ash_test_base.cc10
-rw-r--r--ash/test/test_session_state_delegate.cc63
-rw-r--r--ash/test/test_session_state_delegate.h67
-rw-r--r--ash/test/test_shell_delegate.cc65
-rw-r--r--ash/test/test_shell_delegate.h38
-rw-r--r--ash/wm/event_client_impl.cc4
-rw-r--r--ash/wm/gestures/shelf_gesture_handler.cc6
-rw-r--r--ash/wm/power_button_controller.cc23
-rw-r--r--ash/wm/power_button_controller_unittest.cc19
-rw-r--r--ash/wm/session_state_controller_impl2_unittest.cc11
-rw-r--r--ash/wm/stacking_controller.cc7
-rw-r--r--ash/wm/system_modal_container_layout_manager.cc9
-rw-r--r--ash/wm/system_modal_container_layout_manager_unittest.cc8
-rw-r--r--ash/wm/window_cycle_controller.cc5
-rw-r--r--ash/wm/window_cycle_controller_unittest.cc5
-rw-r--r--ash/wm/workspace/workspace_cycler.cc3
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc3
-rw-r--r--chrome/browser/chromeos/dbus/printer_service_provider.cc7
-rw-r--r--chrome/browser/idle_chromeos.cc3
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate.cc11
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate.h8
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc48
-rw-r--r--chrome/browser/ui/ash/chrome_shell_delegate_views.cc24
-rw-r--r--chrome/browser/ui/ash/session_state_delegate.h29
-rw-r--r--chrome/browser/ui/ash/session_state_delegate_chromeos.cc49
-rw-r--r--chrome/browser/ui/ash/session_state_delegate_views.cc33
-rw-r--r--chrome/chrome_browser_ui.gypi4
50 files changed, 553 insertions, 344 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 9face4f..a98c4b36 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -26,6 +26,7 @@
#include "ash/root_window_controller.h"
#include "ash/rotator/screen_rotation.h"
#include "ash/screenshot_delegate.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
@@ -101,7 +102,7 @@ void HandleCycleWindowLinear(CycleDirection direction) {
#if defined(OS_CHROMEOS)
bool HandleLock() {
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
return true;
}
@@ -427,16 +428,12 @@ bool AcceleratorController::IsReservedAccelerator(
bool AcceleratorController::PerformAction(int action,
const ui::Accelerator& accelerator) {
ash::Shell* shell = ash::Shell::GetInstance();
- bool at_login_screen = false;
-#if defined(OS_CHROMEOS)
- at_login_screen = !shell->delegate()->IsSessionStarted();
-#endif
- if (at_login_screen &&
+ if (!shell->session_state_delegate()->IsActiveUserSessionStarted() &&
actions_allowed_at_login_screen_.find(action) ==
actions_allowed_at_login_screen_.end()) {
return false;
}
- if (shell->IsScreenLocked() &&
+ if (shell->session_state_delegate()->IsScreenLocked() &&
actions_allowed_at_lock_screen_.find(action) ==
actions_allowed_at_lock_screen_.end()) {
return false;
diff --git a/ash/accelerators/nested_dispatcher_controller_unittest.cc b/ash/accelerators/nested_dispatcher_controller_unittest.cc
index 3cf1721..ecc7972 100644
--- a/ash/accelerators/nested_dispatcher_controller_unittest.cc
+++ b/ash/accelerators/nested_dispatcher_controller_unittest.cc
@@ -3,8 +3,8 @@
// found in the LICENSE file.
#include "ash/accelerators/accelerator_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "base/bind.h"
@@ -109,7 +109,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) {
MockDispatcher inner_dispatcher;
scoped_ptr<aura::Window> associated_window(CreateTestWindowInShellWithId(0));
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
DispatchKeyReleaseA();
aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(
@@ -117,7 +117,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) {
associated_window.get(),
true /* nestable_tasks_allowed */);
EXPECT_EQ(0, inner_dispatcher.num_key_events_dispatched());
- Shell::GetInstance()->delegate()->UnlockScreen();
+ Shell::GetInstance()->session_state_delegate()->UnlockScreen();
}
// Aura window above lock screen in z order.
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 1ea89b8..46debce 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -163,6 +163,7 @@
'screensaver/screensaver_view.cc',
'screensaver/screensaver_view.h',
'screenshot_delegate.h',
+ 'session_state_delegate.h',
'shelf/background_animator.cc',
'shelf/background_animator.h',
'shelf/shelf_layout_manager.cc',
@@ -550,6 +551,8 @@
'test/test_activation_delegate.h',
'test/test_launcher_delegate.cc',
'test/test_launcher_delegate.h',
+ 'test/test_session_state_delegate.cc',
+ 'test/test_session_state_delegate.cc',
'test/test_shell_delegate.cc',
'test/test_shell_delegate.h',
'test/test_suite.cc',
@@ -637,6 +640,8 @@
'root_window_controller_unittest.cc',
'screen_ash_unittest.cc',
'screensaver/screensaver_view_unittest.cc',
+ 'session_state_delegate_stub.cc',
+ 'session_state_delegate_stub.h',
'shelf/shelf_layout_manager_unittest.cc',
'shelf/shelf_widget_unittest.cc',
'shell_unittest.cc',
@@ -763,6 +768,8 @@
'ash_resources',
],
'sources': [
+ 'session_state_delegate_stub.cc',
+ 'session_state_delegate_stub.h',
'shell/app_list.cc',
'shell/bubble.cc',
'shell/content_client/shell_browser_main_parts.cc',
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc
index 35e7d0d..6d6e487 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -11,8 +11,8 @@
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/desktop_background/user_wallpaper_delegate.h"
#include "ash/root_window_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_animations.h"
@@ -201,8 +201,7 @@ views::Widget* CreateDesktopBackground(aura::RootWindow* root_window,
// 4. From an empty background, guest user logged in.
if (wallpaper_delegate->ShouldShowInitialAnimation() ||
root_window->GetProperty(kAnimatingDesktopController) ||
- Shell::GetInstance()->delegate()->IsGuestSession() ||
- Shell::GetInstance()->delegate()->IsUserLoggedIn()) {
+ Shell::GetInstance()->session_state_delegate()->HasActiveUser()) {
views::corewm::SetWindowVisibilityAnimationTransition(
desktop_widget->GetNativeView(), views::corewm::ANIMATE_SHOW);
} else {
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index a975fa8..6cefecc 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -12,6 +12,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
#include "ash/focus_cycler.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shelf/shelf_widget.h"
@@ -290,7 +291,7 @@ void RootWindowController::InitForPrimaryDisplay() {
new ToplevelWindowEventHandler(panel_container));
panel_container->SetLayoutManager(panel_layout_manager_);
}
- if (Shell::GetInstance()->delegate()->IsUserLoggedIn())
+ if (Shell::GetInstance()->session_state_delegate()->HasActiveUser())
shelf_->CreateLauncher();
InitKeyboard();
diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc
index 55f0763..c5bd68d 100644
--- a/ash/root_window_controller_unittest.cc
+++ b/ash/root_window_controller_unittest.cc
@@ -5,9 +5,9 @@
#include "ash/root_window_controller.h"
#include "ash/display/display_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/ash_test_base.h"
@@ -301,7 +301,7 @@ TEST_F(RootWindowControllerTest, ModalContainer) {
controller->GetSystemModalLayoutManager(
session_modal_widget->GetNativeView()));
- shell->delegate()->LockScreen();
+ shell->session_state_delegate()->LockScreen();
EXPECT_EQ(user::LOGGED_IN_LOCKED,
shell->system_tray_delegate()->GetUserLoginStatus());
EXPECT_EQ(Shell::GetContainer(controller->root_window(),
@@ -322,7 +322,7 @@ TEST_F(RootWindowControllerTest, ModalContainer) {
controller->GetSystemModalLayoutManager(
session_modal_widget->GetNativeView()));
- shell->delegate()->UnlockScreen();
+ shell->session_state_delegate()->UnlockScreen();
}
TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
@@ -333,8 +333,8 @@ TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
SetUserLoggedIn(false);
EXPECT_EQ(user::LOGGED_IN_NONE,
shell->system_tray_delegate()->GetUserLoginStatus());
- EXPECT_FALSE(shell->delegate()->IsUserLoggedIn());
- EXPECT_FALSE(shell->delegate()->IsSessionStarted());
+ EXPECT_FALSE(shell->session_state_delegate()->HasActiveUser());
+ EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
internal::RootWindowController* controller =
shell->GetPrimaryRootWindowController();
@@ -358,8 +358,8 @@ TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
SetSessionStarted(true);
EXPECT_EQ(user::LOGGED_IN_USER,
shell->system_tray_delegate()->GetUserLoginStatus());
- EXPECT_TRUE(shell->delegate()->IsUserLoggedIn());
- EXPECT_TRUE(shell->delegate()->IsSessionStarted());
+ EXPECT_TRUE(shell->session_state_delegate()->HasActiveUser());
+ EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
EXPECT_EQ(Shell::GetContainer(controller->root_window(),
internal::kShellWindowId_SystemModalContainer)->layout_manager(),
controller->GetSystemModalLayoutManager(NULL));
diff --git a/ash/session_state_delegate.h b/ash/session_state_delegate.h
new file mode 100644
index 0000000..f5ee359
--- /dev/null
+++ b/ash/session_state_delegate.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SESSION_STATE_DELEGATE_H_
+#define ASH_SESSION_STATE_DELEGATE_H_
+
+#include "ash/ash_export.h"
+
+namespace ash {
+
+// Delegate for checking and modifying the session state.
+class ASH_EXPORT SessionStateDelegate {
+ public:
+ virtual ~SessionStateDelegate() {};
+
+ // Returns |true| if a session is in progress and there is an active user.
+ virtual bool HasActiveUser() const = 0;
+
+ // Returns |true| if the session has been fully started for the active user.
+ // When a user becomes active, the profile and browser UI are not immediately
+ // available. Only once this method starts returning |true| is the browser
+ // startup complete and both profile and UI are fully available.
+ virtual bool IsActiveUserSessionStarted() const = 0;
+
+ // Returns true if the screen can be locked.
+ virtual bool CanLockScreen() const = 0;
+
+ // Returns true if the screen is currently locked.
+ virtual bool IsScreenLocked() const = 0;
+
+ // Locks the screen. The locking happens asynchronously.
+ virtual void LockScreen() = 0;
+
+ // Unlocks the screen.
+ virtual void UnlockScreen() = 0;
+};
+
+} // namespace ash
+
+#endif // ASH_SESSION_STATE_DELEGATE_H_
diff --git a/ash/session_state_delegate_stub.cc b/ash/session_state_delegate_stub.cc
new file mode 100644
index 0000000..b913b5f
--- /dev/null
+++ b/ash/session_state_delegate_stub.cc
@@ -0,0 +1,45 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/session_state_delegate_stub.h"
+
+#include "ash/shell.h"
+#include "ash/shell/example_factory.h"
+
+namespace ash {
+
+SessionStateDelegateStub::SessionStateDelegateStub() : screen_locked_(false) {
+}
+
+SessionStateDelegateStub::~SessionStateDelegateStub() {
+}
+
+bool SessionStateDelegateStub::HasActiveUser() const {
+ return true;
+}
+
+bool SessionStateDelegateStub::IsActiveUserSessionStarted() const {
+ return true;
+}
+
+bool SessionStateDelegateStub::CanLockScreen() const {
+ return true;
+}
+
+bool SessionStateDelegateStub::IsScreenLocked() const {
+ return screen_locked_;
+}
+
+void SessionStateDelegateStub::LockScreen() {
+ shell::CreateLockScreen();
+ screen_locked_ = true;
+ Shell::GetInstance()->UpdateShelfVisibility();
+}
+
+void SessionStateDelegateStub::UnlockScreen() {
+ screen_locked_ = false;
+ Shell::GetInstance()->UpdateShelfVisibility();
+}
+
+} // namespace ash
diff --git a/ash/session_state_delegate_stub.h b/ash/session_state_delegate_stub.h
new file mode 100644
index 0000000..db9b711
--- /dev/null
+++ b/ash/session_state_delegate_stub.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SESSION_STATE_DELEGATE_STUB_H_
+#define ASH_SESSION_STATE_DELEGATE_STUB_H_
+
+#include "ash/session_state_delegate.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+
+// Stub implementation of SessionStateDelegate for testing.
+class SessionStateDelegateStub : public SessionStateDelegate {
+ public:
+ SessionStateDelegateStub();
+ virtual ~SessionStateDelegateStub();
+
+ // SessionStateDelegate:
+ virtual bool HasActiveUser() const OVERRIDE;
+ virtual bool IsActiveUserSessionStarted() const OVERRIDE;
+ virtual bool CanLockScreen() const OVERRIDE;
+ virtual bool IsScreenLocked() const OVERRIDE;
+ virtual void LockScreen() OVERRIDE;
+ virtual void UnlockScreen() OVERRIDE;
+
+ private:
+ bool screen_locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateStub);
+};
+
+} // namespace ash
+
+#endif // ASH_SESSION_STATE_DELEGATE_STUB_H_
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index 6e9e3c7..3f168e2 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -12,9 +12,9 @@
#include "ash/launcher/launcher_types.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/property_util.h"
@@ -272,8 +272,7 @@ ShelfLayoutManager::CalculateShelfVisibilityWhileDragging() {
}
void ShelfLayoutManager::UpdateVisibilityState() {
- ShellDelegate* delegate = Shell::GetInstance()->delegate();
- if (delegate && delegate->IsScreenLocked()) {
+ if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
SetState(SHELF_VISIBLE);
} else if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) {
// TODO(zelidrag): Verify shelf drag animation still shows on the device
@@ -514,11 +513,11 @@ ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {}
ShelfLayoutManager::TargetBounds::~TargetBounds() {}
void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
- ShellDelegate* delegate = Shell::GetInstance()->delegate();
State state;
state.visibility_state = visibility_state;
state.auto_hide_state = CalculateAutoHideState(visibility_state);
- state.is_screen_locked = delegate && delegate->IsScreenLocked();
+ state.is_screen_locked =
+ Shell::GetInstance()->session_state_delegate()->IsScreenLocked();
// It's possible for SetState() when a window becomes maximized but the state
// won't have changed value. Do the dimming check before the early exit.
diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc
index 30c9220..faf1edb 100644
--- a/ash/shelf/shelf_layout_manager_unittest.cc
+++ b/ash/shelf/shelf_layout_manager_unittest.cc
@@ -13,9 +13,9 @@
#include "ash/launcher/launcher_view.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray.h"
@@ -497,12 +497,12 @@ TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
lock_widget->Show();
// Lock the screen.
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
shelf->UpdateVisibilityState();
// Showing a widget in the lock screen should force the shelf to be visibile.
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
- Shell::GetInstance()->delegate()->UnlockScreen();
+ Shell::GetInstance()->session_state_delegate()->UnlockScreen();
shelf->UpdateVisibilityState();
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
}
diff --git a/ash/shelf/shelf_widget.cc b/ash/shelf/shelf_widget.cc
index 7550622..1e2da78 100644
--- a/ash/shelf/shelf_widget.cc
+++ b/ash/shelf/shelf_widget.cc
@@ -10,10 +10,10 @@
#include "ash/launcher/launcher_navigator.h"
#include "ash/launcher/launcher_view.h"
#include "ash/root_window_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/property_util.h"
#include "ash/wm/status_area_layout_manager.h"
@@ -440,8 +440,10 @@ ShelfWidget::ShelfWidget(
status_area_widget_ = new internal::StatusAreaWidget(status_container);
status_area_widget_->CreateTrayViews();
- if (Shell::GetInstance()->delegate()->IsSessionStarted())
+ if (Shell::GetInstance()->session_state_delegate()->
+ IsActiveUserSessionStarted()) {
status_area_widget_->Show();
+ }
Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_);
shelf_layout_manager_ = new internal::ShelfLayoutManager(this);
@@ -498,9 +500,8 @@ void ShelfWidget::CreateLauncher() {
internal::RootWindowController::ForWindow(window_container_)->
OnLauncherCreated();
- ShellDelegate* delegate = shell->delegate();
- if (delegate)
- launcher_->SetVisible(delegate->IsSessionStarted());
+ launcher_->SetVisible(
+ shell->session_state_delegate()->IsActiveUserSessionStarted());
Show();
}
diff --git a/ash/shell.cc b/ash/shell.cc
index 7b809cb..9356cfc 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -28,6 +28,7 @@
#include "ash/magnifier/partial_magnification_controller.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell_delegate.h"
@@ -559,6 +560,8 @@ void Shell::Init() {
// StatusAreaWidget uses Shell's CapsLockDelegate.
caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
+ session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
+
if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) {
resize_shadow_controller_.reset(new internal::ResizeShadowController());
shadow_controller_.reset(
@@ -602,11 +605,11 @@ void Shell::Init() {
}
void Shell::ShowContextMenu(const gfx::Point& location_in_screen) {
- // No context menus if user have not logged in.
- if (!delegate_->IsUserLoggedIn())
+ // No context menus if there is no session with an active user.
+ if (!session_state_delegate_->HasActiveUser())
return;
// No context menus when screen is locked.
- if (IsScreenLocked())
+ if (session_state_delegate_->IsScreenLocked())
return;
aura::RootWindow* root =
@@ -640,14 +643,6 @@ aura::Window* Shell::GetAppListWindow() {
return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
}
-bool Shell::CanLockScreen() {
- return delegate_->CanLockScreen();
-}
-
-bool Shell::IsScreenLocked() const {
- return delegate_->IsScreenLocked();
-}
-
bool Shell::IsSystemModalWindowOpen() const {
if (simulate_modal_window_open_for_testing_)
return true;
diff --git a/ash/shell.h b/ash/shell.h
index e644d2a..e8089c1 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -82,6 +82,7 @@ class PowerButtonController;
class RootWindowHostFactory;
class ScreenAsh;
class SessionStateController;
+class SessionStateDelegate;
class ShellDelegate;
class ShellObserver;
class SystemTray;
@@ -217,13 +218,6 @@ class ASH_EXPORT Shell
// Returns app list window or NULL if it is not visible.
aura::Window* GetAppListWindow();
- // Returns true if a user is logged in whose session can be locked (i.e. the
- // user has a password with which to unlock the session).
- bool CanLockScreen();
-
- // Returns true if the screen is locked.
- bool IsScreenLocked() const;
-
// Returns true if a system-modal dialog window is currently open.
bool IsSystemModalWindowOpen() const;
@@ -334,6 +328,10 @@ class ASH_EXPORT Shell
return caps_lock_delegate_.get();
}
+ SessionStateDelegate* session_state_delegate() {
+ return session_state_delegate_.get();
+ }
+
HighContrastController* high_contrast_controller() {
return high_contrast_controller_.get();
}
@@ -503,6 +501,7 @@ class ASH_EXPORT Shell
scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
+ scoped_ptr<SessionStateDelegate> session_state_delegate_;
scoped_ptr<LauncherDelegate> launcher_delegate_;
scoped_ptr<LauncherModel> launcher_model_;
diff --git a/ash/shell/app_list.cc b/ash/shell/app_list.cc
index d005f2d..9afee4f 100644
--- a/ash/shell/app_list.cc
+++ b/ash/shell/app_list.cc
@@ -4,10 +4,10 @@
#include <string>
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/toplevel_window.h"
-#include "ash/shell_delegate.h"
#include "base/basictypes.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/string_search.h"
@@ -109,7 +109,7 @@ class WindowTypeLauncherItem : public app_list::AppListItemModel {
break;
}
case LOCK_SCREEN: {
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
break;
}
case WIDGETS_WINDOW: {
diff --git a/ash/shell/lock_view.cc b/ash/shell/lock_view.cc
index d60eba2b..235cb81 100644
--- a/ash/shell/lock_view.cc
+++ b/ash/shell/lock_view.cc
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/shell/example_factory.h"
#include "base/utf_string_conversions.h"
@@ -64,7 +64,7 @@ class LockView : public views::WidgetDelegateView,
// Overridden from views::WidgetDelegateView:
virtual void WindowClosing() OVERRIDE {
- Shell::GetInstance()->delegate()->UnlockScreen();
+ Shell::GetInstance()->session_state_delegate()->UnlockScreen();
}
// Overridden from views::ButtonListener:
diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc
index bb29637..69dec53c 100644
--- a/ash/shell/shell_delegate_impl.cc
+++ b/ash/shell/shell_delegate_impl.cc
@@ -8,6 +8,8 @@
#include "ash/caps_lock_delegate_stub.h"
#include "ash/host/root_window_host_factory.h"
+#include "ash/session_state_delegate.h"
+#include "ash/session_state_delegate_stub.h"
#include "ash/shell/context_menu.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/launcher_delegate_impl.h"
@@ -23,7 +25,6 @@ namespace shell {
ShellDelegateImpl::ShellDelegateImpl()
: watcher_(NULL),
launcher_delegate_(NULL),
- locked_(false),
spoken_feedback_enabled_(false),
high_contrast_enabled_(false),
screen_magnifier_enabled_(false),
@@ -39,18 +40,6 @@ void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
launcher_delegate_->set_watcher(watcher);
}
-bool ShellDelegateImpl::IsUserLoggedIn() const {
- return true;
-}
-
-bool ShellDelegateImpl::IsSessionStarted() const {
- return true;
-}
-
-bool ShellDelegateImpl::IsGuestSession() const {
- return false;
-}
-
bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
return false;
}
@@ -63,25 +52,6 @@ bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
return false;
}
-bool ShellDelegateImpl::CanLockScreen() const {
- return true;
-}
-
-void ShellDelegateImpl::LockScreen() {
- ash::shell::CreateLockScreen();
- locked_ = true;
- ash::Shell::GetInstance()->UpdateShelfVisibility();
-}
-
-void ShellDelegateImpl::UnlockScreen() {
- locked_ = false;
- ash::Shell::GetInstance()->UpdateShelfVisibility();
-}
-
-bool ShellDelegateImpl::IsScreenLocked() const {
- return locked_;
-}
-
void ShellDelegateImpl::PreInit() {
}
@@ -198,6 +168,10 @@ ash::CapsLockDelegate* ShellDelegateImpl::CreateCapsLockDelegate() {
return new CapsLockDelegateStub;
}
+ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
+ return new SessionStateDelegateStub;
+}
+
aura::client::UserActionClient* ShellDelegateImpl::CreateUserActionClient() {
return NULL;
}
diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h
index b162d7a..81d5228 100644
--- a/ash/shell/shell_delegate_impl.h
+++ b/ash/shell/shell_delegate_impl.h
@@ -27,16 +27,9 @@ class ShellDelegateImpl : public ash::ShellDelegate {
void SetWatcher(WindowWatcher* watcher);
- virtual bool IsUserLoggedIn() const OVERRIDE;
- virtual bool IsSessionStarted() const OVERRIDE;
- virtual bool IsGuestSession() const OVERRIDE;
virtual bool IsFirstRunAfterBoot() const OVERRIDE;
virtual bool IsMultiProfilesEnabled() const OVERRIDE;
virtual bool IsRunningInForcedAppMode() const OVERRIDE;
- virtual bool CanLockScreen() const OVERRIDE;
- virtual void LockScreen() OVERRIDE;
- virtual void UnlockScreen() OVERRIDE;
- virtual bool IsScreenLocked() const OVERRIDE;
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
@@ -69,6 +62,7 @@ class ShellDelegateImpl : public ash::ShellDelegate {
virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate() OVERRIDE;
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual ash::CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
+ virtual ash::SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
@@ -91,7 +85,6 @@ class ShellDelegateImpl : public ash::ShellDelegate {
LauncherDelegateImpl* launcher_delegate_;
- bool locked_;
bool spoken_feedback_enabled_;
bool high_contrast_enabled_;
bool screen_magnifier_enabled_;
diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc
index c764a41..caeb673 100644
--- a/ash/shell/window_type_launcher.cc
+++ b/ash/shell/window_type_launcher.cc
@@ -6,12 +6,12 @@
#include "ash/root_window_controller.h"
#include "ash/screensaver/screensaver_view.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/panel_window.h"
#include "ash/shell/toplevel_window.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/web_notification/web_notification_tray.h"
@@ -336,7 +336,7 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
} else if (sender == bubble_button_) {
CreatePointyBubble(sender);
} else if (sender == lock_button_) {
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
} else if (sender == widgets_button_) {
CreateWidgetsWindow();
} else if (sender == system_modal_button_) {
diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h
index 99aeb6e..0ff5fe6 100644
--- a/ash/shell_delegate.h
+++ b/ash/shell_delegate.h
@@ -45,6 +45,7 @@ class LauncherDelegate;
class LauncherModel;
struct LauncherItem;
class RootWindowHostFactory;
+class SessionStateDelegate;
class SystemTrayDelegate;
class UserWallpaperDelegate;
@@ -98,15 +99,6 @@ class ASH_EXPORT ShellDelegate {
// The Shell owns the delegate.
virtual ~ShellDelegate() {}
- // Returns true if user has logged in.
- virtual bool IsUserLoggedIn() const = 0;
-
- // Returns true if we're logged in and browser has been started
- virtual bool IsSessionStarted() const = 0;
-
- // Returns true if we're logged in as guest.
- virtual bool IsGuestSession() const = 0;
-
// Returns true if this is the first time that the shell has been run after
// the system has booted. false is returned after the shell has been
// restarted, typically due to logging in as a guest or logging out.
@@ -118,19 +110,6 @@ class ASH_EXPORT ShellDelegate {
// Returns true if we're running in forced app mode.
virtual bool IsRunningInForcedAppMode() const = 0;
- // Returns true if a user is logged in whose session can be locked (i.e. the
- // user has a password with which to unlock the session).
- virtual bool CanLockScreen() const = 0;
-
- // Invoked when a user locks the screen.
- virtual void LockScreen() = 0;
-
- // Unlock the screen. Currently used only for tests.
- virtual void UnlockScreen() = 0;
-
- // Returns true if the screen is currently locked.
- virtual bool IsScreenLocked() const = 0;
-
// Called before processing |Shell::Init()| so that the delegate
// can perform tasks necessary before the shell is initialized.
virtual void PreInit() = 0;
@@ -226,6 +205,9 @@ class ASH_EXPORT ShellDelegate {
// Creates a caps lock delegate. Shell takes ownership of the delegate.
virtual CapsLockDelegate* CreateCapsLockDelegate() = 0;
+ // Creates a session state delegate. Shell takes ownership of the delegate.
+ virtual SessionStateDelegate* CreateSessionStateDelegate() = 0;
+
// Creates a user action client. Shell takes ownership of the object.
virtual aura::client::UserActionClient* CreateUserActionClient() = 0;
diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc
index 039354f..70ca5c2 100644
--- a/ash/shell_unittest.cc
+++ b/ash/shell_unittest.cc
@@ -11,9 +11,9 @@
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/launcher/launcher.h"
#include "ash/root_window_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/root_window_layout_manager.h"
@@ -219,7 +219,7 @@ TEST_F(ShellTest, CreateLockScreenModalWindow) {
EXPECT_TRUE(GetDefaultContainer()->Contains(
widget->GetNativeWindow()->parent()));
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
// Create a LockScreen window.
views::Widget* lock_widget = CreateTestWindow(widget_params);
ash::Shell::GetContainer(
@@ -264,10 +264,12 @@ TEST_F(ShellTest, CreateLockScreenModalWindow) {
}
TEST_F(ShellTest, IsScreenLocked) {
- ash::Shell::GetInstance()->delegate()->LockScreen();
- EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked());
- ash::Shell::GetInstance()->delegate()->UnlockScreen();
- EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked());
+ SessionStateDelegate* delegate =
+ Shell::GetInstance()->session_state_delegate();
+ delegate->LockScreen();
+ EXPECT_TRUE(delegate->IsScreenLocked());
+ delegate->UnlockScreen();
+ EXPECT_FALSE(delegate->IsScreenLocked());
}
// Fails on Mac, see http://crbug.com/115662
diff --git a/ash/system/date/tray_date.cc b/ash/system/date/tray_date.cc
index fb1fffb..34edabb 100644
--- a/ash/system/date/tray_date.cc
+++ b/ash/system/date/tray_date.cc
@@ -4,6 +4,7 @@
#include "ash/system/date/tray_date.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/date/date_view.h"
@@ -89,7 +90,7 @@ class DateDefaultView : public views::View,
view->AddButton(shutdown_);
}
- if (ash::Shell::GetInstance()->CanLockScreen()) {
+ if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
lock_ = new ash::internal::TrayPopupHeaderButton(this,
IDR_AURA_UBER_TRAY_LOCKSCREEN,
IDR_AURA_UBER_TRAY_LOCKSCREEN,
diff --git a/ash/system/tray/test_system_tray_delegate.cc b/ash/system/tray/test_system_tray_delegate.cc
index 30e63e4..b02f208 100644
--- a/ash/system/tray/test_system_tray_delegate.cc
+++ b/ash/system/tray/test_system_tray_delegate.cc
@@ -6,8 +6,8 @@
#include <string>
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/volume_control_delegate.h"
#include "base/utf_string_conversions.h"
#include "base/message_loop.h"
@@ -90,9 +90,12 @@ const gfx::ImageSkia& TestSystemTrayDelegate::GetUserImage() const {
user::LoginStatus TestSystemTrayDelegate::GetUserLoginStatus() const {
// At new user image screen manager->IsUserLoggedIn() would return true
// but there's no browser session available yet so use SessionStarted().
- if (!Shell::GetInstance()->delegate()->IsSessionStarted())
+ SessionStateDelegate* delegate =
+ Shell::GetInstance()->session_state_delegate();
+
+ if (!delegate->IsActiveUserSessionStarted())
return ash::user::LOGGED_IN_NONE;
- if (Shell::GetInstance()->IsScreenLocked())
+ if (delegate->IsScreenLocked())
return user::LOGGED_IN_LOCKED;
// TODO(nkostylev): Support LOGGED_IN_OWNER, LOGGED_IN_GUEST, LOGGED_IN_KIOSK,
// LOGGED_IN_PUBLIC.
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 3346c3c..24b004f 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -14,6 +14,7 @@
#include "ash/shell.h"
#include "ash/test/display_manager_test_api.h"
#include "ash/test/shell_test_api.h"
+#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/coordinate_conversion.h"
#include "base/command_line.h"
@@ -275,15 +276,18 @@ void AshTestBase::RunAllPendingInMessageLoop() {
}
void AshTestBase::SetSessionStarted(bool session_started) {
- test_shell_delegate_->SetSessionStarted(session_started);
+ test_shell_delegate_->test_session_state_delegate()->
+ SetActiveUserSessionStarted(session_started);
}
void AshTestBase::SetUserLoggedIn(bool user_logged_in) {
- test_shell_delegate_->SetUserLoggedIn(user_logged_in);
+ test_shell_delegate_->test_session_state_delegate()->
+ SetHasActiveUser(user_logged_in);
}
void AshTestBase::SetCanLockScreen(bool can_lock_screen) {
- test_shell_delegate_->SetCanLockScreen(can_lock_screen);
+ test_shell_delegate_->test_session_state_delegate()->
+ SetCanLockScreen(can_lock_screen);
}
} // namespace test
diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc
new file mode 100644
index 0000000..881f4982
--- /dev/null
+++ b/ash/test/test_session_state_delegate.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/test/test_session_state_delegate.h"
+
+namespace ash {
+namespace test {
+
+TestSessionStateDelegate::TestSessionStateDelegate()
+ : has_active_user_(true),
+ active_user_session_started_(true),
+ can_lock_screen_(true),
+ screen_locked_(false) {
+}
+
+TestSessionStateDelegate::~TestSessionStateDelegate() {
+}
+
+bool TestSessionStateDelegate::HasActiveUser() const {
+ return has_active_user_;
+}
+
+bool TestSessionStateDelegate::IsActiveUserSessionStarted() const {
+ return active_user_session_started_;
+}
+
+bool TestSessionStateDelegate::CanLockScreen() const {
+ return has_active_user_ && can_lock_screen_;
+}
+
+bool TestSessionStateDelegate::IsScreenLocked() const {
+ return screen_locked_;
+}
+
+void TestSessionStateDelegate::LockScreen() {
+ if (CanLockScreen())
+ screen_locked_ = true;
+}
+
+void TestSessionStateDelegate::UnlockScreen() {
+ screen_locked_ = false;
+}
+
+void TestSessionStateDelegate::SetHasActiveUser(bool has_active_user) {
+ has_active_user_ = has_active_user;
+ if (!has_active_user)
+ active_user_session_started_ = false;
+}
+
+void TestSessionStateDelegate::SetActiveUserSessionStarted(
+ bool active_user_session_started) {
+ active_user_session_started_ = active_user_session_started;
+ if (active_user_session_started)
+ has_active_user_ = true;
+}
+
+void TestSessionStateDelegate::SetCanLockScreen(bool can_lock_screen) {
+ can_lock_screen_ = can_lock_screen;
+}
+
+} // namespace test
+} // namespace ash
diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h
new file mode 100644
index 0000000..807e335
--- /dev/null
+++ b/ash/test/test_session_state_delegate.h
@@ -0,0 +1,67 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_
+#define ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_
+
+#include "ash/session_state_delegate.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+namespace ash {
+namespace test {
+
+class TestSessionStateDelegate : public SessionStateDelegate {
+ public:
+ TestSessionStateDelegate();
+ virtual ~TestSessionStateDelegate();
+
+ // SessionStateDelegate:
+ virtual bool HasActiveUser() const OVERRIDE;
+ virtual bool IsActiveUserSessionStarted() const OVERRIDE;
+ virtual bool CanLockScreen() const OVERRIDE;
+ virtual bool IsScreenLocked() const OVERRIDE;
+ virtual void LockScreen() OVERRIDE;
+ virtual void UnlockScreen() OVERRIDE;
+
+ // Updates the internal state that indicates whether a session is in progress
+ // and there is an active user. If |has_active_user| is |false|,
+ // |active_user_session_started_| is reset to |false| as well (see below for
+ // the difference between these two flags).
+ void SetHasActiveUser(bool has_active_user);
+
+ // Updates the internal state that indicates whether the session has been
+ // fully started for the active user. If |active_user_session_started| is
+ // |true|, |has_active_user_| is set to |true| as well (see below for the
+ // difference between these two flags).
+ void SetActiveUserSessionStarted(bool active_user_session_started);
+
+ // Updates the internal state that indicates whether the screen can be locked.
+ // Locking will only actually be allowed when this value is |true| and there
+ // is an active user.
+ void SetCanLockScreen(bool can_lock_screen);
+
+ private:
+ // Whether a session is in progress and there is an active user.
+ bool has_active_user_;
+
+ // When a user becomes active, the profile and browser UI are not immediately
+ // available. Only once this flag becomes |true| is the browser startup
+ // complete and both profile and UI are fully available.
+ bool active_user_session_started_;
+
+ // Whether the screen can be locked. Locking will only actually be allowed
+ // when this is |true| and there is an active user.
+ bool can_lock_screen_;
+
+ // Whether the screen is currently locked.
+ bool screen_locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestSessionStateDelegate);
+};
+
+} // namespace test
+} // namespace ash
+
+#endif // ASH_TEST_TEST_SESSION_STATE_DELEGATE_H_
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc
index ea971d7..8013d08 100644
--- a/ash/test/test_shell_delegate.cc
+++ b/ash/test/test_shell_delegate.cc
@@ -8,10 +8,13 @@
#include "ash/caps_lock_delegate_stub.h"
#include "ash/host/root_window_host_factory.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/test_launcher_delegate.h"
+#include "ash/test/test_session_state_delegate.h"
#include "ash/wm/window_util.h"
+#include "base/logging.h"
#include "content/public/test/test_browser_context.h"
#include "ui/aura/window.h"
@@ -19,32 +22,17 @@ namespace ash {
namespace test {
TestShellDelegate::TestShellDelegate()
- : locked_(false),
- session_started_(true),
- spoken_feedback_enabled_(false),
+ : spoken_feedback_enabled_(false),
high_contrast_enabled_(false),
screen_magnifier_enabled_(false),
screen_magnifier_type_(kDefaultMagnifierType),
- user_logged_in_(true),
- can_lock_screen_(true),
- num_exit_requests_(0) {
+ num_exit_requests_(0),
+ test_session_state_delegate_(NULL) {
}
TestShellDelegate::~TestShellDelegate() {
}
-bool TestShellDelegate::IsUserLoggedIn() const {
- return user_logged_in_;
-}
-
-bool TestShellDelegate::IsSessionStarted() const {
- return session_started_;
-}
-
-bool TestShellDelegate::IsGuestSession() const {
- return false;
-}
-
bool TestShellDelegate::IsFirstRunAfterBoot() const {
return false;
}
@@ -57,22 +45,6 @@ bool TestShellDelegate::IsRunningInForcedAppMode() const {
return false;
}
-bool TestShellDelegate::CanLockScreen() const {
- return user_logged_in_ && can_lock_screen_;
-}
-
-void TestShellDelegate::LockScreen() {
- locked_ = true;
-}
-
-void TestShellDelegate::UnlockScreen() {
- locked_ = false;
-}
-
-bool TestShellDelegate::IsScreenLocked() const {
- return locked_;
-}
-
void TestShellDelegate::PreInit() {
}
@@ -185,6 +157,12 @@ CapsLockDelegate* TestShellDelegate::CreateCapsLockDelegate() {
return new CapsLockDelegateStub;
}
+SessionStateDelegate* TestShellDelegate::CreateSessionStateDelegate() {
+ DCHECK(!test_session_state_delegate_);
+ test_session_state_delegate_ = new TestSessionStateDelegate();
+ return test_session_state_delegate_;
+}
+
aura::client::UserActionClient* TestShellDelegate::CreateUserActionClient() {
return NULL;
}
@@ -229,26 +207,13 @@ RootWindowHostFactory* TestShellDelegate::CreateRootWindowHostFactory() {
return RootWindowHostFactory::Create();
}
-void TestShellDelegate::SetSessionStarted(bool session_started) {
- session_started_ = session_started;
- if (session_started)
- user_logged_in_ = true;
-}
-
-void TestShellDelegate::SetUserLoggedIn(bool user_logged_in) {
- user_logged_in_ = user_logged_in;
- if (!user_logged_in)
- session_started_ = false;
-}
-
-void TestShellDelegate::SetCanLockScreen(bool can_lock_screen) {
- can_lock_screen_ = can_lock_screen;
-}
-
base::string16 TestShellDelegate::GetProductName() const {
return base::string16();
}
+TestSessionStateDelegate* TestShellDelegate::test_session_state_delegate() {
+ return test_session_state_delegate_;
+}
} // namespace test
} // namespace ash
diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h
index 1ff9ce9..6c95ea8 100644
--- a/ash/test/test_shell_delegate.h
+++ b/ash/test/test_shell_delegate.h
@@ -18,7 +18,7 @@ class KeyboardControllerProxy;
namespace ash {
namespace test {
-class AshTestBase;
+class TestSessionStateDelegate;
class TestShellDelegate : public ShellDelegate {
public:
@@ -26,16 +26,9 @@ class TestShellDelegate : public ShellDelegate {
virtual ~TestShellDelegate();
// Overridden from ShellDelegate:
- virtual bool IsUserLoggedIn() const OVERRIDE;
- virtual bool IsSessionStarted() const OVERRIDE;
- virtual bool IsGuestSession() const OVERRIDE;
virtual bool IsFirstRunAfterBoot() const OVERRIDE;
virtual bool IsMultiProfilesEnabled() const OVERRIDE;
virtual bool IsRunningInForcedAppMode() const OVERRIDE;
- virtual bool CanLockScreen() const OVERRIDE;
- virtual void LockScreen() OVERRIDE;
- virtual void UnlockScreen() OVERRIDE;
- virtual bool IsScreenLocked() const OVERRIDE;
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
@@ -68,6 +61,7 @@ class TestShellDelegate : public ShellDelegate {
virtual SystemTrayDelegate* CreateSystemTrayDelegate() OVERRIDE;
virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
+ virtual SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(UserMetricsAction action) OVERRIDE;
@@ -85,39 +79,19 @@ class TestShellDelegate : public ShellDelegate {
int num_exit_requests() const { return num_exit_requests_; }
+ TestSessionStateDelegate* test_session_state_delegate();
+
private:
- friend class ash::test::AshTestBase;
-
- // Given |session_started| will update internal state.
- // If |session_started| is true this method will also set
- // |user_logged_in_| to true.
- // When session is started it always means that user has logged in.
- // Possible situation is that user has already logged in but session has not
- // been started (user selects avatar and login window is still open).
- void SetSessionStarted(bool session_started);
-
- // Given |user_logged_in| will update internal state.
- // If |user_logged_in| is false this method will also set |session_started_|
- // to false. When user is not logged in it always means that session
- // hasn't been started too.
- void SetUserLoggedIn(bool user_logged_in);
-
- // Sets the internal state that indicates whether the user can lock the
- // screen.
- void SetCanLockScreen(bool can_lock_screen);
-
- bool locked_;
- bool session_started_;
bool spoken_feedback_enabled_;
bool high_contrast_enabled_;
bool screen_magnifier_enabled_;
MagnifierType screen_magnifier_type_;
- bool user_logged_in_;
- bool can_lock_screen_;
int num_exit_requests_;
scoped_ptr<content::BrowserContext> current_browser_context_;
+ TestSessionStateDelegate* test_session_state_delegate_; // Not owned.
+
DISALLOW_COPY_AND_ASSIGN(TestShellDelegate);
};
diff --git a/ash/wm/event_client_impl.cc b/ash/wm/event_client_impl.cc
index 241f514..ab62f68 100644
--- a/ash/wm/event_client_impl.cc
+++ b/ash/wm/event_client_impl.cc
@@ -4,6 +4,7 @@
#include "ash/wm/event_client_impl.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ui/aura/window.h"
@@ -21,7 +22,8 @@ bool EventClientImpl::CanProcessEventsWithinSubtree(
const aura::Window* window) const {
const aura::RootWindow* root_window =
window ? window->GetRootWindow() : NULL;
- if (Shell::GetInstance()->IsScreenLocked() && root_window) {
+ if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
+ root_window) {
const aura::Window* lock_screen_containers = Shell::GetContainer(
root_window,
kShellWindowId_LockScreenContainersContainer);
diff --git a/ash/wm/gestures/shelf_gesture_handler.cc b/ash/wm/gestures/shelf_gesture_handler.cc
index a4e8737..2fa7905 100644
--- a/ash/wm/gestures/shelf_gesture_handler.cc
+++ b/ash/wm/gestures/shelf_gesture_handler.cc
@@ -5,11 +5,11 @@
#include "ash/wm/gestures/shelf_gesture_handler.h"
#include "ash/root_window_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_types.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/system/status_area_widget.h"
#include "ash/wm/gestures/tray_gesture_handler.h"
#include "ash/wm/window_util.h"
@@ -31,8 +31,8 @@ ShelfGestureHandler::~ShelfGestureHandler() {
bool ShelfGestureHandler::ProcessGestureEvent(const ui::GestureEvent& event) {
Shell* shell = Shell::GetInstance();
- if (!shell->delegate()->IsUserLoggedIn() ||
- shell->delegate()->IsScreenLocked()) {
+ if (!shell->session_state_delegate()->HasActiveUser() ||
+ shell->session_state_delegate()->IsScreenLocked()) {
// The gestures are disabled in the lock/login screen.
return false;
}
diff --git a/ash/wm/power_button_controller.cc b/ash/wm/power_button_controller.cc
index 9359b8a..6850608 100644
--- a/ash/wm/power_button_controller.cc
+++ b/ash/wm/power_button_controller.cc
@@ -5,8 +5,8 @@
#include "ash/wm/power_button_controller.h"
#include "ash/ash_switches.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/session_state_animator.h"
#include "ash/wm/session_state_controller.h"
@@ -45,13 +45,15 @@ void PowerButtonController::OnPowerButtonEvent(
if (screen_is_off_)
return;
- Shell* shell = Shell::GetInstance();
+ const SessionStateDelegate* session_state_delegate =
+ Shell::GetInstance()->session_state_delegate();
if (has_legacy_power_button_) {
// If power button releases won't get reported correctly because we're not
// running on official hardware, just lock the screen or shut down
// immediately.
if (down) {
- if (shell->CanLockScreen() && !shell->IsScreenLocked() &&
+ if (session_state_delegate->CanLockScreen() &&
+ !session_state_delegate->IsScreenLocked() &&
!controller_->LockRequested()) {
controller_->StartLockAnimationAndLockImmediately();
} else {
@@ -64,10 +66,12 @@ void PowerButtonController::OnPowerButtonEvent(
if (controller_->LockRequested())
return;
- if (shell->CanLockScreen() && !shell->IsScreenLocked())
+ if (session_state_delegate->CanLockScreen() &&
+ !session_state_delegate->IsScreenLocked()) {
controller_->StartLockAnimation(true);
- else
+ } else {
controller_->StartShutdownAnimation();
+ }
} else { // Button is up.
if (controller_->CanCancelLockAnimation())
controller_->CancelLockAnimation();
@@ -81,9 +85,12 @@ void PowerButtonController::OnLockButtonEvent(
bool down, const base::TimeTicks& timestamp) {
lock_button_down_ = down;
- Shell* shell = Shell::GetInstance();
- if (!shell->CanLockScreen() || shell->IsScreenLocked() ||
- controller_->LockRequested() || controller_->ShutdownRequested()) {
+ const SessionStateDelegate* session_state_delegate =
+ Shell::GetInstance()->session_state_delegate();
+ if (!session_state_delegate->CanLockScreen() ||
+ session_state_delegate->IsScreenLocked() ||
+ controller_->LockRequested() ||
+ controller_->ShutdownRequested()) {
return;
}
diff --git a/ash/wm/power_button_controller_unittest.cc b/ash/wm/power_button_controller_unittest.cc
index a989644..7dbdf73 100644
--- a/ash/wm/power_button_controller_unittest.cc
+++ b/ash/wm/power_button_controller_unittest.cc
@@ -8,6 +8,7 @@
#include "ash/wm/session_state_controller_impl.h"
#include "ash/ash_switches.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/test_shell_delegate.h"
@@ -77,6 +78,7 @@ class PowerButtonControllerTest : public AshTestBase {
animator_.get()));
shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
+ state_delegate_ = Shell::GetInstance()->session_state_delegate();
}
protected:
@@ -95,6 +97,7 @@ class PowerButtonControllerTest : public AshTestBase {
SessionStateControllerImpl* state_controller_; // not owned
TestPowerButtonControllerDelegate* delegate_; // not owned
TestShellDelegate* shell_delegate_; // not owned
+ SessionStateDelegate* state_delegate_; // not owned
scoped_ptr<SessionStateControllerImpl::TestApi> test_api_;
scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_;
@@ -139,7 +142,7 @@ TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) {
// Notify that the lock window is visible. We should make it fade in.
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
internal::SessionStateAnimator::kAllLockScreenContainersMask,
@@ -305,7 +308,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) {
// Notify that the lock window is visible. We should make it fade in.
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
internal::SessionStateAnimator::kAllLockScreenContainersMask,
@@ -320,7 +323,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) {
// Notify that the screen has been unlocked. We should show the
// non-screen-locker windows.
state_controller_->OnLockStateChanged(false);
- shell_delegate_->UnlockScreen();
+ state_delegate_->UnlockScreen();
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
internal::SessionStateAnimator::DESKTOP_BACKGROUND |
@@ -341,7 +344,7 @@ TEST_F(PowerButtonControllerTest, LockToShutdown) {
test_api_->trigger_lock_timeout();
state_controller_->OnStartingLock();
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
// When the lock-to-shutdown timeout fires, we should start the shutdown
// timer.
@@ -379,7 +382,7 @@ TEST_F(PowerButtonControllerTest, CancelLockToShutdown) {
// Power button is released while system attempts to lock.
controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
EXPECT_FALSE(state_controller_->ShutdownRequested());
EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
@@ -479,7 +482,7 @@ TEST_F(PowerButtonControllerTest, LockButtonBasic) {
// Pressing the button also shouldn't do anything after the screen is locked.
state_controller_->OnStartingLock();
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
EXPECT_FALSE(test_api_->lock_timer_is_running());
controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
@@ -568,7 +571,7 @@ TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) {
TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
state_controller_->RequestShutdown();
EXPECT_TRUE(
animator_api_->ContainersAreAnimated(
@@ -590,7 +593,7 @@ TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) {
TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) {
state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER);
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
// Press the power button and check that we start the shutdown timer.
controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
diff --git a/ash/wm/session_state_controller_impl2_unittest.cc b/ash/wm/session_state_controller_impl2_unittest.cc
index 08032e6..d5aec41 100644
--- a/ash/wm/session_state_controller_impl2_unittest.cc
+++ b/ash/wm/session_state_controller_impl2_unittest.cc
@@ -5,6 +5,7 @@
#include "ash/wm/session_state_controller_impl2.h"
#include "ash/ash_switches.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
@@ -137,6 +138,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
animator_.get()));
shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
ash::Shell::GetInstance()->delegate());
+ state_delegate_ = Shell::GetInstance()->session_state_delegate();
}
virtual void TearDown() {
@@ -310,7 +312,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
void ExpectUnlockedState() {
//TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
- EXPECT_FALSE(shell_delegate_->IsScreenLocked());
+ EXPECT_FALSE(state_delegate_->IsScreenLocked());
aura::Window::Windows containers;
@@ -331,7 +333,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
void ExpectLockedState() {
//TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
- EXPECT_TRUE(shell_delegate_->IsScreenLocked());
+ EXPECT_TRUE(state_delegate_->IsScreenLocked());
aura::Window::Windows containers;
@@ -370,7 +372,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
void SystemLocks() {
state_controller_->OnLockStateChanged(true);
- shell_delegate_->LockScreen();
+ state_delegate_->LockScreen();
//TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
}
@@ -382,7 +384,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
void SystemUnlocks() {
state_controller_->OnLockStateChanged(false);
- shell_delegate_->UnlockScreen();
+ state_delegate_->UnlockScreen();
//TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
}
@@ -399,6 +401,7 @@ class SessionStateControllerImpl2Test : public AshTestBase {
SessionStateControllerImpl2* state_controller_; // not owned
TestSessionStateControllerDelegate* delegate_; // not owned
TestShellDelegate* shell_delegate_; // not owned
+ SessionStateDelegate* state_delegate_; // not owned
scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_;
scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_;
diff --git a/ash/wm/stacking_controller.cc b/ash/wm/stacking_controller.cc
index bbafab48..3802440b 100644
--- a/ash/wm/stacking_controller.cc
+++ b/ash/wm/stacking_controller.cc
@@ -5,8 +5,8 @@
#include "ash/wm/stacking_controller.h"
#include "ash/display/display_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/always_on_top_controller.h"
#include "ash/wm/coordinate_conversion.h"
@@ -119,8 +119,9 @@ aura::Window* StackingController::GetSystemModalContainer(
// If screen lock is not active and user session is active,
// all modal windows are placed into the normal modal container.
- if (!Shell::GetInstance()->delegate()->IsScreenLocked() &&
- Shell::GetInstance()->delegate()->IsSessionStarted()) {
+ if (!Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
+ Shell::GetInstance()->session_state_delegate()->
+ IsActiveUserSessionStarted()) {
return GetContainerById(root,
internal::kShellWindowId_SystemModalContainer);
}
diff --git a/ash/wm/system_modal_container_layout_manager.cc b/ash/wm/system_modal_container_layout_manager.cc
index 192d5ab..d35aaa6 100644
--- a/ash/wm/system_modal_container_layout_manager.cc
+++ b/ash/wm/system_modal_container_layout_manager.cc
@@ -4,8 +4,8 @@
#include "ash/wm/system_modal_container_layout_manager.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/system_modal_container_event_filter.h"
#include "ash/wm/window_animations.h"
@@ -67,8 +67,9 @@ void SystemModalContainerLayoutManager::OnWindowAddedToLayout(
child->type() == aura::client::WINDOW_TYPE_POPUP);
DCHECK(
container_->id() != internal::kShellWindowId_LockSystemModalContainer ||
- Shell::GetInstance()->delegate()->IsScreenLocked() ||
- !Shell::GetInstance()->delegate()->IsSessionStarted());
+ Shell::GetInstance()->session_state_delegate()->IsScreenLocked() ||
+ !Shell::GetInstance()->session_state_delegate()->
+ IsActiveUserSessionStarted());
child->AddObserver(this);
if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE)
@@ -138,7 +139,7 @@ bool SystemModalContainerLayoutManager::CanWindowReceiveEvents(
return true;
// This container can not handle events if the screen is locked and it is not
// above the lock screen layer (crbug.com/110920).
- if (ash::Shell::GetInstance()->IsScreenLocked() &&
+ if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
container_->id() < ash::internal::kShellWindowId_LockScreenContainer)
return true;
return wm::GetActivatableWindow(window) == modal_window();
diff --git a/ash/wm/system_modal_container_layout_manager_unittest.cc b/ash/wm/system_modal_container_layout_manager_unittest.cc
index f7d7373..15107a4 100644
--- a/ash/wm/system_modal_container_layout_manager_unittest.cc
+++ b/ash/wm/system_modal_container_layout_manager_unittest.cc
@@ -5,8 +5,8 @@
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/root_window_controller.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h"
@@ -313,7 +313,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) {
// Create a window in the lock screen container and ensure that it receives
// the mouse event instead of the modal window (crbug.com/110920).
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
EventTestWindow* lock_delegate = new EventTestWindow(false);
scoped_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent(
Shell::GetPrimaryRootWindowController()->GetContainer(
@@ -337,7 +337,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) {
EXPECT_EQ(1, lock_delegate->mouse_presses());
EXPECT_EQ(1, lock_modal_delegate->mouse_presses());
- Shell::GetInstance()->delegate()->UnlockScreen();
+ Shell::GetInstance()->session_state_delegate()->UnlockScreen();
}
// Makes sure we don't crash if a modal window is shown while the parent window
@@ -409,7 +409,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) {
// Normal system modal window while locked. Shows locked system modal
// background.
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
scoped_ptr<aura::Window> lock_parent(OpenTestWindowWithParent(
Shell::GetPrimaryRootWindowController()->GetContainer(
ash::internal::kShellWindowId_LockScreenContainer),
diff --git a/ash/wm/window_cycle_controller.cc b/ash/wm/window_cycle_controller.cc
index 86f3cf8..0cdfcde 100644
--- a/ash/wm/window_cycle_controller.cc
+++ b/ash/wm/window_cycle_controller.cc
@@ -6,7 +6,8 @@
#include <algorithm>
-#include "ash/shell_delegate.h"
+#include "ash/session_state_delegate.h"
+#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/activation_controller.h"
#include "ash/wm/window_cycle_list.h"
@@ -121,7 +122,7 @@ WindowCycleController::~WindowCycleController() {
bool WindowCycleController::CanCycle() {
// Don't allow window cycling if the screen is locked or a modal dialog is
// open.
- return !Shell::GetInstance()->IsScreenLocked() &&
+ return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
!Shell::GetInstance()->IsSystemModalWindowOpen();
}
diff --git a/ash/wm/window_cycle_controller_unittest.cc b/ash/wm/window_cycle_controller_unittest.cc
index fabd9d9..186e2bdf7 100644
--- a/ash/wm/window_cycle_controller_unittest.cc
+++ b/ash/wm/window_cycle_controller_unittest.cc
@@ -8,6 +8,7 @@
#include "ash/display/display_controller.h"
#include "ash/display/display_manager.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
@@ -145,14 +146,14 @@ TEST_F(WindowCycleControllerTest, HandleCycleWindow) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// When the screen is locked, cycling window does not take effect.
- Shell::GetInstance()->delegate()->LockScreen();
+ Shell::GetInstance()->session_state_delegate()->LockScreen();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- Shell::GetInstance()->delegate()->UnlockScreen();
+ Shell::GetInstance()->session_state_delegate()->UnlockScreen();
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
diff --git a/ash/wm/workspace/workspace_cycler.cc b/ash/wm/workspace/workspace_cycler.cc
index 6731993..9d4cda1 100644
--- a/ash/wm/workspace/workspace_cycler.cc
+++ b/ash/wm/workspace/workspace_cycler.cc
@@ -6,6 +6,7 @@
#include <cmath>
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/wm/workspace/workspace_cycler_configuration.h"
#include "ash/wm/workspace/workspace_manager.h"
@@ -22,7 +23,7 @@ namespace {
// Returns true if cycling is allowed.
bool IsCyclingAllowed() {
// Cycling is disabled if the screen is locked or a modal dialog is open.
- return !Shell::GetInstance()->IsScreenLocked() &&
+ return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
!Shell::GetInstance()->IsSystemModalWindowOpen();
}
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index 1b052d2..1d4dc62 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -6,6 +6,7 @@
#include "ash/ash_switches.h"
#include "ash/screen_ash.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/wm/always_on_top_controller.h"
#include "ash/wm/base_layout_manager.h"
@@ -288,7 +289,7 @@ void WorkspaceLayoutManager::AdjustWindowSizesForScreenChange(
// This would happen if the launcher was auto hidden before the login screen
// was shown and then gets shown when the login screen gets presented.
if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED &&
- Shell::GetInstance()->IsScreenLocked())
+ Shell::GetInstance()->session_state_delegate()->IsScreenLocked())
return;
work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
workspace_->window()->parent());
diff --git a/chrome/browser/chromeos/dbus/printer_service_provider.cc b/chrome/browser/chromeos/dbus/printer_service_provider.cc
index 3db81cd..c6d4d74 100644
--- a/chrome/browser/chromeos/dbus/printer_service_provider.cc
+++ b/chrome/browser/chromeos/dbus/printer_service_provider.cc
@@ -4,8 +4,8 @@
#include "chrome/browser/chromeos/dbus/printer_service_provider.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
-#include "ash/shell_delegate.h"
#include "ash/wm/window_util.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
@@ -60,8 +60,9 @@ void FindOrOpenCloudPrintPage(const std::string& /* vendor */,
const std::string& /* product */) {
UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent", PRINTER_ADDED,
PRINTER_SERVICE_EVENT_MAX);
- if (!ash::Shell::GetInstance()->delegate()->IsSessionStarted() ||
- ash::Shell::GetInstance()->delegate()->IsScreenLocked()) {
+ if (!ash::Shell::GetInstance()->session_state_delegate()->
+ IsActiveUserSessionStarted() ||
+ ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
return;
}
diff --git a/chrome/browser/idle_chromeos.cc b/chrome/browser/idle_chromeos.cc
index 7977c41..9bb2f12 100644
--- a/chrome/browser/idle_chromeos.cc
+++ b/chrome/browser/idle_chromeos.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/idle.h"
+#include "ash/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/wm/user_activity_detector.h"
#include "base/time.h"
@@ -15,5 +16,5 @@ void CalculateIdleTime(IdleTimeCallback notify) {
}
bool CheckIdleStateIsLocked() {
- return ash::Shell::GetInstance()->IsScreenLocked();
+ return ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked();
}
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc
index 2ecb35a..1fd4f9a 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc
@@ -8,6 +8,7 @@
#include "ash/host/root_window_host_factory.h"
#include "ash/launcher/launcher_types.h"
#include "ash/magnifier/magnifier_constants.h"
+#include "ash/session_state_delegate.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/wm/window_properties.h"
@@ -26,6 +27,7 @@
#include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
+#include "chrome/browser/ui/ash/session_state_delegate.h"
#include "chrome/browser/ui/ash/user_action_handler.h"
#include "chrome/browser/ui/ash/window_positioner.h"
#include "chrome/browser/ui/browser.h"
@@ -79,11 +81,6 @@ bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
return chrome::IsRunningInForcedAppMode();
}
-void ChromeShellDelegate::UnlockScreen() {
- // This is used only for testing thus far.
- NOTIMPLEMENTED();
-}
-
void ChromeShellDelegate::Exit() {
chrome::AttemptUserExit();
}
@@ -198,6 +195,10 @@ ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate(
return launcher_delegate_;
}
+ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() {
+ return new SessionStateDelegate;
+}
+
aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() {
return new UserActionHandler;
}
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h
index bbe922d..4158f21 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate.h
+++ b/chrome/browser/ui/ash/chrome_shell_delegate.h
@@ -47,16 +47,9 @@ class ChromeShellDelegate : public ash::ShellDelegate,
}
// ash::ShellDelegate overrides;
- virtual bool IsUserLoggedIn() const OVERRIDE;
- virtual bool IsSessionStarted() const OVERRIDE;
- virtual bool IsGuestSession() const OVERRIDE;
virtual bool IsFirstRunAfterBoot() const OVERRIDE;
virtual bool IsMultiProfilesEnabled() const OVERRIDE;
virtual bool IsRunningInForcedAppMode() const OVERRIDE;
- virtual bool CanLockScreen() const OVERRIDE;
- virtual void LockScreen() OVERRIDE;
- virtual void UnlockScreen() OVERRIDE;
- virtual bool IsScreenLocked() const OVERRIDE;
virtual void PreInit() OVERRIDE;
virtual void Shutdown() OVERRIDE;
virtual void Exit() OVERRIDE;
@@ -89,6 +82,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate() OVERRIDE;
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
virtual ash::CapsLockDelegate* CreateCapsLockDelegate() OVERRIDE;
+ virtual ash::SessionStateDelegate* CreateSessionStateDelegate() OVERRIDE;
virtual aura::client::UserActionClient* CreateUserActionClient() OVERRIDE;
virtual void OpenFeedbackPage() OVERRIDE;
virtual void RecordUserMetricsAction(ash::UserMetricsAction action) OVERRIDE;
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
index 3440703..5745189 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc
@@ -8,7 +8,6 @@
#include "ash/system/chromeos/network/network_observer.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/wm/window_util.h"
-#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
#include "base/prefs/pref_service.h"
#include "base/utf_string_conversions.h"
@@ -24,7 +23,6 @@
#include "chrome/browser/chromeos/input_method/input_method_configuration.h"
#include "chrome/browser/chromeos/input_method/input_method_manager.h"
#include "chrome/browser/chromeos/login/screen_locker.h"
-#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_display_host.h"
#include "chrome/browser/chromeos/system/ash_system_tray_delegate.h"
#include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
@@ -43,60 +41,17 @@
#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
-#include "chromeos/dbus/session_manager_client.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
-bool ChromeShellDelegate::IsUserLoggedIn() const {
- // When running a Chrome OS build outside of a device (i.e. on a developer's
- // workstation) and not running as login-manager, pretend like we're always
- // logged in.
- if (!base::chromeos::IsRunningOnChromeOS() &&
- !CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kLoginManager)) {
- return true;
- }
-
- return chromeos::UserManager::Get()->IsUserLoggedIn();
-}
-
-bool ChromeShellDelegate::IsSessionStarted() const {
- // Returns true if we're logged in and browser has been started
- return chromeos::UserManager::Get()->IsSessionStarted();
-}
-
-bool ChromeShellDelegate::IsGuestSession() const {
- return CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kGuestSession);
-}
-
bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
return CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kFirstBoot);
}
-bool ChromeShellDelegate::CanLockScreen() const {
- return chromeos::UserManager::Get()->CanCurrentUserLock();
-}
-
-void ChromeShellDelegate::LockScreen() {
- if (CanLockScreen()) {
- // TODO(antrim) : additional logging for crbug/173178
- LOG(WARNING) << "Requesting screen lock from ChromeShellDelegate";
- chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
- RequestLockScreen();
- }
-}
-
-bool ChromeShellDelegate::IsScreenLocked() const {
- if (!chromeos::ScreenLocker::default_screen_locker())
- return false;
- return chromeos::ScreenLocker::default_screen_locker()->locked();
-}
-
void ChromeShellDelegate::PreInit() {
chromeos::LoadDisplayPreferences(IsFirstRunAfterBoot());
}
@@ -247,9 +202,6 @@ void ChromeShellDelegate::ShowKeyboardOverlay() {
}
bool ChromeShellDelegate::ShouldAlwaysShowAccessibilityMenu() const {
- if (!IsUserLoggedIn())
- return true;
-
Profile* profile = ProfileManager::GetDefaultProfile();
if (!profile)
return false;
diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
index 7d4d1ea..8bf7dca 100644
--- a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
+++ b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc
@@ -8,34 +8,10 @@
#include "chrome/browser/ui/ash/caps_lock_delegate_views.h"
#include "chrome/browser/ui/ash/window_positioner.h"
-bool ChromeShellDelegate::IsUserLoggedIn() const {
- return true;
-}
-
-// Returns true if we're logged in and browser has been started
-bool ChromeShellDelegate::IsSessionStarted() const {
- return true;
-}
-
-bool ChromeShellDelegate::IsGuestSession() const {
- return false;
-}
-
bool ChromeShellDelegate::IsFirstRunAfterBoot() const {
return false;
}
-bool ChromeShellDelegate::CanLockScreen() const {
- return false;
-}
-
-void ChromeShellDelegate::LockScreen() {
-}
-
-bool ChromeShellDelegate::IsScreenLocked() const {
- return false;
-}
-
void ChromeShellDelegate::PreInit() {
}
diff --git a/chrome/browser/ui/ash/session_state_delegate.h b/chrome/browser/ui/ash/session_state_delegate.h
new file mode 100644
index 0000000..9209c45
--- /dev/null
+++ b/chrome/browser/ui/ash/session_state_delegate.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_
+#define CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_
+
+#include "ash/session_state_delegate.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+class SessionStateDelegate : public ash::SessionStateDelegate {
+ public:
+ SessionStateDelegate();
+ virtual ~SessionStateDelegate();
+
+ // ash::SessionStateDelegate:
+ virtual bool HasActiveUser() const OVERRIDE;
+ virtual bool IsActiveUserSessionStarted() const OVERRIDE;
+ virtual bool CanLockScreen() const OVERRIDE;
+ virtual bool IsScreenLocked() const OVERRIDE;
+ virtual void LockScreen() OVERRIDE;
+ virtual void UnlockScreen() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SessionStateDelegate);
+};
+
+#endif // CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_
diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc
new file mode 100644
index 0000000..24936e9
--- /dev/null
+++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/ash/session_state_delegate.h"
+
+#include "base/logging.h"
+#include "chrome/browser/chromeos/login/screen_locker.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/session_manager_client.h"
+
+SessionStateDelegate::SessionStateDelegate() {
+}
+
+SessionStateDelegate::~SessionStateDelegate() {
+}
+
+bool SessionStateDelegate::HasActiveUser() const {
+ return chromeos::UserManager::Get()->IsUserLoggedIn();
+}
+
+bool SessionStateDelegate::IsActiveUserSessionStarted() const {
+ return chromeos::UserManager::Get()->IsSessionStarted();
+}
+
+bool SessionStateDelegate::CanLockScreen() const {
+ return chromeos::UserManager::Get()->CanCurrentUserLock();
+}
+
+bool SessionStateDelegate::IsScreenLocked() const {
+ return chromeos::ScreenLocker::default_screen_locker() &&
+ chromeos::ScreenLocker::default_screen_locker()->locked();
+}
+
+void SessionStateDelegate::LockScreen() {
+ if (!CanLockScreen())
+ return;
+
+ // TODO(antrim): Additional logging for http://crbug.com/173178.
+ LOG(WARNING) << "Requesting screen lock from SessionStateDelegate";
+ chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
+ RequestLockScreen();
+}
+
+void SessionStateDelegate::UnlockScreen() {
+ // This is used only for testing thus far.
+ NOTIMPLEMENTED();
+}
diff --git a/chrome/browser/ui/ash/session_state_delegate_views.cc b/chrome/browser/ui/ash/session_state_delegate_views.cc
new file mode 100644
index 0000000..e8e4e51
--- /dev/null
+++ b/chrome/browser/ui/ash/session_state_delegate_views.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/ash/session_state_delegate.h"
+
+SessionStateDelegate::SessionStateDelegate() {
+}
+
+SessionStateDelegate::~SessionStateDelegate() {
+}
+
+bool SessionStateDelegate::HasActiveUser() const {
+ return true;
+}
+
+bool SessionStateDelegate::IsActiveUserSessionStarted() const {
+ return true;
+}
+
+bool SessionStateDelegate::CanLockScreen() const {
+ return false;
+}
+
+bool SessionStateDelegate::IsScreenLocked() const {
+ return false;
+}
+
+void SessionStateDelegate::LockScreen() {
+}
+
+void SessionStateDelegate::UnlockScreen() {
+}
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index eb0fc6a..c8e2db9 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -204,6 +204,9 @@
'browser/ui/ash/launcher/shell_window_launcher_controller.h',
'browser/ui/ash/screenshot_taker.cc',
'browser/ui/ash/screenshot_taker.h',
+ 'browser/ui/ash/session_state_delegate.h',
+ 'browser/ui/ash/session_state_delegate_chromeos.cc',
+ 'browser/ui/ash/session_state_delegate_views.cc',
'browser/ui/ash/tabs/dock_info_ash.cc',
'browser/ui/ash/tabs/dock_info_ash.h',
'browser/ui/ash/tabs/dock_info_chromeos.cc',
@@ -2418,6 +2421,7 @@
['exclude', 'browser/storage_monitor/storage_monitor_linux.h'],
['exclude', 'browser/ui/ash/caps_lock_delegate_views.cc'],
['exclude', 'browser/ui/ash/chrome_shell_delegate_views.cc'],
+ ['exclude', 'browser/ui/ash/session_state_delegate_views.cc'],
['exclude', 'browser/ui/screen_capture_notification_ui_stub.cc'],
['exclude', 'browser/ui/views/frame/desktop_browser_frame_aura.cc'],
['exclude', 'browser/ui/views/frame/desktop_browser_frame_aura.h'],