diff options
-rw-r--r-- | ash/accelerators/accelerator_controller.cc | 15 | ||||
-rw-r--r-- | ash/accelerators/accelerator_table.cc | 2 | ||||
-rw-r--r-- | ash/accelerators/accelerator_table.h | 1 | ||||
-rw-r--r-- | ash/session_state_delegate.h | 4 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.cc | 3 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.h | 1 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.cc | 4 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_chromeos.cc | 42 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_chromeos.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_views.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_views.h | 1 |
12 files changed, 76 insertions, 3 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 135e0f7..deacdbf 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -68,6 +68,7 @@ #include "ui/views/widget/widget.h" #if defined(OS_CHROMEOS) +#include "ash/session_state_delegate.h" #include "ash/system/chromeos/keyboard_brightness_controller.h" #include "base/chromeos/chromeos_version.h" #endif // defined(OS_CHROMEOS) @@ -188,6 +189,18 @@ bool HandleToggleSpokenFeedback() { return true; } +bool SwitchToNextUser() { + if (!Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() || + !ash::switches::ShowMultiProfileShelfMenu()) + return false; + ash::SessionStateDelegate* delegate = + ash::Shell::GetInstance()->session_state_delegate(); + if (delegate->NumberOfLoggedInUsers() <= 1) + return false; + delegate->SwitchActiveUserToNext(); + return true; +} + #endif // defined(OS_CHROMEOS) bool HandleRotatePaneFocus(Shell::Direction direction) { @@ -570,6 +583,8 @@ bool AcceleratorController::PerformAction(int action, case SWAP_PRIMARY_DISPLAY: Shell::GetInstance()->display_controller()->SwapPrimaryDisplay(); return true; + case SWITCH_TO_NEXT_USER: + return SwitchToNextUser(); case TOGGLE_SPOKEN_FEEDBACK: return HandleToggleSpokenFeedback(); case TOGGLE_WIFI: diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc index bdf23fb..5e23d79 100644 --- a/ash/accelerators/accelerator_table.cc +++ b/ash/accelerators/accelerator_table.cc @@ -82,6 +82,8 @@ const AcceleratorData kAcceleratorData[] = { { true, ui::VKEY_Z, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, TOGGLE_SPOKEN_FEEDBACK }, { true, ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN, SILENCE_SPOKEN_FEEDBACK}, + { true, ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, + SWITCH_TO_NEXT_USER }, #endif // defined(OS_CHROMEOS) { true, ui::VKEY_I, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, OPEN_FEEDBACK_PAGE }, #if !defined(OS_WIN) diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h index 7d23adf..d1e22a8 100644 --- a/ash/accelerators/accelerator_table.h +++ b/ash/accelerators/accelerator_table.h @@ -130,6 +130,7 @@ enum AcceleratorAction { OPEN_CROSH, OPEN_FILE_DIALOG, // Open 'Open file' dialog. OPEN_FILE_MANAGER, + SWITCH_TO_NEXT_USER, #endif }; diff --git a/ash/session_state_delegate.h b/ash/session_state_delegate.h index 9ca213c..f8219bd 100644 --- a/ash/session_state_delegate.h +++ b/ash/session_state_delegate.h @@ -81,6 +81,10 @@ class ASH_EXPORT SessionStateDelegate { // (if that user has already signed in). virtual void SwitchActiveUser(const std::string& user_email) = 0; + // Switches the active user to the next user, with the same ordering as + // GetLoggedInUsers. + virtual void SwitchActiveUserToNext() = 0; + // Adds or removes sessions state observer. virtual void AddSessionStateObserver(SessionStateObserver* observer) = 0; virtual void RemoveSessionStateObserver(SessionStateObserver* observer) = 0; diff --git a/ash/session_state_delegate_stub.cc b/ash/session_state_delegate_stub.cc index 31f7345..587d61f 100644 --- a/ash/session_state_delegate_stub.cc +++ b/ash/session_state_delegate_stub.cc @@ -73,6 +73,9 @@ void SessionStateDelegateStub::GetLoggedInUsers(UserIdList* users) { void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { } +void SessionStateDelegateStub::SwitchActiveUserToNext() { +} + void SessionStateDelegateStub::AddSessionStateObserver( ash::SessionStateObserver* observer) { } diff --git a/ash/session_state_delegate_stub.h b/ash/session_state_delegate_stub.h index 1843383..afd63dd 100644 --- a/ash/session_state_delegate_stub.h +++ b/ash/session_state_delegate_stub.h @@ -35,6 +35,7 @@ class SessionStateDelegateStub : public SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; + virtual void SwitchActiveUserToNext() OVERRIDE; virtual void AddSessionStateObserver( ash::SessionStateObserver* observer) OVERRIDE; virtual void RemoveSessionStateObserver( diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc index f7812d7..d61bb85 100644 --- a/ash/test/test_session_state_delegate.cc +++ b/ash/test/test_session_state_delegate.cc @@ -114,6 +114,10 @@ void TestSessionStateDelegate::SwitchActiveUser(const std::string& email) { activated_user_ = email; } +void TestSessionStateDelegate::SwitchActiveUserToNext() { + activated_user_ = "someone@tray"; +} + void TestSessionStateDelegate::AddSessionStateObserver( SessionStateObserver* observer) { } diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h index 520c634..40ba70d 100644 --- a/ash/test/test_session_state_delegate.h +++ b/ash/test/test_session_state_delegate.h @@ -38,6 +38,7 @@ class TestSessionStateDelegate : public SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; virtual void SwitchActiveUser(const std::string& email) OVERRIDE; + virtual void SwitchActiveUserToNext() OVERRIDE; virtual void AddSessionStateObserver( ash::SessionStateObserver* observer) OVERRIDE; virtual void RemoveSessionStateObserver( diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc index 62327f3..f95c40f 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc @@ -98,9 +98,45 @@ void SessionStateDelegateChromeos::GetLoggedInUsers(ash::UserIdList* users) { void SessionStateDelegateChromeos::SwitchActiveUser( const std::string& user_email) { - // The user_id can be a display email which might be capitalized and has dots. - chromeos::UserManager::Get()->SwitchActiveUser( - gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email))); + // Disallow switching to an already active user since that might crash. + // Transform the |user_email| into a |user_id| for comparison & switching. + std::string user_id = + gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email)); + if (user_id == chromeos::UserManager::Get()->GetActiveUser()->email()) + return; + chromeos::UserManager::Get()->SwitchActiveUser(user_id); +} + +void SessionStateDelegateChromeos::SwitchActiveUserToNext() { + // Make sure there is a user to switch to. + if (NumberOfLoggedInUsers() <= 1) + return; + + const chromeos::UserList& logged_in_users = + chromeos::UserManager::Get()->GetLoggedInUsers(); + + std::string user_id = chromeos::UserManager::Get()->GetActiveUser()->email(); + + // Get an iterator positioned at the active user. + chromeos::UserList::const_iterator it; + for (it = logged_in_users.begin(); + it != logged_in_users.end(); ++it) { + if ((*it)->email() == user_id) + break; + } + + // Active user not found. + if (it == logged_in_users.end()) + return; + + // Get the next user's email, wrapping to the start of the list if necessary. + if (++it == logged_in_users.end()) + user_id = (*logged_in_users.begin())->email(); + else + user_id = (*it)->email(); + + // Switch using the transformed |user_id|. + chromeos::UserManager::Get()->SwitchActiveUser(user_id); } void SessionStateDelegateChromeos::AddSessionStateObserver( diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.h b/chrome/browser/ui/ash/session_state_delegate_chromeos.h index 344b561..56fd9c3 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.h +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.h @@ -39,6 +39,7 @@ class SessionStateDelegateChromeos ash::MultiProfileIndex index) const OVERRIDE; virtual void GetLoggedInUsers(ash::UserIdList* users) OVERRIDE; virtual void SwitchActiveUser(const std::string& user_email) OVERRIDE; + virtual void SwitchActiveUserToNext() OVERRIDE; virtual void AddSessionStateObserver( ash::SessionStateObserver* observer) OVERRIDE; virtual void RemoveSessionStateObserver( diff --git a/chrome/browser/ui/ash/session_state_delegate_views.cc b/chrome/browser/ui/ash/session_state_delegate_views.cc index 933b2f3..499b3f9 100644 --- a/chrome/browser/ui/ash/session_state_delegate_views.cc +++ b/chrome/browser/ui/ash/session_state_delegate_views.cc @@ -77,6 +77,10 @@ void SessionStateDelegate::SwitchActiveUser(const std::string& user_email) { NOTIMPLEMENTED(); } +void SessionStateDelegate::SwitchActiveUserToNext() { + NOTIMPLEMENTED(); +} + void SessionStateDelegate::AddSessionStateObserver( ash::SessionStateObserver* observer) { NOTIMPLEMENTED(); diff --git a/chrome/browser/ui/ash/session_state_delegate_views.h b/chrome/browser/ui/ash/session_state_delegate_views.h index d209e2a..d8e5441 100644 --- a/chrome/browser/ui/ash/session_state_delegate_views.h +++ b/chrome/browser/ui/ash/session_state_delegate_views.h @@ -36,6 +36,7 @@ class SessionStateDelegate : public ash::SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual void GetLoggedInUsers(ash::UserIdList* users) OVERRIDE; virtual void SwitchActiveUser(const std::string& user_email) OVERRIDE; + virtual void SwitchActiveUserToNext() OVERRIDE; virtual void AddSessionStateObserver( ash::SessionStateObserver* observer) OVERRIDE; virtual void RemoveSessionStateObserver( |