diff options
18 files changed, 130 insertions, 255 deletions
diff --git a/chrome/browser/automation/testing_automation_provider_chromeos.cc b/chrome/browser/automation/testing_automation_provider_chromeos.cc index 96eedfb..000677f 100644 --- a/chrome/browser/automation/testing_automation_provider_chromeos.cc +++ b/chrome/browser/automation/testing_automation_provider_chromeos.cc @@ -47,6 +47,7 @@ #include "chrome/common/pref_names.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #include "chromeos/dbus/update_engine_client.h" #include "content/public/browser/web_contents.h" #include "net/base/network_change_notifier.h" @@ -515,8 +516,7 @@ void TestingAutomationProvider::GetOOBEScreenInfo(DictionaryValue* args, void TestingAutomationProvider::LockScreen(DictionaryValue* args, IPC::Message* reply_message) { new ScreenLockUnlockObserver(this, reply_message, true); - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenLockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen(); } void TestingAutomationProvider::UnlockScreen(DictionaryValue* args, diff --git a/chrome/browser/chromeos/login/login_performer.cc b/chrome/browser/chromeos/login/login_performer.cc index 5a77afc..cb0e689 100644 --- a/chrome/browser/chromeos/login/login_performer.cc +++ b/chrome/browser/chromeos/login/login_performer.cc @@ -28,7 +28,7 @@ #include "chrome/common/net/gaia/gaia_auth_util.h" #include "chrome/common/pref_names.h" #include "chromeos/dbus/dbus_thread_manager.h" -#include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" @@ -386,16 +386,14 @@ void LoginPerformer::RequestScreenLock() { ResolveScreenLocked(); } else { screen_lock_requested_ = true; - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenLockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen(); } } void LoginPerformer::RequestScreenUnlock() { DVLOG(1) << "Screen unlock requested"; if (ScreenLocker::default_screen_locker()) { - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenUnlockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestUnlockScreen(); // Will unsubscribe from notifications once unlock is successful. } else { LOG(ERROR) << "Screen is not locked"; diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 0688b38..3b285a4 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -50,7 +50,7 @@ using content::UserMetricsAction; namespace { // Observer to start ScreenLocker when the screen lock -class ScreenLockObserver : public chromeos::PowerManagerClient::Observer, +class ScreenLockObserver : public chromeos::SessionManagerClient::Observer, public content::NotificationObserver { public: ScreenLockObserver() : session_started_(false) { @@ -69,10 +69,10 @@ class ScreenLockObserver : public chromeos::PowerManagerClient::Observer, switch (type) { case chrome::NOTIFICATION_LOGIN_USER_CHANGED: { // Register Screen Lock only after a user has logged in. - chromeos::PowerManagerClient* power_manager = - chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); - if (!power_manager->HasObserver(this)) - power_manager->AddObserver(this); + chromeos::SessionManagerClient* session_manager = + chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); + if (!session_manager->HasObserver(this)) + session_manager->AddObserver(this); break; } @@ -200,8 +200,7 @@ void ScreenLocker::OnLoginSuccess( content::Source<Profile>(profile), content::Details<const GoogleServiceSigninSuccessDetails>(&details)); } - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenUnlockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestUnlockScreen(); if (login_status_consumer_) login_status_consumer_->OnLoginSuccess(username, password, pending_requests, @@ -287,9 +286,6 @@ void ScreenLocker::Show() { new ScreenLocker(UserManager::Get()->GetLoggedInUser()); locker->Init(); } else { - // PowerManager re-sends lock screen signal if it doesn't - // receive the response within timeout. Just send complete - // signal. DVLOG(1) << "Show: locker already exists. Just sending completion event."; DBusThreadManager::Get()->GetPowerManagerClient()-> NotifyScreenLockCompleted(); diff --git a/chrome/browser/chromeos/notifications/system_notification.cc b/chrome/browser/chromeos/notifications/system_notification.cc index 587ce48..077a5ff 100644 --- a/chrome/browser/chromeos/notifications/system_notification.cc +++ b/chrome/browser/chromeos/notifications/system_notification.cc @@ -16,7 +16,7 @@ namespace chromeos { void SystemNotification::Init(int icon_resource_id) { - DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); collection_ = static_cast<BalloonCollectionImplAsh*>( g_browser_process->notification_ui_manager()->balloon_collection()); std::string url = web_ui_util::GetImageDataUrlFromResource(icon_resource_id); @@ -56,7 +56,7 @@ SystemNotification::SystemNotification(Profile* profile, } SystemNotification::~SystemNotification() { - DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); } void SystemNotification::UnlockScreen() { @@ -84,7 +84,8 @@ void SystemNotification::Show(const string16& message, callback_ = callback; sticky_ = sticky; - if (DBusThreadManager::Get()->GetPowerManagerClient()->GetIsScreenLocked()) { + if (DBusThreadManager::Get()->GetSessionManagerClient()-> + GetIsScreenLocked()) { if (visible_ && urgent && !urgent_) { // Hide the notification so that we show/update it on unlock. Hide(); diff --git a/chrome/browser/chromeos/notifications/system_notification.h b/chrome/browser/chromeos/notifications/system_notification.h index f9d78b9..284fca3 100644 --- a/chrome/browser/chromeos/notifications/system_notification.h +++ b/chrome/browser/chromeos/notifications/system_notification.h @@ -13,7 +13,7 @@ #include "base/string16.h" #include "chrome/browser/chromeos/notifications/balloon_view_host_chromeos.h" // MessageCallback #include "chrome/browser/notifications/notification_delegate.h" -#include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #include "googleurl/src/gurl.h" class BalloonCollectionImplAsh; @@ -24,7 +24,7 @@ namespace chromeos { // The system notification object handles the display of a system notification -class SystemNotification : public PowerManagerClient::Observer { +class SystemNotification : public SessionManagerClient::Observer { public: // The profile is the current user profile. The id is any string used // to uniquely identify this notification. The title is the title of @@ -42,7 +42,7 @@ class SystemNotification : public PowerManagerClient::Observer { virtual ~SystemNotification(); - // PowerManagerClient::Observer override. + // SessionManagerClient::Observer override. virtual void UnlockScreen() OVERRIDE; void set_title(const string16& title) { title_ = title; } diff --git a/chrome/browser/chromeos/power/power_button_controller_delegate_chromeos.cc b/chrome/browser/chromeos/power/power_button_controller_delegate_chromeos.cc index e67fb03..24bd760 100644 --- a/chrome/browser/chromeos/power/power_button_controller_delegate_chromeos.cc +++ b/chrome/browser/chromeos/power/power_button_controller_delegate_chromeos.cc @@ -9,6 +9,7 @@ #include "chrome/browser/lifetime/application_lifetime.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" namespace chromeos { @@ -22,8 +23,7 @@ void PowerButtonControllerDelegateChromeos::RequestLockScreen() { return; } - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenLockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen(); } void PowerButtonControllerDelegateChromeos::RequestShutdown() { diff --git a/chrome/browser/chromeos/power/power_button_observer.cc b/chrome/browser/chromeos/power/power_button_observer.cc index a10e5b5..57742ec 100644 --- a/chrome/browser/chromeos/power/power_button_observer.cc +++ b/chrome/browser/chromeos/power/power_button_observer.cc @@ -51,6 +51,7 @@ PowerButtonObserver::PowerButtonObserver() { content::NotificationService::AllSources()); DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); // Tell the controller about the initial state. ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus()); @@ -61,6 +62,7 @@ PowerButtonObserver::PowerButtonObserver() { } PowerButtonObserver::~PowerButtonObserver() { + DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); } diff --git a/chrome/browser/chromeos/power/power_button_observer.h b/chrome/browser/chromeos/power/power_button_observer.h index 6cbd402..b1dfca9 100644 --- a/chrome/browser/chromeos/power/power_button_observer.h +++ b/chrome/browser/chromeos/power/power_button_observer.h @@ -9,6 +9,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -17,7 +18,8 @@ namespace chromeos { // Listens for power button, login, and screen lock events and passes them to // the Aura shell's PowerButtonController class. class PowerButtonObserver : public content::NotificationObserver, - public PowerManagerClient::Observer { + public PowerManagerClient::Observer, + public SessionManagerClient::Observer { public: // This class registers/unregisters itself as an observer in ctor/dtor. PowerButtonObserver(); @@ -34,6 +36,8 @@ class PowerButtonObserver : public content::NotificationObserver, bool down, const base::TimeTicks& timestamp) OVERRIDE; virtual void LockButtonStateChanged( bool down, const base::TimeTicks& timestamp) OVERRIDE; + + // SessionManagerClient::Observer implementation. virtual void LockScreen() OVERRIDE; content::NotificationRegistrar registrar_; diff --git a/chrome/browser/chromeos/power/screen_lock_observer.cc b/chrome/browser/chromeos/power/screen_lock_observer.cc index 1e5039f..419a489 100644 --- a/chrome/browser/chromeos/power/screen_lock_observer.cc +++ b/chrome/browser/chromeos/power/screen_lock_observer.cc @@ -10,11 +10,11 @@ namespace chromeos { ScreenLockObserver::ScreenLockObserver() { - DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); } ScreenLockObserver::~ScreenLockObserver() { - DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); } void ScreenLockObserver::UnlockScreen() { diff --git a/chrome/browser/chromeos/power/screen_lock_observer.h b/chrome/browser/chromeos/power/screen_lock_observer.h index ff34365..61f2f1d 100644 --- a/chrome/browser/chromeos/power/screen_lock_observer.h +++ b/chrome/browser/chromeos/power/screen_lock_observer.h @@ -8,19 +8,19 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" namespace chromeos { // A class to observe screen lock events and dispatch onScreenUnlocked extension // API events. -class ScreenLockObserver : public PowerManagerClient::Observer { +class ScreenLockObserver : public SessionManagerClient::Observer { public: // This class registers/unregisters itself as an observer in ctor/dtor. ScreenLockObserver(); virtual ~ScreenLockObserver(); - // PowerManagerClient::Observer override. + // SessionManagerClient::Observer override. virtual void UnlockScreen() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index ae77fcc..b77c18f 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -66,6 +66,7 @@ #include "chrome/common/url_constants.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_service.h" @@ -152,6 +153,7 @@ void BluetoothDeviceConnectError() { class SystemTrayDelegate : public ash::SystemTrayDelegate, public AudioHandler::VolumeObserver, public PowerManagerClient::Observer, + public SessionManagerClient::Observer, public NetworkMenuIcon::Delegate, public NetworkMenu::Delegate, public NetworkLibrary::NetworkManagerObserver, @@ -184,6 +186,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( PowerManagerClient::UPDATE_INITIAL); + DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); crosnet->AddNetworkManagerObserver(this); @@ -226,6 +229,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, AudioHandler* audiohandler = AudioHandler::GetInstance(); if (audiohandler) audiohandler->RemoveVolumeObserver(this); + DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); if (crosnet) { @@ -380,8 +384,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } virtual void RequestLockScreen() OVERRIDE { - DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenLockRequested(); + DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen(); } virtual void RequestRestart() OVERRIDE { @@ -951,6 +954,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, NotifyRefreshClock(); } + // Overridden from SessionManagerClient::Observer. virtual void LockScreen() OVERRIDE { screen_locked_ = true; ash::Shell::GetInstance()->status_area_widget()-> diff --git a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc index 9901c4c..c4b770c 100644 --- a/chrome/browser/ui/views/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/views/ash/chrome_shell_delegate.cc @@ -47,6 +47,7 @@ #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/power_manager_client.h" +#include "chromeos/dbus/session_manager_client.h" #endif namespace { @@ -102,8 +103,8 @@ void ChromeShellDelegate::LockScreen() { #if defined(OS_CHROMEOS) if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession) && !chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) { - chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> - NotifyScreenLockRequested(); + chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> + RequestLockScreen(); } #endif } diff --git a/chromeos/dbus/mock_power_manager_client.h b/chromeos/dbus/mock_power_manager_client.h index 4a29e21..51cf36c 100644 --- a/chromeos/dbus/mock_power_manager_client.h +++ b/chromeos/dbus/mock_power_manager_client.h @@ -38,11 +38,8 @@ class MockPowerManagerClient : public PowerManagerClient { uint32, int, const PowerStateRequestIdCallback&)); - MOCK_METHOD0(NotifyScreenLockRequested, void(void)); MOCK_METHOD0(NotifyScreenLockCompleted, void(void)); - MOCK_METHOD0(NotifyScreenUnlockRequested, void(void)); MOCK_METHOD0(NotifyScreenUnlockCompleted, void(void)); - MOCK_METHOD0(GetIsScreenLocked, bool(void)); }; } // namespace chromeos diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h index b8632b54..2ea212fe 100644 --- a/chromeos/dbus/mock_session_manager_client.h +++ b/chromeos/dbus/mock_session_manager_client.h @@ -19,12 +19,16 @@ class MockSessionManagerClient : public SessionManagerClient { MOCK_METHOD1(AddObserver, void(Observer*)); MOCK_METHOD1(RemoveObserver, void(Observer*)); + MOCK_METHOD1(HasObserver, bool(Observer*)); MOCK_METHOD0(EmitLoginPromptReady, void(void)); MOCK_METHOD0(EmitLoginPromptVisible, void(void)); MOCK_METHOD0(RestartEntd, void(void)); MOCK_METHOD2(RestartJob, void(int, const std::string&)); MOCK_METHOD1(StartSession, void(const std::string&)); MOCK_METHOD0(StopSession, void(void)); + MOCK_METHOD0(RequestLockScreen, void(void)); + MOCK_METHOD0(RequestUnlockScreen, void(void)); + MOCK_METHOD0(GetIsScreenLocked, bool(void)); MOCK_METHOD1(RetrieveDevicePolicy, void(const RetrievePolicyCallback&)); MOCK_METHOD1(RetrieveUserPolicy, void(const RetrievePolicyCallback&)); MOCK_METHOD2(StoreDevicePolicy, void(const std::string&, diff --git a/chromeos/dbus/power_manager_client.cc b/chromeos/dbus/power_manager_client.cc index 6c279fe..d1e7fb5 100644 --- a/chromeos/dbus/power_manager_client.cc +++ b/chromeos/dbus/power_manager_client.cc @@ -10,7 +10,6 @@ #include "base/callback.h" #include "base/format_macros.h" #include "base/memory/scoped_ptr.h" -#include "base/metrics/histogram.h" #include "base/observer_list.h" #include "base/stringprintf.h" #include "base/time.h" @@ -28,25 +27,8 @@ namespace chromeos { // The PowerManagerClient implementation used in production. class PowerManagerClientImpl : public PowerManagerClient { public: - enum LockScreensState { - LOCK_SCREEN_REQUESTED, // Lock screen is requested. - LOCK_SCREEN_REQUEST_SUCCEEDED, // Method call succeeded. - LOCK_SCREEN_REQUEST_FAILED, // Method call failed. - LOCK_SCREEN_FINISHED, // Signal is received. - NUM_LOCK_SCREEN_STATES - }; - - enum UnlockScreensState { - UNLOCK_SCREEN_REQUESTED, // Unlock screen is requested. - UNLOCK_SCREEN_REQUEST_SUCCEEDED, // Method call succeeded. - UNLOCK_SCREEN_REQUEST_FAILED, // Method call failed. - UNLOCK_SCREEN_FINISHED, // Signal is received. - NUM_UNLOCK_SCREEN_STATES - }; - explicit PowerManagerClientImpl(dbus::Bus* bus) : power_manager_proxy_(NULL), - screen_locked_(false), weak_ptr_factory_(this) { power_manager_proxy_ = bus->GetObjectProxy( power_manager::kPowerManagerServiceName, @@ -99,22 +81,6 @@ class PowerManagerClientImpl : public PowerManagerClient { base::Bind(&PowerManagerClientImpl::SignalConnected, weak_ptr_factory_.GetWeakPtr())); - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kLockScreenSignal, - base::Bind(&PowerManagerClientImpl::ScreenLockSignalReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - - session_manager_proxy_->ConnectToSignal( - chromium::kChromiumInterface, - chromium::kUnlockScreenSignal, - base::Bind(&PowerManagerClientImpl::ScreenUnlockSignalReceived, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::SignalConnected, - weak_ptr_factory_.GetWeakPtr())); - power_manager_proxy_->ConnectToSignal( power_manager::kPowerManagerInterface, power_manager::kIdleNotifySignal, @@ -299,48 +265,14 @@ class PowerManagerClientImpl : public PowerManagerClient { weak_ptr_factory_.GetWeakPtr(), callback)); } - virtual void NotifyScreenLockRequested() OVERRIDE { - dbus::MethodCall method_call(power_manager::kPowerManagerInterface, - power_manager::kRequestLockScreenMethod); - UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", - LOCK_SCREEN_REQUESTED, - NUM_LOCK_SCREEN_STATES); - power_manager_proxy_->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&PowerManagerClientImpl::OnScreenLockRequested, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::OnScreenLockRequestedError, - weak_ptr_factory_.GetWeakPtr())); - } - virtual void NotifyScreenLockCompleted() OVERRIDE { SimpleMethodCallToPowerManager(power_manager::kScreenIsLockedMethod); } - virtual void NotifyScreenUnlockRequested() OVERRIDE { - dbus::MethodCall method_call(power_manager::kPowerManagerInterface, - power_manager::kRequestUnlockScreenMethod); - UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", - UNLOCK_SCREEN_REQUESTED, - NUM_UNLOCK_SCREEN_STATES); - power_manager_proxy_->CallMethodWithErrorCallback( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&PowerManagerClientImpl::OnScreenUnlockRequested, - weak_ptr_factory_.GetWeakPtr()), - base::Bind(&PowerManagerClientImpl::OnScreenUnlockRequestedError, - weak_ptr_factory_.GetWeakPtr())); - } - virtual void NotifyScreenUnlockCompleted() OVERRIDE { SimpleMethodCallToPowerManager(power_manager::kScreenIsUnlockedMethod); } - virtual bool GetIsScreenLocked() OVERRIDE { - return screen_locked_; - } - private: // Called when a dbus signal is initially connected. void SignalConnected(const std::string& interface_name, @@ -503,47 +435,6 @@ class PowerManagerClientImpl : public PowerManagerClient { callback.Run(request_id); } - void OnScreenLockRequested(dbus::Response* response) { - UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", - LOCK_SCREEN_REQUEST_SUCCEEDED, - NUM_LOCK_SCREEN_STATES); - } - - void OnScreenLockRequestedError(dbus::ErrorResponse* error_response) { - if (error_response) { - dbus::MessageReader reader(error_response); - std::string error_message; - reader.PopString(&error_message); - LOG(ERROR) << "Failed to call ScreenLockRequested: " - << error_response->GetErrorName() - << ": " << error_message; - } - UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", - LOCK_SCREEN_REQUEST_FAILED, - NUM_LOCK_SCREEN_STATES); - } - - void OnScreenUnlockRequested(dbus::Response* response) { - UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", - UNLOCK_SCREEN_REQUEST_SUCCEEDED, - NUM_UNLOCK_SCREEN_STATES); - } - - void OnScreenUnlockRequestedError(dbus::ErrorResponse* error_response) { - if (error_response) { - dbus::MessageReader reader(error_response); - std::string error_message; - reader.PopString(&error_message); - LOG(ERROR) << "Failed to call ScreenUnlockRequested: " - << error_response->GetErrorName() - << ": " << error_message; - } - UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", - UNLOCK_SCREEN_REQUEST_FAILED, - NUM_UNLOCK_SCREEN_STATES); - } - - void OnGetScreenBrightnessPercent( const GetScreenBrightnessPercentCallback& callback, dbus::Response* response) { @@ -560,26 +451,6 @@ class PowerManagerClientImpl : public PowerManagerClient { callback.Run(percent); } - void ScreenLockSignalReceived(dbus::Signal* signal) { - // TODO(flackr): This warning is actually a signal that things are working - // as expected. As per http://crbug.com/126217, this will help determine - // if the problem is with dbus or in chrome. - LOG(WARNING) << "LockScreen signal received from power manager."; - screen_locked_ = true; - UMA_HISTOGRAM_ENUMERATION("LockScreen.LockScreenPath", - LOCK_SCREEN_FINISHED, - NUM_LOCK_SCREEN_STATES); - FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); - } - - void ScreenUnlockSignalReceived(dbus::Signal* signal) { - screen_locked_ = false; - UMA_HISTOGRAM_ENUMERATION("LockScreen.UnlockScreenPath", - UNLOCK_SCREEN_FINISHED, - NUM_UNLOCK_SCREEN_STATES); - FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); - } - void IdleNotifySignalReceived(dbus::Signal* signal) { dbus::MessageReader reader(signal); int64 threshold = 0; @@ -634,7 +505,6 @@ class PowerManagerClientImpl : public PowerManagerClient { dbus::ObjectProxy* power_manager_proxy_; dbus::ObjectProxy* session_manager_proxy_; ObserverList<Observer> observers_; - bool screen_locked_; base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); @@ -648,8 +518,7 @@ class PowerManagerClientStubImpl : public PowerManagerClient { : discharging_(true), battery_percentage_(40), brightness_(50.0), - pause_count_(2), - screen_locked_(false) { + pause_count_(2) { } virtual ~PowerManagerClientStubImpl() {} @@ -726,19 +595,8 @@ class PowerManagerClientStubImpl : public PowerManagerClient { int overrides, const PowerStateRequestIdCallback& callback) OVERRIDE {} - virtual void NotifyScreenLockRequested() OVERRIDE { - screen_locked_ = true; - FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); - } virtual void NotifyScreenLockCompleted() OVERRIDE {} - virtual void NotifyScreenUnlockRequested() OVERRIDE { - screen_locked_ = false; - FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); - } virtual void NotifyScreenUnlockCompleted() OVERRIDE {} - virtual bool GetIsScreenLocked() OVERRIDE { - return screen_locked_; - } private: void Update() { @@ -786,7 +644,6 @@ class PowerManagerClientStubImpl : public PowerManagerClient { ObserverList<Observer> observers_; base::RepeatingTimer<PowerManagerClientStubImpl> timer_; PowerSupplyStatus status_; - bool screen_locked_; }; PowerManagerClient::PowerManagerClient() { diff --git a/chromeos/dbus/power_manager_client.h b/chromeos/dbus/power_manager_client.h index dcd9848..3526890 100644 --- a/chromeos/dbus/power_manager_client.h +++ b/chromeos/dbus/power_manager_client.h @@ -74,12 +74,6 @@ class CHROMEOS_EXPORT PowerManagerClient { virtual void LockButtonStateChanged(bool down, const base::TimeTicks& timestamp) {} - // Called when the screen is locked. - virtual void LockScreen() {} - - // Called when the screen is unlocked. - virtual void UnlockScreen() {} - // Called when we go idle for threshold time. virtual void IdleNotify(int64 threshold_secs) {} @@ -134,23 +128,12 @@ class CHROMEOS_EXPORT PowerManagerClient { // Requests shutdown of the system. virtual void RequestShutdown() = 0; - // Notifies PowerManager that a user requested to lock the screen. - virtual void NotifyScreenLockRequested() = 0; - // Notifies PowerManager that screen lock has been completed. virtual void NotifyScreenLockCompleted() = 0; - // Notifies PowerManager that a user unlocked the screen. - virtual void NotifyScreenUnlockRequested() = 0; - // Notifies PowerManager that screen is unlocked. virtual void NotifyScreenUnlockCompleted() = 0; - // Return whether or not the screen is locked. Implementation should cache - // this state so that it can return immediately. Useful for observers that - // need to know the current screen lock state when they are added. - virtual bool GetIsScreenLocked() = 0; - // Idle management functions: // Calculates idle time asynchronously, after the idle time request has diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc index 6c40353..dd90b94 100644 --- a/chromeos/dbus/session_manager_client.cc +++ b/chromeos/dbus/session_manager_client.cc @@ -20,12 +20,12 @@ class SessionManagerClientImpl : public SessionManagerClient { public: explicit SessionManagerClientImpl(dbus::Bus* bus) : session_manager_proxy_(NULL), + screen_locked_(false), weak_ptr_factory_(this) { session_manager_proxy_ = bus->GetObjectProxy( login_manager::kSessionManagerServiceName, dbus::ObjectPath(login_manager::kSessionManagerServicePath)); - // Monitor the D-Bus signal for owner key changes. session_manager_proxy_->ConnectToSignal( chromium::kChromiumInterface, chromium::kOwnerKeySetSignal, @@ -34,7 +34,6 @@ class SessionManagerClientImpl : public SessionManagerClient { base::Bind(&SessionManagerClientImpl::SignalConnected, weak_ptr_factory_.GetWeakPtr())); - // Monitor the D-Bus signal for property changes. session_manager_proxy_->ConnectToSignal( chromium::kChromiumInterface, chromium::kPropertyChangeCompleteSignal, @@ -42,46 +41,50 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_.GetWeakPtr()), base::Bind(&SessionManagerClientImpl::SignalConnected, weak_ptr_factory_.GetWeakPtr())); + + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kLockScreenSignal, + base::Bind(&SessionManagerClientImpl::ScreenLockReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); + + session_manager_proxy_->ConnectToSignal( + chromium::kChromiumInterface, + chromium::kUnlockScreenSignal, + base::Bind(&SessionManagerClientImpl::ScreenUnlockReceived, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&SessionManagerClientImpl::SignalConnected, + weak_ptr_factory_.GetWeakPtr())); } virtual ~SessionManagerClientImpl() { } - // SessionManagerClient override. + // SessionManagerClient overrides: virtual void AddObserver(Observer* observer) OVERRIDE { observers_.AddObserver(observer); } - // SessionManagerClient override. virtual void RemoveObserver(Observer* observer) OVERRIDE { observers_.RemoveObserver(observer); } - // SessionManagerClient override. + virtual bool HasObserver(Observer* observer) OVERRIDE { + return observers_.HasObserver(observer); + } + virtual void EmitLoginPromptReady() OVERRIDE { - dbus::MethodCall method_call( - login_manager::kSessionManagerInterface, + SimpleMethodCallToSessionManager( login_manager::kSessionManagerEmitLoginPromptReady); - session_manager_proxy_->CallMethod( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&SessionManagerClientImpl::OnEmitLoginPromptReady, - weak_ptr_factory_.GetWeakPtr())); } - // SessionManagerClient override. virtual void EmitLoginPromptVisible() OVERRIDE { - dbus::MethodCall method_call( - login_manager::kSessionManagerInterface, + SimpleMethodCallToSessionManager( login_manager::kSessionManagerEmitLoginPromptVisible); - session_manager_proxy_->CallMethod( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&SessionManagerClientImpl::OnEmitLoginPromptVisible, - weak_ptr_factory_.GetWeakPtr())); } - // SessionManagerClient override. virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE { dbus::MethodCall method_call(login_manager::kSessionManagerInterface, login_manager::kSessionManagerRestartJob); @@ -95,18 +98,10 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_.GetWeakPtr())); } - // SessionManagerClient override. virtual void RestartEntd() OVERRIDE { - dbus::MethodCall method_call(login_manager::kSessionManagerInterface, - login_manager::kSessionManagerRestartEntd); - session_manager_proxy_->CallMethod( - &method_call, - dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, - base::Bind(&SessionManagerClientImpl::OnRestartEntd, - weak_ptr_factory_.GetWeakPtr())); + SimpleMethodCallToSessionManager(login_manager::kSessionManagerRestartEntd); } - // SessionManagerClient override. virtual void StartSession(const std::string& user_email) OVERRIDE { dbus::MethodCall method_call(login_manager::kSessionManagerInterface, login_manager::kSessionManagerStartSession); @@ -120,7 +115,6 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_.GetWeakPtr())); } - // SessionManagerClient override. virtual void StopSession() OVERRIDE { dbus::MethodCall method_call(login_manager::kSessionManagerInterface, login_manager::kSessionManagerStopSession); @@ -133,28 +127,37 @@ class SessionManagerClientImpl : public SessionManagerClient { weak_ptr_factory_.GetWeakPtr())); } - // SessionManagerClient override. + virtual void RequestLockScreen() OVERRIDE { + SimpleMethodCallToSessionManager(login_manager::kSessionManagerLockScreen); + } + + virtual void RequestUnlockScreen() OVERRIDE { + SimpleMethodCallToSessionManager( + login_manager::kSessionManagerUnlockScreen); + } + + virtual bool GetIsScreenLocked() OVERRIDE { + return screen_locked_; + } + virtual void RetrieveDevicePolicy( const RetrievePolicyCallback& callback) OVERRIDE { CallRetrievePolicy(login_manager::kSessionManagerRetrievePolicy, callback); } - // SessionManagerClient override. virtual void RetrieveUserPolicy( const RetrievePolicyCallback& callback) OVERRIDE { CallRetrievePolicy(login_manager::kSessionManagerRetrieveUserPolicy, callback); } - // SessionManagerClient override. virtual void StoreDevicePolicy(const std::string& policy_blob, const StorePolicyCallback& callback) OVERRIDE { CallStorePolicy(login_manager::kSessionManagerStorePolicy, policy_blob, callback); } - // SessionManagerClient override. virtual void StoreUserPolicy(const std::string& policy_blob, const StorePolicyCallback& callback) OVERRIDE { CallStorePolicy(login_manager::kSessionManagerStoreUserPolicy, @@ -162,6 +165,17 @@ class SessionManagerClientImpl : public SessionManagerClient { } private: + // Makes a method call to the session manager with no arguments and no + // response. + void SimpleMethodCallToSessionManager(const std::string& method_name) { + dbus::MethodCall method_call(login_manager::kSessionManagerInterface, + method_name); + session_manager_proxy_->CallMethod( + &method_call, + dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, + dbus::ObjectProxy::EmptyResponseCallback()); + } + // Helper for Retrieve{User,Device}Policy. virtual void CallRetrievePolicy(const std::string& method_name, const RetrievePolicyCallback& callback) { @@ -195,20 +209,6 @@ class SessionManagerClientImpl : public SessionManagerClient { callback)); } - // Called when kSessionManagerEmitLoginPromptReady method is complete. - void OnEmitLoginPromptReady(dbus::Response* response) { - LOG_IF(ERROR, !response) - << "Failed to call " - << login_manager::kSessionManagerEmitLoginPromptReady; - } - - // Called when kSessionManagerEmitLoginPromptVisible method is complete. - void OnEmitLoginPromptVisible(dbus::Response* response) { - LOG_IF(ERROR, !response) - << "Failed to call " - << login_manager::kSessionManagerEmitLoginPromptVisible; - } - // Called when kSessionManagerRestartJob method is complete. void OnRestartJob(dbus::Response* response) { LOG_IF(ERROR, !response) @@ -216,13 +216,6 @@ class SessionManagerClientImpl : public SessionManagerClient { << login_manager::kSessionManagerRestartJob; } - // Called when kSessionManagerRestartEntd method is complete. - void OnRestartEntd(dbus::Response* response) { - LOG_IF(ERROR, !response) - << "Failed to call " - << login_manager::kSessionManagerRestartEntd; - } - // Called when kSessionManagerStartSession method is complete. void OnStartSession(dbus::Response* response) { LOG_IF(ERROR, !response) @@ -300,6 +293,16 @@ class SessionManagerClientImpl : public SessionManagerClient { FOR_EACH_OBSERVER(Observer, observers_, PropertyChangeComplete(success)); } + void ScreenLockReceived(dbus::Signal* signal) { + screen_locked_ = true; + FOR_EACH_OBSERVER(Observer, observers_, LockScreen()); + } + + void ScreenUnlockReceived(dbus::Signal* signal) { + screen_locked_ = false; + FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen()); + } + // Called when the object is connected to the signal. void SignalConnected(const std::string& interface_name, const std::string& signal_name, @@ -309,6 +312,7 @@ class SessionManagerClientImpl : public SessionManagerClient { dbus::ObjectProxy* session_manager_proxy_; ObserverList<Observer> observers_; + bool screen_locked_; base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(SessionManagerClientImpl); @@ -320,12 +324,16 @@ class SessionManagerClientStubImpl : public SessionManagerClient { // SessionManagerClient overrides. virtual void AddObserver(Observer* observer) OVERRIDE {} virtual void RemoveObserver(Observer* observer) OVERRIDE {} + virtual bool HasObserver(Observer* observer) OVERRIDE { return false; } virtual void EmitLoginPromptReady() OVERRIDE {} virtual void EmitLoginPromptVisible() OVERRIDE {} virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {} virtual void RestartEntd() OVERRIDE {} virtual void StartSession(const std::string& user_email) OVERRIDE {} virtual void StopSession() OVERRIDE {} + virtual void RequestLockScreen() OVERRIDE {} + virtual void RequestUnlockScreen() OVERRIDE {} + virtual bool GetIsScreenLocked() OVERRIDE { return false; } virtual void RetrieveDevicePolicy( const RetrievePolicyCallback& callback) OVERRIDE { callback.Run(""); diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h index 82382e3..aed121e 100644 --- a/chromeos/dbus/session_manager_client.h +++ b/chromeos/dbus/session_manager_client.h @@ -26,13 +26,22 @@ class CHROMEOS_EXPORT SessionManagerClient { public: // Called when the owner key is set. virtual void OwnerKeySet(bool success) {} + // Called when the property change is complete. virtual void PropertyChangeComplete(bool success) {} + + // Called when the screen is locked. + virtual void LockScreen() {} + + // Called when the screen is unlocked. + virtual void UnlockScreen() {} + }; // Adds and removes the observer. virtual void AddObserver(Observer* observer) = 0; virtual void RemoveObserver(Observer* observer) = 0; + virtual bool HasObserver(Observer* observer) = 0; // Kicks off an attempt to emit the "login-prompt-ready" upstart signal. virtual void EmitLoginPromptReady() = 0; @@ -53,6 +62,17 @@ class CHROMEOS_EXPORT SessionManagerClient { // Stops the current session. virtual void StopSession() = 0; + // Locks the screen. + virtual void RequestLockScreen() = 0; + + // Unlocks the screen. + virtual void RequestUnlockScreen() = 0; + + // Returns whether or not the screen is locked. Implementation should cache + // this state so that it can return immediately. Useful for observers that + // need to know the current screen lock state when they are added. + virtual bool GetIsScreenLocked() = 0; + // Used for RetrieveDevicePolicy and RetrieveUserPolicy. Takes a serialized // protocol buffer as string. Upon success, we will pass a protobuf to the // callback. On failure, we will pass "". |