Skip to content

Commit

Permalink
Introduce SessionStateObserver
Browse files Browse the repository at this point in the history
Use this in tooltip managers (158027 : Lockscreen leaks information via tooltip),
Use this in launcher animation on full lock in new animations (138171).

BUG=158027,138171


Review URL: https://chromiumcodereview.appspot.com/11416037

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169033 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
antrim@chromium.org committed Nov 21, 2012
1 parent d38ae9d commit 83482fb
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 41 deletions.
1 change: 1 addition & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
'wm/session_state_controller_impl.h',
'wm/session_state_controller_impl2.cc',
'wm/session_state_controller_impl2.h',
'wm/session_state_observer.h',
'wm/shelf_layout_manager.cc',
'wm/shelf_layout_manager.h',
'wm/shelf_types.h',
Expand Down
17 changes: 15 additions & 2 deletions ash/launcher/launcher_tooltip_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "ash/launcher/launcher_view.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/session_state_controller.h"
#include "ash/wm/session_state_observer.h"
#include "ash/wm/window_animations.h"
#include "base/bind.h"
#include "base/message_loop.h"
Expand Down Expand Up @@ -148,17 +150,21 @@ LauncherTooltipManager::LauncherTooltipManager(
launcher_view_(launcher_view) {
if (shelf_layout_manager)
shelf_layout_manager->AddObserver(this);
if (Shell::HasInstance())
if (Shell::HasInstance()) {
Shell::GetInstance()->AddPreTargetHandler(this);
Shell::GetInstance()->session_state_controller()->AddObserver(this);
}
}

LauncherTooltipManager::~LauncherTooltipManager() {
CancelHidingAnimation();
Close();
if (shelf_layout_manager_)
shelf_layout_manager_->RemoveObserver(this);
if (Shell::HasInstance())
if (Shell::HasInstance()) {
Shell::GetInstance()->RemovePreTargetHandler(this);
Shell::GetInstance()->session_state_controller()->RemoveObserver(this);
}
}

void LauncherTooltipManager::ShowDelayed(views::View* anchor,
Expand Down Expand Up @@ -307,6 +313,13 @@ ui::EventResult LauncherTooltipManager::OnGestureEvent(
return ui::ER_UNHANDLED;
}

void LauncherTooltipManager::OnSessionStateEvent(
SessionStateObserver::EventType event) {
if (event == SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED ||
event == SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED)
Close();
}

void LauncherTooltipManager::WillDeleteShelf() {
shelf_layout_manager_ = NULL;
}
Expand Down
8 changes: 7 additions & 1 deletion ash/launcher/launcher_tooltip_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ASH_LAUNCHER_LAUNCHER_TOOLTIP_MANAGER_H_

#include "ash/ash_export.h"
#include "ash/wm/session_state_observer.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/shelf_types.h"
#include "base/basictypes.h"
Expand Down Expand Up @@ -36,7 +37,8 @@ class LauncherView;
// LauncherTooltipManager manages the tooltip balloon poping up on launcher
// items.
class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler,
public ShelfLayoutManager::Observer {
public ShelfLayoutManager::Observer,
public SessionStateObserver {
public:
LauncherTooltipManager(ShelfAlignment alignment,
ShelfLayoutManager* shelf_layout_manager,
Expand Down Expand Up @@ -75,6 +77,10 @@ class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler,
virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE;

// SessionStateObserver override:
virtual void OnSessionStateEvent(SessionStateObserver::EventType event)
OVERRIDE;

// ShelfLayoutManager::Observer overrides:
virtual void WillDeleteShelf() OVERRIDE;
virtual void WillChangeVisibilityState(
Expand Down
1 change: 1 addition & 0 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void RootWindowController::CloseChildWindows() {
delete child;
}

launcher_.reset();
// All containers are deleted, so reset shelf_.
shelf_ = NULL;
}
Expand Down
21 changes: 11 additions & 10 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ Shell::~Shell() {
drag_drop_controller_.reset();
magnification_controller_.reset();
partial_magnification_controller_.reset();
power_button_controller_.reset();
session_state_controller_.reset();
resize_shadow_controller_.reset();
shadow_controller_.reset();
tooltip_controller_.reset();
Expand All @@ -287,6 +285,9 @@ Shell::~Shell() {
user_action_client_.reset();
visibility_controller_.reset();

power_button_controller_.reset();
session_state_controller_.reset();

// This also deletes all RootWindows.
display_controller_.reset();
screen_position_controller_.reset();
Expand Down Expand Up @@ -463,6 +464,14 @@ void Shell::Init() {

CommandLine* command_line = CommandLine::ForCurrentProcess();

if (command_line->HasSwitch(ash::switches::kAshNewLockAnimationsEnabled))
session_state_controller_.reset(new SessionStateControllerImpl2);
else
session_state_controller_.reset(new SessionStateControllerImpl);
power_button_controller_.reset(new PowerButtonController(
session_state_controller_.get()));
AddShellObserver(session_state_controller_.get());

if (command_line->HasSwitch(switches::kAshTouchHud)) {
touch_observer_hud_.reset(new internal::TouchObserverHUD);
AddPreTargetHandler(touch_observer_hud_.get());
Expand Down Expand Up @@ -542,14 +551,6 @@ void Shell::Init() {
// the correct size.
user_wallpaper_delegate_->InitializeWallpaper();

if (command_line->HasSwitch(ash::switches::kAshNewLockAnimationsEnabled))
session_state_controller_.reset(new SessionStateControllerImpl2);
else
session_state_controller_.reset(new SessionStateControllerImpl);
power_button_controller_.reset(new PowerButtonController(
session_state_controller_.get()));
AddShellObserver(session_state_controller_.get());

if (initially_hide_cursor_)
cursor_manager_.ShowCursor(false);
cursor_manager_.SetCursor(ui::kCursorPointer);
Expand Down
15 changes: 15 additions & 0 deletions ash/tooltips/tooltip_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/cursor_manager.h"
#include "ash/wm/session_state_controller.h"
#include "ash/wm/session_state_observer.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/string_split.h"
Expand Down Expand Up @@ -216,11 +218,15 @@ TooltipController::TooltipController(
base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
this, &TooltipController::TooltipTimerFired);
DCHECK(drag_drop_client_);
if (Shell::GetInstance())
Shell::GetInstance()->session_state_controller()->AddObserver(this);
}

TooltipController::~TooltipController() {
if (tooltip_window_)
tooltip_window_->RemoveObserver(this);
if (Shell::GetInstance())
Shell::GetInstance()->session_state_controller()->RemoveObserver(this);
}

void TooltipController::UpdateTooltip(aura::Window* target) {
Expand Down Expand Up @@ -312,6 +318,15 @@ ui::EventResult TooltipController::OnTouchEvent(ui::TouchEvent* event) {
return ui::ER_UNHANDLED;
}

void TooltipController::OnSessionStateEvent(
SessionStateObserver::EventType event) {
if (event == SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED ||
event == SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED) {
if (tooltip_.get() && tooltip_->IsVisible())
tooltip_->Hide();
}
}

void TooltipController::OnWindowDestroyed(aura::Window* window) {
if (tooltip_window_ == window) {
tooltip_window_->RemoveObserver(this);
Expand Down
8 changes: 7 additions & 1 deletion ash/tooltips/tooltip_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ASH_TOOLTIPS_TOOLTIP_CONTROLLER_H_

#include "ash/ash_export.h"
#include "ash/wm/session_state_observer.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/timer.h"
Expand All @@ -32,7 +33,8 @@ namespace internal {
// TooltipController provides tooltip functionality for aura shell.
class ASH_EXPORT TooltipController : public aura::client::TooltipClient,
public ui::EventHandler,
public aura::WindowObserver {
public aura::WindowObserver,
public SessionStateObserver {
public:
explicit TooltipController(aura::client::DragDropClient* drag_drop_client);
virtual ~TooltipController();
Expand All @@ -46,6 +48,10 @@ class ASH_EXPORT TooltipController : public aura::client::TooltipClient,
virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE;

// Overridden from SessionStateController.
virtual void OnSessionStateEvent(SessionStateObserver::EventType event)
OVERRIDE;

// Overridden from aura::WindowObserver.
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;

Expand Down
14 changes: 14 additions & 0 deletions ash/wm/session_state_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@ void SessionStateController::SetDelegate(
SessionStateControllerDelegate* delegate) {
delegate_.reset(delegate);
}

void SessionStateController::AddObserver(SessionStateObserver* observer) {
observers_.AddObserver(observer);
}

void SessionStateController::RemoveObserver(SessionStateObserver* observer) {
observers_.RemoveObserver(observer);
}

bool SessionStateController::HasObserver(SessionStateObserver* observer) {
return observers_.HasObserver(observer);
}


} // namespace ash
8 changes: 8 additions & 0 deletions ash/wm/session_state_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include "ash/ash_export.h"
#include "ash/shell_observer.h"
#include "ash/wm/session_state_animator.h"
#include "ash/wm/session_state_observer.h"
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/time.h"
#include "base/timer.h"
#include "ui/aura/root_window_observer.h"
Expand Down Expand Up @@ -120,13 +122,19 @@ class ASH_EXPORT SessionStateController : public aura::RootWindowObserver,
// Callback is guaranteed to be called once and then discarded.
virtual void SetLockScreenDisplayedCallback(base::Closure& callback) = 0;

virtual void AddObserver(SessionStateObserver* observer);
virtual void RemoveObserver(SessionStateObserver* observer);
virtual bool HasObserver(SessionStateObserver* observer);

protected:
friend class test::PowerButtonControllerTest;

scoped_ptr<internal::SessionStateAnimator> animator_;

scoped_ptr<SessionStateControllerDelegate> delegate_;

ObserverList<SessionStateObserver> observers_;

private:
DISALLOW_COPY_AND_ASSIGN(SessionStateController);
};
Expand Down
11 changes: 11 additions & 0 deletions ash/wm/session_state_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ void SessionStateControllerImpl::OnLockStateChanged(bool locked) {
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_FADE_IN,
internal::SessionStateAnimator::ANIMATION_SPEED_SHOW_LOCK_SCREEN);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
lock_timer_.Stop();
lock_fail_timer_.Stop();

Expand Down Expand Up @@ -102,6 +105,9 @@ void SessionStateControllerImpl::OnStartingLock() {
internal::SessionStateAnimator::ANIMATION_FULL_CLOSE,
internal::SessionStateAnimator::ANIMATION_SPEED_FAST);

FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));

// Hide the screen locker containers so we can make them fade in later.
animator_->StartAnimation(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
Expand All @@ -114,6 +120,8 @@ void SessionStateControllerImpl::StartLockAnimationAndLockImmediately() {
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
OnLockTimeout();
}

Expand All @@ -124,6 +132,9 @@ void SessionStateControllerImpl::StartLockAnimation(bool shutdown_after_lock) {
internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED));
StartLockTimer();
}

Expand Down
11 changes: 10 additions & 1 deletion ash/wm/session_state_controller_impl2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ void SessionStateControllerImpl2::SetLockScreenDisplayedCallback(
}

void SessionStateControllerImpl2::OnLockScreenAnimationFinished() {
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_LOCK_ANIMATION_FINISHED));
if (!lock_screen_displayed_callback_.is_null()) {
lock_screen_displayed_callback_.Run();
lock_screen_displayed_callback_.Reset();
Expand All @@ -112,7 +115,8 @@ void SessionStateControllerImpl2::OnStartingLock() {
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);

FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
// Hide the screen locker containers so we can raise them later.
animator_->StartAnimation(
internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
Expand All @@ -126,6 +130,8 @@ void SessionStateControllerImpl2::StartLockAnimationAndLockImmediately() {
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(SessionStateObserver::EVENT_LOCK_ANIMATION_STARTED));
OnLockTimeout();
}

Expand All @@ -137,6 +143,9 @@ void SessionStateControllerImpl2::StartLockAnimation(bool shutdown_after_lock) {
internal::SessionStateAnimator::LAUNCHER,
internal::SessionStateAnimator::ANIMATION_LIFT,
internal::SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
FOR_EACH_OBSERVER(SessionStateObserver, observers_,
OnSessionStateEvent(
SessionStateObserver::EVENT_PRELOCK_ANIMATION_STARTED));
StartLockTimer();
}

Expand Down
28 changes: 28 additions & 0 deletions ash/wm/session_state_observer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2012 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_WM_SESSION_STATE_OBSERVER_H_
#define ASH_WM_SESSION_STATE_OBSERVER_H_

#include "ash/ash_export.h"

namespace ash {

// Interface for classes that want to be notified by SessionStateController when
// session-related events occur.
class ASH_EXPORT SessionStateObserver {
public:
enum EventType {
EVENT_PRELOCK_ANIMATION_STARTED,
EVENT_LOCK_ANIMATION_STARTED,
EVENT_LOCK_ANIMATION_FINISHED,
};

virtual void OnSessionStateEvent(EventType event) = 0;
virtual ~SessionStateObserver() {};
};

} // namespace ash

#endif // ASH_WM_SESSION_STATE_CONTROLLER_H_
11 changes: 0 additions & 11 deletions chrome/browser/chromeos/login/screen_locker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ void ScreenLocker::Init() {
authenticator_ = LoginUtils::Get()->CreateAuthenticator(this);
delegate_.reset(new WebUIScreenLocker(this));
delegate_->LockScreen(unlock_on_input_);
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(ash::switches::kAshNewLockAnimationsEnabled)) {
base::Closure callback = base::Bind(&ScreenLocker::OnFullyDisplayedCallback,
weak_factory_.GetWeakPtr());
ash::Shell::GetInstance()->session_state_controller()->
SetLockScreenDisplayedCallback(callback);
}
}

void ScreenLocker::OnLoginFailure(const LoginFailure& error) {
Expand Down Expand Up @@ -429,10 +422,6 @@ void ScreenLocker::ScreenLockReady() {
DBusThreadManager::Get()->GetSessionManagerClient()->NotifyLockScreenShown();
}

void ScreenLocker::OnFullyDisplayedCallback() {
delegate_->ProcessFullyDisplayedAnimations();
}

content::WebUI* ScreenLocker::GetAssociatedWebUI() {
return delegate_->GetAssociatedWebUI();
}
Expand Down
Loading

0 comments on commit 83482fb

Please sign in to comment.