Skip to content

Commit

Permalink
Revert 194589 "Revert 194578 "Add ash SessionStateDelegate""
Browse files Browse the repository at this point in the history
The CL turned out to be innocent, the bots turned green without the revert.

> 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

TBR=gavinp@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194602 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
bartfab@google.com committed Apr 17, 2013
1 parent 6f9c92a commit fcb123d
Show file tree
Hide file tree
Showing 50 changed files with 553 additions and 344 deletions.
11 changes: 4 additions & 7 deletions ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ash/accelerators/nested_dispatcher_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -109,15 +109,15 @@ 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(
&inner_dispatcher,
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.
Expand Down
7 changes: 7 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions ash/desktop_background/desktop_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions ash/root_window_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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));
Expand Down
41 changes: 41 additions & 0 deletions ash/session_state_delegate.h
Original file line number Diff line number Diff line change
@@ -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_
45 changes: 45 additions & 0 deletions ash/session_state_delegate_stub.cc
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions ash/session_state_delegate_stub.h
Original file line number Diff line number Diff line change
@@ -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_
9 changes: 4 additions & 5 deletions ash/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions ash/shelf/shelf_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}
Expand Down
Loading

0 comments on commit fcb123d

Please sign in to comment.