diff options
author | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 14:47:48 +0000 |
---|---|---|
committer | gavinp@chromium.org <gavinp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 14:47:48 +0000 |
commit | f2192efaf719d6e54459fde8ef38093e08e194e0 (patch) | |
tree | 26b06fa106a8ab701dcda5e4c00f959d9d82a700 /ash | |
parent | b0b94f5c503e44cc2190a9c7c4d20425f77e6a42 (diff) | |
download | chromium_src-f2192efaf719d6e54459fde8ef38093e08e194e0.zip chromium_src-f2192efaf719d6e54459fde8ef38093e08e194e0.tar.gz chromium_src-f2192efaf719d6e54459fde8ef38093e08e194e0.tar.bz2 |
Revert 194578 "Add ash SessionStateDelegate"
> 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
TBR=bartfab@google.com
Review URL: https://codereview.chromium.org/14200034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194589 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
40 files changed, 256 insertions, 425 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index a98c4b36..9face4f 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -26,7 +26,6 @@ #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" @@ -102,7 +101,7 @@ void HandleCycleWindowLinear(CycleDirection direction) { #if defined(OS_CHROMEOS) bool HandleLock() { - Shell::GetInstance()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->delegate()->LockScreen(); return true; } @@ -428,12 +427,16 @@ bool AcceleratorController::IsReservedAccelerator( bool AcceleratorController::PerformAction(int action, const ui::Accelerator& accelerator) { ash::Shell* shell = ash::Shell::GetInstance(); - if (!shell->session_state_delegate()->IsActiveUserSessionStarted() && + bool at_login_screen = false; +#if defined(OS_CHROMEOS) + at_login_screen = !shell->delegate()->IsSessionStarted(); +#endif + if (at_login_screen && actions_allowed_at_login_screen_.find(action) == actions_allowed_at_login_screen_.end()) { return false; } - if (shell->session_state_delegate()->IsScreenLocked() && + if (shell->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 ecc7972..3cf1721 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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()->session_state_delegate()->UnlockScreen(); + Shell::GetInstance()->delegate()->UnlockScreen(); } // Aura window above lock screen in z order. diff --git a/ash/ash.gyp b/ash/ash.gyp index 46debce..1ea89b8 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -163,7 +163,6 @@ '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', @@ -551,8 +550,6 @@ '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', @@ -640,8 +637,6 @@ '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', @@ -768,8 +763,6 @@ '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 6d6e487..35e7d0d 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,7 +201,8 @@ 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()->session_state_delegate()->HasActiveUser()) { + Shell::GetInstance()->delegate()->IsGuestSession() || + Shell::GetInstance()->delegate()->IsUserLoggedIn()) { 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 6a8e815..86911f7 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -12,7 +12,6 @@ #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" @@ -291,7 +290,7 @@ void RootWindowController::InitForPrimaryDisplay() { new ToplevelWindowEventHandler(panel_container)); panel_container->SetLayoutManager(panel_layout_manager_); } - if (Shell::GetInstance()->session_state_delegate()->HasActiveUser()) + if (Shell::GetInstance()->delegate()->IsUserLoggedIn()) shelf_->CreateLauncher(); InitKeyboard(); diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc index c5bd68d..55f0763 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->session_state_delegate()->LockScreen(); + shell->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->session_state_delegate()->UnlockScreen(); + shell->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->session_state_delegate()->HasActiveUser()); - EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); + EXPECT_FALSE(shell->delegate()->IsUserLoggedIn()); + EXPECT_FALSE(shell->delegate()->IsSessionStarted()); 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->session_state_delegate()->HasActiveUser()); - EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); + EXPECT_TRUE(shell->delegate()->IsUserLoggedIn()); + EXPECT_TRUE(shell->delegate()->IsSessionStarted()); 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 deleted file mode 100644 index f5ee359..0000000 --- a/ash/session_state_delegate.h +++ /dev/null @@ -1,41 +0,0 @@ -// 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 deleted file mode 100644 index b913b5f..0000000 --- a/ash/session_state_delegate_stub.cc +++ /dev/null @@ -1,45 +0,0 @@ -// 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 deleted file mode 100644 index db9b711..0000000 --- a/ash/session_state_delegate_stub.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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 3f168e2..6e9e3c7 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,7 +272,8 @@ ShelfLayoutManager::CalculateShelfVisibilityWhileDragging() { } void ShelfLayoutManager::UpdateVisibilityState() { - if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { + ShellDelegate* delegate = Shell::GetInstance()->delegate(); + if (delegate && 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 @@ -513,11 +514,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 = - Shell::GetInstance()->session_state_delegate()->IsScreenLocked(); + state.is_screen_locked = delegate && 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 faf1edb..30c9220 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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()->session_state_delegate()->UnlockScreen(); + Shell::GetInstance()->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 1e2da78..7550622 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,10 +440,8 @@ ShelfWidget::ShelfWidget( status_area_widget_ = new internal::StatusAreaWidget(status_container); status_area_widget_->CreateTrayViews(); - if (Shell::GetInstance()->session_state_delegate()-> - IsActiveUserSessionStarted()) { + if (Shell::GetInstance()->delegate()->IsSessionStarted()) status_area_widget_->Show(); - } Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); shelf_layout_manager_ = new internal::ShelfLayoutManager(this); @@ -500,8 +498,9 @@ void ShelfWidget::CreateLauncher() { internal::RootWindowController::ForWindow(window_container_)-> OnLauncherCreated(); - launcher_->SetVisible( - shell->session_state_delegate()->IsActiveUserSessionStarted()); + ShellDelegate* delegate = shell->delegate(); + if (delegate) + launcher_->SetVisible(delegate->IsSessionStarted()); Show(); } diff --git a/ash/shell.cc b/ash/shell.cc index 9356cfc..7b809cb 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -28,7 +28,6 @@ #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" @@ -560,8 +559,6 @@ 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( @@ -605,11 +602,11 @@ void Shell::Init() { } void Shell::ShowContextMenu(const gfx::Point& location_in_screen) { - // No context menus if there is no session with an active user. - if (!session_state_delegate_->HasActiveUser()) + // No context menus if user have not logged in. + if (!delegate_->IsUserLoggedIn()) return; // No context menus when screen is locked. - if (session_state_delegate_->IsScreenLocked()) + if (IsScreenLocked()) return; aura::RootWindow* root = @@ -643,6 +640,14 @@ 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 e8089c1..e644d2a 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -82,7 +82,6 @@ class PowerButtonController; class RootWindowHostFactory; class ScreenAsh; class SessionStateController; -class SessionStateDelegate; class ShellDelegate; class ShellObserver; class SystemTray; @@ -218,6 +217,13 @@ 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; @@ -328,10 +334,6 @@ 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(); } @@ -501,7 +503,6 @@ 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 9afee4f..d005f2d 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->delegate()->LockScreen(); break; } case WIDGETS_WINDOW: { diff --git a/ash/shell/lock_view.cc b/ash/shell/lock_view.cc index 235cb81..d60eba2b 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()->session_state_delegate()->UnlockScreen(); + Shell::GetInstance()->delegate()->UnlockScreen(); } // Overridden from views::ButtonListener: diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index 69dec53c..bb29637 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -8,8 +8,6 @@ #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" @@ -25,6 +23,7 @@ namespace shell { ShellDelegateImpl::ShellDelegateImpl() : watcher_(NULL), launcher_delegate_(NULL), + locked_(false), spoken_feedback_enabled_(false), high_contrast_enabled_(false), screen_magnifier_enabled_(false), @@ -40,6 +39,18 @@ 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; } @@ -52,6 +63,25 @@ 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() { } @@ -168,10 +198,6 @@ 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 81d5228..b162d7a 100644 --- a/ash/shell/shell_delegate_impl.h +++ b/ash/shell/shell_delegate_impl.h @@ -27,9 +27,16 @@ 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; @@ -62,7 +69,6 @@ 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; @@ -85,6 +91,7 @@ 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 caeb673..c764a41 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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 0ff5fe6..99aeb6e 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -45,7 +45,6 @@ class LauncherDelegate; class LauncherModel; struct LauncherItem; class RootWindowHostFactory; -class SessionStateDelegate; class SystemTrayDelegate; class UserWallpaperDelegate; @@ -99,6 +98,15 @@ 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. @@ -110,6 +118,19 @@ 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; @@ -205,9 +226,6 @@ 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 70ca5c2..039354f 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->delegate()->LockScreen(); // Create a LockScreen window. views::Widget* lock_widget = CreateTestWindow(widget_params); ash::Shell::GetContainer( @@ -264,12 +264,10 @@ TEST_F(ShellTest, CreateLockScreenModalWindow) { } TEST_F(ShellTest, IsScreenLocked) { - SessionStateDelegate* delegate = - Shell::GetInstance()->session_state_delegate(); - delegate->LockScreen(); - EXPECT_TRUE(delegate->IsScreenLocked()); - delegate->UnlockScreen(); - EXPECT_FALSE(delegate->IsScreenLocked()); + ash::Shell::GetInstance()->delegate()->LockScreen(); + EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); + ash::Shell::GetInstance()->delegate()->UnlockScreen(); + EXPECT_FALSE(Shell::GetInstance()->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 34edabb..fb1fffb 100644 --- a/ash/system/date/tray_date.cc +++ b/ash/system/date/tray_date.cc @@ -4,7 +4,6 @@ #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" @@ -90,7 +89,7 @@ class DateDefaultView : public views::View, view->AddButton(shutdown_); } - if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) { + if (ash::Shell::GetInstance()->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 b02f208..30e63e4 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,12 +90,9 @@ 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(). - SessionStateDelegate* delegate = - Shell::GetInstance()->session_state_delegate(); - - if (!delegate->IsActiveUserSessionStarted()) + if (!Shell::GetInstance()->delegate()->IsSessionStarted()) return ash::user::LOGGED_IN_NONE; - if (delegate->IsScreenLocked()) + if (Shell::GetInstance()->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 24b004f..3346c3c 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -14,7 +14,6 @@ #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" @@ -276,18 +275,15 @@ void AshTestBase::RunAllPendingInMessageLoop() { } void AshTestBase::SetSessionStarted(bool session_started) { - test_shell_delegate_->test_session_state_delegate()-> - SetActiveUserSessionStarted(session_started); + test_shell_delegate_->SetSessionStarted(session_started); } void AshTestBase::SetUserLoggedIn(bool user_logged_in) { - test_shell_delegate_->test_session_state_delegate()-> - SetHasActiveUser(user_logged_in); + test_shell_delegate_->SetUserLoggedIn(user_logged_in); } void AshTestBase::SetCanLockScreen(bool can_lock_screen) { - test_shell_delegate_->test_session_state_delegate()-> - SetCanLockScreen(can_lock_screen); + test_shell_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 deleted file mode 100644 index 881f4982..0000000 --- a/ash/test/test_session_state_delegate.cc +++ /dev/null @@ -1,63 +0,0 @@ -// 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 deleted file mode 100644 index 807e335..0000000 --- a/ash/test/test_session_state_delegate.h +++ /dev/null @@ -1,67 +0,0 @@ -// 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 8013d08..ea971d7 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -8,13 +8,10 @@ #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" @@ -22,17 +19,32 @@ namespace ash { namespace test { TestShellDelegate::TestShellDelegate() - : spoken_feedback_enabled_(false), + : locked_(false), + session_started_(true), + spoken_feedback_enabled_(false), high_contrast_enabled_(false), screen_magnifier_enabled_(false), screen_magnifier_type_(kDefaultMagnifierType), - num_exit_requests_(0), - test_session_state_delegate_(NULL) { + user_logged_in_(true), + can_lock_screen_(true), + num_exit_requests_(0) { } 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; } @@ -45,6 +57,22 @@ 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() { } @@ -157,12 +185,6 @@ 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; } @@ -207,13 +229,26 @@ 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 6c95ea8..1ff9ce9 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 TestSessionStateDelegate; +class AshTestBase; class TestShellDelegate : public ShellDelegate { public: @@ -26,9 +26,16 @@ 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; @@ -61,7 +68,6 @@ 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; @@ -79,19 +85,39 @@ 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 ab62f68..241f514 100644 --- a/ash/wm/event_client_impl.cc +++ b/ash/wm/event_client_impl.cc @@ -4,7 +4,6 @@ #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" @@ -22,8 +21,7 @@ bool EventClientImpl::CanProcessEventsWithinSubtree( const aura::Window* window) const { const aura::RootWindow* root_window = window ? window->GetRootWindow() : NULL; - if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && - root_window) { + if (Shell::GetInstance()->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 2fa7905..a4e8737 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->session_state_delegate()->HasActiveUser() || - shell->session_state_delegate()->IsScreenLocked()) { + if (!shell->delegate()->IsUserLoggedIn() || + shell->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 6850608..9359b8a 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,15 +45,13 @@ void PowerButtonController::OnPowerButtonEvent( if (screen_is_off_) return; - const SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); + Shell* shell = Shell::GetInstance(); 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 (session_state_delegate->CanLockScreen() && - !session_state_delegate->IsScreenLocked() && + if (shell->CanLockScreen() && !shell->IsScreenLocked() && !controller_->LockRequested()) { controller_->StartLockAnimationAndLockImmediately(); } else { @@ -66,12 +64,10 @@ void PowerButtonController::OnPowerButtonEvent( if (controller_->LockRequested()) return; - if (session_state_delegate->CanLockScreen() && - !session_state_delegate->IsScreenLocked()) { + if (shell->CanLockScreen() && !shell->IsScreenLocked()) controller_->StartLockAnimation(true); - } else { + else controller_->StartShutdownAnimation(); - } } else { // Button is up. if (controller_->CanCancelLockAnimation()) controller_->CancelLockAnimation(); @@ -85,12 +81,9 @@ void PowerButtonController::OnLockButtonEvent( bool down, const base::TimeTicks& timestamp) { lock_button_down_ = down; - const SessionStateDelegate* session_state_delegate = - Shell::GetInstance()->session_state_delegate(); - if (!session_state_delegate->CanLockScreen() || - session_state_delegate->IsScreenLocked() || - controller_->LockRequested() || - controller_->ShutdownRequested()) { + Shell* shell = Shell::GetInstance(); + if (!shell->CanLockScreen() || shell->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 7dbdf73..a989644 100644 --- a/ash/wm/power_button_controller_unittest.cc +++ b/ash/wm/power_button_controller_unittest.cc @@ -8,7 +8,6 @@ #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" @@ -78,7 +77,6 @@ class PowerButtonControllerTest : public AshTestBase { animator_.get())); shell_delegate_ = reinterpret_cast<TestShellDelegate*>( ash::Shell::GetInstance()->delegate()); - state_delegate_ = Shell::GetInstance()->session_state_delegate(); } protected: @@ -97,7 +95,6 @@ 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_; @@ -142,7 +139,7 @@ TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { // Notify that the lock window is visible. We should make it fade in. state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); EXPECT_TRUE( animator_api_->ContainersAreAnimated( internal::SessionStateAnimator::kAllLockScreenContainersMask, @@ -308,7 +305,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) { // Notify that the lock window is visible. We should make it fade in. state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); EXPECT_TRUE( animator_api_->ContainersAreAnimated( internal::SessionStateAnimator::kAllLockScreenContainersMask, @@ -323,7 +320,7 @@ TEST_F(PowerButtonControllerTest, LockAndUnlock) { // Notify that the screen has been unlocked. We should show the // non-screen-locker windows. state_controller_->OnLockStateChanged(false); - state_delegate_->UnlockScreen(); + shell_delegate_->UnlockScreen(); EXPECT_TRUE( animator_api_->ContainersAreAnimated( internal::SessionStateAnimator::DESKTOP_BACKGROUND | @@ -344,7 +341,7 @@ TEST_F(PowerButtonControllerTest, LockToShutdown) { test_api_->trigger_lock_timeout(); state_controller_->OnStartingLock(); state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); // When the lock-to-shutdown timeout fires, we should start the shutdown // timer. @@ -382,7 +379,7 @@ TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { // Power button is released while system attempts to lock. controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); EXPECT_FALSE(state_controller_->ShutdownRequested()); EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); @@ -482,7 +479,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); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); EXPECT_FALSE(test_api_->lock_timer_is_running()); controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); @@ -571,7 +568,7 @@ TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); state_controller_->RequestShutdown(); EXPECT_TRUE( animator_api_->ContainersAreAnimated( @@ -593,7 +590,7 @@ TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_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 d5aec41..08032e6 100644 --- a/ash/wm/session_state_controller_impl2_unittest.cc +++ b/ash/wm/session_state_controller_impl2_unittest.cc @@ -5,7 +5,6 @@ #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" @@ -138,7 +137,6 @@ 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() { @@ -312,7 +310,7 @@ class SessionStateControllerImpl2Test : public AshTestBase { void ExpectUnlockedState() { //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); - EXPECT_FALSE(state_delegate_->IsScreenLocked()); + EXPECT_FALSE(shell_delegate_->IsScreenLocked()); aura::Window::Windows containers; @@ -333,7 +331,7 @@ class SessionStateControllerImpl2Test : public AshTestBase { void ExpectLockedState() { //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating()); - EXPECT_TRUE(state_delegate_->IsScreenLocked()); + EXPECT_TRUE(shell_delegate_->IsScreenLocked()); aura::Window::Windows containers; @@ -372,7 +370,7 @@ class SessionStateControllerImpl2Test : public AshTestBase { void SystemLocks() { state_controller_->OnLockStateChanged(true); - state_delegate_->LockScreen(); + shell_delegate_->LockScreen(); //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); } @@ -384,7 +382,7 @@ class SessionStateControllerImpl2Test : public AshTestBase { void SystemUnlocks() { state_controller_->OnLockStateChanged(false); - state_delegate_->UnlockScreen(); + shell_delegate_->UnlockScreen(); //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta()); } @@ -401,7 +399,6 @@ 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 3802440b..bbafab48 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,9 +119,8 @@ 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()->session_state_delegate()->IsScreenLocked() && - Shell::GetInstance()->session_state_delegate()-> - IsActiveUserSessionStarted()) { + if (!Shell::GetInstance()->delegate()->IsScreenLocked() && + Shell::GetInstance()->delegate()->IsSessionStarted()) { 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 d35aaa6..192d5ab 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,9 +67,8 @@ void SystemModalContainerLayoutManager::OnWindowAddedToLayout( child->type() == aura::client::WINDOW_TYPE_POPUP); DCHECK( container_->id() != internal::kShellWindowId_LockSystemModalContainer || - Shell::GetInstance()->session_state_delegate()->IsScreenLocked() || - !Shell::GetInstance()->session_state_delegate()-> - IsActiveUserSessionStarted()); + Shell::GetInstance()->delegate()->IsScreenLocked() || + !Shell::GetInstance()->delegate()->IsSessionStarted()); child->AddObserver(this); if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) @@ -139,7 +138,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 (Shell::GetInstance()->session_state_delegate()->IsScreenLocked() && + if (ash::Shell::GetInstance()->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 15107a4..f7d7373 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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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()->session_state_delegate()->UnlockScreen(); + Shell::GetInstance()->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()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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 0cdfcde..86f3cf8 100644 --- a/ash/wm/window_cycle_controller.cc +++ b/ash/wm/window_cycle_controller.cc @@ -6,8 +6,7 @@ #include <algorithm> -#include "ash/session_state_delegate.h" -#include "ash/shell.h" +#include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" #include "ash/wm/activation_controller.h" #include "ash/wm/window_cycle_list.h" @@ -122,7 +121,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()->session_state_delegate()->IsScreenLocked() && + return !Shell::GetInstance()->IsScreenLocked() && !Shell::GetInstance()->IsSystemModalWindowOpen(); } diff --git a/ash/wm/window_cycle_controller_unittest.cc b/ash/wm/window_cycle_controller_unittest.cc index 186e2bdf7..fabd9d9 100644 --- a/ash/wm/window_cycle_controller_unittest.cc +++ b/ash/wm/window_cycle_controller_unittest.cc @@ -8,7 +8,6 @@ #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" @@ -146,14 +145,14 @@ TEST_F(WindowCycleControllerTest, HandleCycleWindow) { EXPECT_TRUE(wm::IsActiveWindow(window0.get())); // When the screen is locked, cycling window does not take effect. - Shell::GetInstance()->session_state_delegate()->LockScreen(); + Shell::GetInstance()->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()->session_state_delegate()->UnlockScreen(); + Shell::GetInstance()->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 9d4cda1..6731993 100644 --- a/ash/wm/workspace/workspace_cycler.cc +++ b/ash/wm/workspace/workspace_cycler.cc @@ -6,7 +6,6 @@ #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" @@ -23,7 +22,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()->session_state_delegate()->IsScreenLocked() && + return !Shell::GetInstance()->IsScreenLocked() && !Shell::GetInstance()->IsSystemModalWindowOpen(); } diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc index 1d4dc62..1b052d2 100644 --- a/ash/wm/workspace/workspace_layout_manager.cc +++ b/ash/wm/workspace/workspace_layout_manager.cc @@ -6,7 +6,6 @@ #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" @@ -289,7 +288,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()->session_state_delegate()->IsScreenLocked()) + Shell::GetInstance()->IsScreenLocked()) return; work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent( workspace_->window()->parent()); |