diff options
30 files changed, 265 insertions, 77 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index d0ad39c..f998d90 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -173,6 +173,7 @@ 'screensaver/screensaver_view.h', 'screenshot_delegate.h', 'session_state_delegate.h', + 'session_state_observer.h', 'shelf/background_animator.cc', 'shelf/background_animator.h', 'shelf/shelf_layout_manager.cc', diff --git a/ash/session_state_delegate.h b/ash/session_state_delegate.h index f5451cf..2688c18 100644 --- a/ash/session_state_delegate.h +++ b/ash/session_state_delegate.h @@ -17,12 +17,14 @@ class ImageSkia; namespace ash { +class SessionStateObserver; + // The index for the multi-profile item to use. The list is always LRU sorted // So that the index #0 is the currently active user. typedef int MultiProfileIndex; -// A list of email addresses. -typedef std::vector<std::string> UserEmailList; +// A list of user_id. +typedef std::vector<std::string> UserIdList; // Delegate for checking and modifying the session state. class ASH_EXPORT SessionStateDelegate { @@ -68,10 +70,14 @@ class ASH_EXPORT SessionStateDelegate { virtual const gfx::ImageSkia& GetUserImage(MultiProfileIndex index) const = 0; // Returns a list of all logged in users. - virtual void GetLoggedInUsers(UserEmailList* users) = 0; + virtual void GetLoggedInUsers(UserIdList* users) = 0; // Switches to another active user (if that user has already signed in). - virtual void SwitchActiveUser(const std::string& email) = 0; + virtual void SwitchActiveUser(const std::string& user_id) = 0; + + // Adds or removes sessions state observer. + virtual void AddSessionStateObserver(SessionStateObserver* observer) = 0; + virtual void RemoveSessionStateObserver(SessionStateObserver* observer) = 0; }; } // namespace ash diff --git a/ash/session_state_delegate_stub.cc b/ash/session_state_delegate_stub.cc index 86ce366..5e610d7 100644 --- a/ash/session_state_delegate_stub.cc +++ b/ash/session_state_delegate_stub.cc @@ -63,11 +63,18 @@ const gfx::ImageSkia& SessionStateDelegateStub::GetUserImage( return null_image_; } -void SessionStateDelegateStub::GetLoggedInUsers( - UserEmailList* users) { +void SessionStateDelegateStub::GetLoggedInUsers(UserIdList* users) { } -void SessionStateDelegateStub::SwitchActiveUser(const std::string& email) { +void SessionStateDelegateStub::SwitchActiveUser(const std::string& user_id) { +} + +void SessionStateDelegateStub::AddSessionStateObserver( + ash::SessionStateObserver* observer) { +} + +void SessionStateDelegateStub::RemoveSessionStateObserver( + ash::SessionStateObserver* observer) { } } // namespace ash diff --git a/ash/session_state_delegate_stub.h b/ash/session_state_delegate_stub.h index 707c53e..81d372f 100644 --- a/ash/session_state_delegate_stub.h +++ b/ash/session_state_delegate_stub.h @@ -32,8 +32,12 @@ class SessionStateDelegateStub : public SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual const gfx::ImageSkia& GetUserImage( ash::MultiProfileIndex index) const OVERRIDE; - virtual void GetLoggedInUsers(UserEmailList* users) OVERRIDE; - virtual void SwitchActiveUser(const std::string& email) OVERRIDE; + virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; + virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; + virtual void AddSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; + virtual void RemoveSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; private: bool screen_locked_; diff --git a/ash/session_state_observer.h b/ash/session_state_observer.h new file mode 100644 index 0000000..f4fad9d --- /dev/null +++ b/ash/session_state_observer.h @@ -0,0 +1,25 @@ +// 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_OBSERVER_H_ +#define ASH_SESSION_STATE_OBSERVER_H_ + +#include <string> + +#include "ash/ash_export.h" + +namespace ash { + +class ASH_EXPORT SessionStateObserver { + public: + // Called when active user has changed. + virtual void ActiveUserChanged(const std::string& user_id) {} + + protected: + virtual ~SessionStateObserver() {} +}; + +} // namespace ash + +#endif // ASH_SESSION_STATE_OBSERVER_H_ diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc index d6e6f28..b8ae5db 100644 --- a/ash/shelf/shelf_layout_manager_unittest.cc +++ b/ash/shelf/shelf_layout_manager_unittest.cc @@ -1246,7 +1246,7 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureRevealsTrayBubble) { generator.GestureScrollSequence(start, end, base::TimeDelta::FromMilliseconds(10), 1); EXPECT_TRUE(tray->HasSystemBubble()); - tray->CloseSystemBubbleForTest(); + tray->CloseSystemBubble(); RunAllPendingInMessageLoop(); EXPECT_FALSE(tray->HasSystemBubble()); @@ -1413,7 +1413,7 @@ TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { EXPECT_TRUE(shelf->IsVisible()); if (!i) { // In our first iteration we make sure there is no bubble. - tray->CloseSystemBubbleForTest(); + tray->CloseSystemBubble(); EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); } else { // In our second iteration we show a bubble. diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index 4602271..e4caaad 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -321,7 +321,7 @@ bool SystemTray::IsMouseInNotificationBubble() const { Shell::GetScreen()->GetCursorScreenPoint()); } -bool SystemTray::CloseSystemBubbleForTest() const { +bool SystemTray::CloseSystemBubble() const { if (!system_bubble_) return false; system_bubble_->bubble()->Close(); diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index 48875fd..1a6b6fa 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -124,10 +124,12 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // Returns true if the mouse is inside the notification bubble. bool IsMouseInNotificationBubble() const; + // Closes system bubble and returns true if it did exist. + bool CloseSystemBubble() const; + // Accessors for testing. // Returns true if the bubble exists. - bool CloseSystemBubbleForTest() const; bool CloseNotificationBubbleForTest() const; // Overridden from TrayBackgroundView. diff --git a/ash/system/tray/system_tray_unittest.cc b/ash/system/tray/system_tray_unittest.cc index 5af8742b..6d36329 100644 --- a/ash/system/tray/system_tray_unittest.cc +++ b/ash/system/tray/system_tray_unittest.cc @@ -142,9 +142,9 @@ TEST_F(SystemTrayTest, SystemTrayDefaultView) { tray->ShowDefaultView(BUBBLE_CREATE_NEW); // Ensure that closing the bubble destroys it. - ASSERT_TRUE(tray->CloseSystemBubbleForTest()); + ASSERT_TRUE(tray->CloseSystemBubble()); RunAllPendingInMessageLoop(); - ASSERT_FALSE(tray->CloseSystemBubbleForTest()); + ASSERT_FALSE(tray->CloseSystemBubble()); } TEST_F(SystemTrayTest, SystemTrayTestItems) { @@ -247,8 +247,8 @@ TEST_F(SystemTrayTest, SystemTrayNotifications) { ASSERT_TRUE(detailed_item->detailed_view() != NULL); ASSERT_TRUE(test_item->notification_view() != NULL); - // Hide the detailed view, ensure the notificaiton view still exists. - ASSERT_TRUE(tray->CloseSystemBubbleForTest()); + // Hide the detailed view, ensure the notification view still exists. + ASSERT_TRUE(tray->CloseSystemBubble()); RunAllPendingInMessageLoop(); ASSERT_TRUE(detailed_item->detailed_view() == NULL); ASSERT_TRUE(test_item->notification_view() != NULL); diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index e3c0697..965a248 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -273,6 +273,9 @@ class UserView : public views::View, // The view of the user card. views::View* user_card_view_; + // This is the owner system tray item of this view. + SystemTrayItem* owner_; + // True if |user_card_view_| is a |UserView| - otherwise it is only a // |views::View|. bool is_user_card_; @@ -595,6 +598,7 @@ UserView::UserView(SystemTrayItem* owner, MultiProfileIndex index) : multiprofile_index_(index), user_card_view_(NULL), + owner_(owner), is_user_card_(false), logout_button_(NULL), add_user_visible_but_disabled_(false) { @@ -710,6 +714,9 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { ash::SessionStateDelegate* delegate = ash::Shell::GetInstance()->session_state_delegate(); delegate->SwitchActiveUser(delegate->GetUserEmail(multiprofile_index_)); + // Since the user list is about to change the system menu should get + // closed. + owner_->system_tray()->CloseSystemBubble(); } } else if (add_menu_option_.get() && sender == add_menu_option_->GetContentsView()) { diff --git a/ash/system/user/tray_user_unittest.cc b/ash/system/user/tray_user_unittest.cc index b2f8a43..7d7b066 100644 --- a/ash/system/user/tray_user_unittest.cc +++ b/ash/system/user/tray_user_unittest.cc @@ -140,7 +140,7 @@ TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { ash::internal::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); - tray()->CloseSystemBubbleForTest(); + tray()->CloseSystemBubble(); } // Make sure that in multi user mode the user panel can be activated and there @@ -207,7 +207,7 @@ TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) { tray_user(0)->GetStateForTest()); // Close and check that everything is deleted. - tray()->CloseSystemBubbleForTest(); + tray()->CloseSystemBubble(); EXPECT_FALSE(tray()->IsAnyBubbleVisible()); for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) EXPECT_EQ(ash::internal::TrayUser::HIDDEN, @@ -226,7 +226,7 @@ TEST_F(TrayUserTest, MutiUserModeButtonClicks) { ClickUserItem(&generator, 1); EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserEmail(1)); - tray()->CloseSystemBubbleForTest(); + tray()->CloseSystemBubble(); } } // namespace internal diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc index 22fdfac..1fdfef6 100644 --- a/ash/test/test_session_state_delegate.cc +++ b/ash/test/test_session_state_delegate.cc @@ -88,13 +88,20 @@ const gfx::ImageSkia& TestSessionStateDelegate::GetUserImage( return null_image_; } -void TestSessionStateDelegate::GetLoggedInUsers(UserEmailList* users) { +void TestSessionStateDelegate::GetLoggedInUsers(UserIdList* users) { } void TestSessionStateDelegate::SwitchActiveUser(const std::string& email) { activated_user_ = email; } +void TestSessionStateDelegate::AddSessionStateObserver( + ash::SessionStateObserver* observer) { +} + +void TestSessionStateDelegate::RemoveSessionStateObserver( + ash::SessionStateObserver* observer) { +} } // namespace test } // namespace ash diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h index 83944d4..17062d5 100644 --- a/ash/test/test_session_state_delegate.h +++ b/ash/test/test_session_state_delegate.h @@ -35,8 +35,12 @@ class TestSessionStateDelegate : public SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual const gfx::ImageSkia& GetUserImage( ash::MultiProfileIndex index) const OVERRIDE; - virtual void GetLoggedInUsers(UserEmailList* users) OVERRIDE; + virtual void GetLoggedInUsers(UserIdList* users) OVERRIDE; virtual void SwitchActiveUser(const std::string& email) OVERRIDE; + virtual void AddSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; + virtual void RemoveSessionStateObserver( + ash::SessionStateObserver* observer) 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|, diff --git a/chrome/browser/chromeos/login/crash_restore_browsertest.cc b/chrome/browser/chromeos/login/crash_restore_browsertest.cc index 5f2fb19..60002af 100644 --- a/chrome/browser/chromeos/login/crash_restore_browsertest.cc +++ b/chrome/browser/chromeos/login/crash_restore_browsertest.cc @@ -80,8 +80,6 @@ class UserSessionRestoreObserver : } virtual ~UserSessionRestoreObserver() {} - virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE { - } virtual void PendingUserSessionsRestoreFinished() OVERRIDE { user_sessions_restored_ = true; UserManager::Get()->RemoveSessionStateObserver(this); diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc index 8c6dbab..dee8454 100644 --- a/chrome/browser/chromeos/login/user_manager.cc +++ b/chrome/browser/chromeos/login/user_manager.cc @@ -28,6 +28,18 @@ static UserManager* g_user_manager = NULL; UserManager::Observer::~Observer() { } +void UserManager::UserSessionStateObserver::ActiveUserChanged( + const User* active_user) { +} + +void UserManager::UserSessionStateObserver::ActiveUserHashChanged( + const std::string& hash) { +} + +void UserManager::UserSessionStateObserver:: +PendingUserSessionsRestoreFinished() { +} + UserManager::UserSessionStateObserver::~UserSessionStateObserver() { } diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h index 059d888..3a23115 100644 --- a/chrome/browser/chromeos/login/user_manager.h +++ b/chrome/browser/chromeos/login/user_manager.h @@ -46,15 +46,20 @@ class UserManager { virtual ~Observer(); }; - // TODO(nkostylev): Merge with session state refactoring CL. + // TODO(nkostylev): Refactor and move this observer out of UserManager. + // Observer interface that defines methods used to notify on user session / + // active user state changes. Default implementation is empty. class UserSessionStateObserver { public: + // Called when active user has changed. + virtual void ActiveUserChanged(const User* active_user); + // Called right before notifying on user change so that those who rely // on user_id hash would be accessing up-to-date value. - virtual void ActiveUserHashChanged(const std::string& hash) = 0; + virtual void ActiveUserHashChanged(const std::string& hash); // Called when UserManager finishes restoring user sessions after crash. - virtual void PendingUserSessionsRestoreFinished() = 0; + virtual void PendingUserSessionsRestoreFinished(); protected: virtual ~UserSessionStateObserver(); diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc index 82b48df..d5fd7d9 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.cc +++ b/chrome/browser/chromeos/login/user_manager_impl.cc @@ -369,13 +369,7 @@ void UserManagerImpl::SwitchActiveUser(const std::string& email) { SetLRUUser(active_user_); NotifyActiveUserHashChanged(active_user_->username_hash()); - - // TODO(nkostylev): Notify session_manager on active user change. - // http://crbug.com/230857 - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_ACTIVE_USER_CHANGED, - content::Source<UserManager>(this), - content::Details<const User>(active_user_)); + NotifyActiveUserChanged(active_user_); } void UserManagerImpl::RestoreActiveSessions() { @@ -1254,8 +1248,11 @@ void UserManagerImpl::RetailModeUserLoggedIn() { void UserManagerImpl::NotifyOnLogin() { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); NotifyActiveUserHashChanged(active_user_->username_hash()); + NotifyActiveUserChanged(active_user_); UpdateLoginState(); + // TODO(nkostylev): Deprecate this notification in favor of + // ActiveUserChanged() observer call. content::NotificationService::current()->Notify( chrome::NOTIFICATION_LOGIN_USER_CHANGED, content::Source<UserManager>(this), @@ -1604,6 +1601,13 @@ void UserManagerImpl::NotifyMergeSessionStateChanged() { MergeSessionStateChanged(merge_session_state_)); } +void UserManagerImpl::NotifyActiveUserChanged(const User* active_user) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, + session_state_observer_list_, + ActiveUserChanged(active_user)); +} + void UserManagerImpl::NotifyActiveUserHashChanged(const std::string& hash) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, diff --git a/chrome/browser/chromeos/login/user_manager_impl.h b/chrome/browser/chromeos/login/user_manager_impl.h index 510eee9..63be822 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.h +++ b/chrome/browser/chromeos/login/user_manager_impl.h @@ -262,6 +262,9 @@ class UserManagerImpl // Notifies observers that merge session state had changed. void NotifyMergeSessionStateChanged(); + // Notifies observers that active user has changed. + void NotifyActiveUserChanged(const User* active_user); + // Notifies observers that active user_id hash has changed. void NotifyActiveUserHashChanged(const std::string& hash); diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc index 9d9e98c..7fc8553 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.cc +++ b/chrome/browser/chromeos/profiles/profile_helper.cc @@ -144,7 +144,4 @@ void ProfileHelper::ActiveUserHashChanged(const std::string& hash) { LOG(INFO) << "Switching to profile path: " << profile_path.value(); } -void ProfileHelper::PendingUserSessionsRestoreFinished() { -} - } // namespace chromeos diff --git a/chrome/browser/chromeos/profiles/profile_helper.h b/chrome/browser/chromeos/profiles/profile_helper.h index dedf7da..3f500d2e 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.h +++ b/chrome/browser/chromeos/profiles/profile_helper.h @@ -77,7 +77,6 @@ class ProfileHelper : public BrowsingDataRemover::Observer, // UserManager::UserSessionStateObserver implementation: virtual void ActiveUserHashChanged(const std::string& hash) OVERRIDE; - virtual void PendingUserSessionsRestoreFinished() OVERRIDE; // BrowsingDataRemover::Observer implementation: virtual void OnBrowsingDataRemoverDone() OVERRIDE; diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index 0f2c5d40..e2ef3a9 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -11,6 +11,8 @@ #include "ash/ash_switches.h" #include "ash/desktop_background/desktop_background_controller.h" +#include "ash/session_state_delegate.h" +#include "ash/session_state_observer.h" #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" @@ -235,7 +237,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, public device::BluetoothAdapter::Observer, public SystemKeyEventListener::CapsLockObserver, public ash::NetworkTrayDelegate, - public policy::CloudPolicyStore::Observer { + public policy::CloudPolicyStore::Observer, + public ash::SessionStateObserver { public: SystemTrayDelegate() : ui_weak_ptr_factory_( @@ -309,6 +312,9 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, device::BluetoothAdapterFactory::GetAdapter( base::Bind(&SystemTrayDelegate::InitializeOnAdapterReady, ui_weak_ptr_factory_->GetWeakPtr())); + + ash::Shell::GetInstance()->session_state_delegate()-> + AddSessionStateObserver(this); } virtual void Shutdown() OVERRIDE { @@ -368,6 +374,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, if (SystemKeyEventListener::GetInstance()) SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); bluetooth_adapter_->RemoveObserver(this); + ash::Shell::GetInstance()->session_state_delegate()-> + RemoveSessionStateObserver(this); // Stop observing gdata operations. DriveIntegrationService* integration_service = @@ -1273,6 +1281,11 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, UpdateEnterpriseDomain(); } + // Overridden from ash::SessionStateObserver + virtual void ActiveUserChanged(const std::string& user_id) OVERRIDE { + GetSystemTrayNotifier()->NotifyUserUpdate(); + } + void UpdateCellular() { const CellularNetworkVector& cellular_networks = CrosLibrary::Get()->GetNetworkLibrary()->cellular_networks(); diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index dbfa165..1741639 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -29,7 +29,6 @@ #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" -#include "chrome/browser/ui/ash/session_state_delegate.h" #include "chrome/browser/ui/ash/user_action_handler.h" #include "chrome/browser/ui/ash/window_positioner.h" #include "chrome/browser/ui/browser.h" @@ -259,10 +258,6 @@ ash::LauncherDelegate* ChromeShellDelegate::CreateLauncherDelegate( return launcher_delegate_; } -ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() { - return new SessionStateDelegate; -} - aura::client::UserActionClient* ChromeShellDelegate::CreateUserActionClient() { return new UserActionHandler; } diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc index 753cb86..7d1ec86 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate_chromeos.cc @@ -24,6 +24,7 @@ #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/speech/tts_controller.h" #include "chrome/browser/ui/ash/caps_lock_delegate_chromeos.h" +#include "chrome/browser/ui/ash/session_state_delegate_chromeos.h" #include "chrome/browser/ui/ash/window_positioner.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" @@ -186,6 +187,10 @@ ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() { return new CapsLockDelegate(xkeyboard); } +ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() { + return new SessionStateDelegateChromeos; +} + void ChromeShellDelegate::ShowKeyboardOverlay() { // TODO(mazda): Move the show logic to ash (http://crbug.com/124222). Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc index bdc86ff..2e07206 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc @@ -9,6 +9,7 @@ #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/ash/caps_lock_delegate_views.h" +#include "chrome/browser/ui/ash/session_state_delegate_views.h" #include "chrome/browser/ui/ash/window_positioner.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" @@ -75,6 +76,10 @@ ash::CapsLockDelegate* ChromeShellDelegate::CreateCapsLockDelegate() { return new CapsLockDelegate(); } +ash::SessionStateDelegate* ChromeShellDelegate::CreateSessionStateDelegate() { + return new SessionStateDelegate; +} + void ChromeShellDelegate::SaveScreenMagnifierScale(double scale) { } diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc index c9bb73e..a44c892 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc @@ -2,42 +2,45 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/ash/session_state_delegate.h" +#include "chrome/browser/ui/ash/session_state_delegate_chromeos.h" +#include "ash/session_state_observer.h" #include "base/logging.h" #include "chrome/browser/chromeos/login/screen_locker.h" +#include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/session_manager_client.h" -SessionStateDelegate::SessionStateDelegate() { +SessionStateDelegateChromeos::SessionStateDelegateChromeos() { + chromeos::UserManager::Get()->AddSessionStateObserver(this); } -SessionStateDelegate::~SessionStateDelegate() { +SessionStateDelegateChromeos::~SessionStateDelegateChromeos() { } -int SessionStateDelegate::GetMaximumNumberOfLoggedInUsers() const { +int SessionStateDelegateChromeos::GetMaximumNumberOfLoggedInUsers() const { return 3; } -int SessionStateDelegate::NumberOfLoggedInUsers() const { +int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const { return chromeos::UserManager::Get()->GetLoggedInUsers().size(); } -bool SessionStateDelegate::IsActiveUserSessionStarted() const { +bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const { return chromeos::UserManager::Get()->IsSessionStarted(); } -bool SessionStateDelegate::CanLockScreen() const { +bool SessionStateDelegateChromeos::CanLockScreen() const { return chromeos::UserManager::Get()->CanCurrentUserLock(); } -bool SessionStateDelegate::IsScreenLocked() const { +bool SessionStateDelegateChromeos::IsScreenLocked() const { return chromeos::ScreenLocker::default_screen_locker() && chromeos::ScreenLocker::default_screen_locker()->locked(); } -void SessionStateDelegate::LockScreen() { +void SessionStateDelegateChromeos::LockScreen() { if (!CanLockScreen()) return; @@ -47,33 +50,32 @@ void SessionStateDelegate::LockScreen() { RequestLockScreen(); } -void SessionStateDelegate::UnlockScreen() { +void SessionStateDelegateChromeos::UnlockScreen() { // This is used only for testing thus far. NOTIMPLEMENTED(); } -const base::string16 SessionStateDelegate::GetUserDisplayName( +const base::string16 SessionStateDelegateChromeos::GetUserDisplayName( ash::MultiProfileIndex index) const { DCHECK_LT(index, NumberOfLoggedInUsers()); return chromeos::UserManager::Get()-> GetLRULoggedInUsers()[index]->display_name(); } -const std::string SessionStateDelegate::GetUserEmail( +const std::string SessionStateDelegateChromeos::GetUserEmail( ash::MultiProfileIndex index) const { DCHECK_LT(index, NumberOfLoggedInUsers()); return chromeos::UserManager::Get()-> GetLRULoggedInUsers()[index]->display_email(); } -const gfx::ImageSkia& SessionStateDelegate::GetUserImage( +const gfx::ImageSkia& SessionStateDelegateChromeos::GetUserImage( ash::MultiProfileIndex index) const { DCHECK_LT(index, NumberOfLoggedInUsers()); return chromeos::UserManager::Get()->GetLRULoggedInUsers()[index]->image(); } -void SessionStateDelegate::GetLoggedInUsers( - ash::UserEmailList* users) { +void SessionStateDelegateChromeos::GetLoggedInUsers(ash::UserIdList* users) { const chromeos::UserList& logged_in_users = chromeos::UserManager::Get()->GetLoggedInUsers(); for (chromeos::UserList::const_iterator it = logged_in_users.begin(); @@ -83,6 +85,24 @@ void SessionStateDelegate::GetLoggedInUsers( } } -void SessionStateDelegate::SwitchActiveUser(const std::string& email) { - chromeos::UserManager::Get()->SwitchActiveUser(email); +void SessionStateDelegateChromeos::SwitchActiveUser( + const std::string& user_id) { + chromeos::UserManager::Get()->SwitchActiveUser(user_id); +} + +void SessionStateDelegateChromeos::AddSessionStateObserver( + ash::SessionStateObserver* observer) { + session_state_observer_list_.AddObserver(observer); +} + +void SessionStateDelegateChromeos::RemoveSessionStateObserver( + ash::SessionStateObserver* observer) { + session_state_observer_list_.RemoveObserver(observer); +} + +void SessionStateDelegateChromeos::ActiveUserChanged( + const chromeos::User* active_user) { + FOR_EACH_OBSERVER(ash::SessionStateObserver, + session_state_observer_list_, + ActiveUserChanged(active_user->email())); } diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.h b/chrome/browser/ui/ash/session_state_delegate_chromeos.h new file mode 100644 index 0000000..025713f --- /dev/null +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.h @@ -0,0 +1,56 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_CHROMEOS_H_ +#define CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_CHROMEOS_H_ + +#include "ash/session_state_delegate.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/observer_list.h" +#include "chrome/browser/chromeos/login/user_manager.h" + +namespace ash { +class SessionStateObserver; +} // namespace ash + +class SessionStateDelegateChromeos + : public ash::SessionStateDelegate, + public chromeos::UserManager::UserSessionStateObserver { + public: + SessionStateDelegateChromeos(); + virtual ~SessionStateDelegateChromeos(); + + // ash::SessionStateDelegate: + virtual int GetMaximumNumberOfLoggedInUsers() const OVERRIDE; + virtual int NumberOfLoggedInUsers() 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; + virtual const base::string16 GetUserDisplayName( + ash::MultiProfileIndex index) const OVERRIDE; + virtual const std::string GetUserEmail( + ash::MultiProfileIndex index) const OVERRIDE; + virtual const gfx::ImageSkia& GetUserImage( + ash::MultiProfileIndex index) const OVERRIDE; + virtual void GetLoggedInUsers(ash::UserIdList* users) OVERRIDE; + virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; + virtual void AddSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; + virtual void RemoveSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; + + // UserManager::UserSessionStateObserver: + virtual void ActiveUserChanged(const chromeos::User* active_user) OVERRIDE; + + private: + // List of observers is only used on Chrome OS for now. + ObserverList<ash::SessionStateObserver> session_state_observer_list_; + + DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateChromeos); +}; + +#endif // CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_CHROMEOS_H_ diff --git a/chrome/browser/ui/ash/session_state_delegate_views.cc b/chrome/browser/ui/ash/session_state_delegate_views.cc index f4aafd0..4aa773a 100644 --- a/chrome/browser/ui/ash/session_state_delegate_views.cc +++ b/chrome/browser/ui/ash/session_state_delegate_views.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/ui/ash/session_state_delegate.h" +#include "chrome/browser/ui/ash/session_state_delegate_views.h" #include "base/logging.h" #include "base/string16.h" @@ -65,11 +65,20 @@ const gfx::ImageSkia& SessionStateDelegate::GetUserImage( return null_image; } -void SessionStateDelegate::GetLoggedInUsers( - ash::UserEmailList* users) { +void SessionStateDelegate::GetLoggedInUsers(ash::UserIdList* users) { NOTIMPLEMENTED(); } -void SessionStateDelegate::SwitchActiveUser(const std::string& email) { +void SessionStateDelegate::SwitchActiveUser(const std::string& user_id) { + NOTIMPLEMENTED(); +} + +void SessionStateDelegate::AddSessionStateObserver( + ash::SessionStateObserver* observer) { + NOTIMPLEMENTED(); +} + +void SessionStateDelegate::RemoveSessionStateObserver( + ash::SessionStateObserver* observer) { NOTIMPLEMENTED(); } diff --git a/chrome/browser/ui/ash/session_state_delegate.h b/chrome/browser/ui/ash/session_state_delegate_views.h index 50a3feb..614b1c2 100644 --- a/chrome/browser/ui/ash/session_state_delegate.h +++ b/chrome/browser/ui/ash/session_state_delegate_views.h @@ -2,12 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_ -#define CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_ +#ifndef CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_VIEWS_H_ +#define CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_VIEWS_H_ #include "ash/session_state_delegate.h" #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/observer_list.h" + +namespace ash { +class SessionStateObserver; +} // namespace ash class SessionStateDelegate : public ash::SessionStateDelegate { public: @@ -28,11 +33,15 @@ class SessionStateDelegate : public ash::SessionStateDelegate { ash::MultiProfileIndex index) const OVERRIDE; virtual const gfx::ImageSkia& GetUserImage( ash::MultiProfileIndex index) const OVERRIDE; - virtual void GetLoggedInUsers(ash::UserEmailList* users) OVERRIDE; - virtual void SwitchActiveUser(const std::string& email) OVERRIDE; + virtual void GetLoggedInUsers(ash::UserIdList* users) OVERRIDE; + virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE; + virtual void AddSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; + virtual void RemoveSessionStateObserver( + ash::SessionStateObserver* observer) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(SessionStateDelegate); }; -#endif // CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_H_ +#endif // CHROME_BROWSER_UI_ASH_SESSION_STATE_DELEGATE_VIEWS_H_ diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index fb38de6..6f0033e 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -249,9 +249,10 @@ 'browser/ui/ash/launcher/shell_window_launcher_controller.h', 'browser/ui/ash/screenshot_taker.cc', 'browser/ui/ash/screenshot_taker.h', - 'browser/ui/ash/session_state_delegate.h', 'browser/ui/ash/session_state_delegate_chromeos.cc', + 'browser/ui/ash/session_state_delegate_chromeos.h', 'browser/ui/ash/session_state_delegate_views.cc', + 'browser/ui/ash/session_state_delegate_views.h', 'browser/ui/ash/tabs/dock_info_ash.cc', 'browser/ui/ash/tabs/dock_info_ash.h', 'browser/ui/ash/tabs/dock_info_chromeos.cc', diff --git a/chrome/common/chrome_notification_types.h b/chrome/common/chrome_notification_types.h index a781c35..c396581 100644 --- a/chrome/common/chrome_notification_types.h +++ b/chrome/common/chrome_notification_types.h @@ -890,12 +890,6 @@ enum NotificationType { // The details are a chromeos::User object. NOTIFICATION_LOGIN_USER_CHANGED, - // Sent when a chromium os active user has changed. - // The details are a chromeos::User object. - // This notification is _not_ sent when user logs in to a new or existing - // session because NOTIFICATION_LOGIN_USER_CHANGED is sent instead. - NOTIFICATION_ACTIVE_USER_CHANGED, - // Sent immediately after the logged-in user's profile is ready. // The details are a Profile object. NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |