diff options
author | derat <derat@chromium.org> | 2015-01-13 13:46:25 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-13 21:48:07 +0000 |
commit | 85e90a06749fe630317eb01ca3487d5a78e9c10a (patch) | |
tree | 166c104d5e5e1a1bcb562fa7c74a01afe67ff703 | |
parent | 3a0efca1a48563a50e634eeb3401b43b7e6b2da7 (diff) | |
download | chromium_src-85e90a06749fe630317eb01ca3487d5a78e9c10a.zip chromium_src-85e90a06749fe630317eb01ca3487d5a78e9c10a.tar.gz chromium_src-85e90a06749fe630317eb01ca3487d5a78e9c10a.tar.bz2 |
chromeos: Make CheckIdleStateIsLocked() query D-Bus client.
Make the Chrome OS implementation of
CheckIdleStateIsLocked() (used by the chrome.idle API) get
the lock state from chromeos::SessionManagerClient instead
of depending on ash::SessionStateDelegate (which reaches
into chrome/browser/chromeos/login/). This makes it possible
for the idle code to be later moved under ui/base/ instead
of living in chrome/browser/, permitting the chrome.idle API
to be moved from chrome/ to extensions/.
As part of this, make SessionManagerClient cache the
most-recently-received-from-session_manager screen-lock
state. Previously it just passed state updates to its
observers, but the idle functions lack a class that can
register itself as an observer.
BUG=446320
Review URL: https://codereview.chromium.org/852453005
Cr-Commit-Position: refs/heads/master@{#311333}
-rw-r--r-- | chrome/browser/chromeos/settings/device_settings_test_helper.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/settings/device_settings_test_helper.h | 1 | ||||
-rw-r--r-- | chrome/browser/idle_chromeos.cc | 11 | ||||
-rw-r--r-- | chromeos/dbus/fake_session_manager_client.cc | 4 | ||||
-rw-r--r-- | chromeos/dbus/fake_session_manager_client.h | 1 | ||||
-rw-r--r-- | chromeos/dbus/mock_session_manager_client.h | 1 | ||||
-rw-r--r-- | chromeos/dbus/session_manager_client.cc | 14 | ||||
-rw-r--r-- | chromeos/dbus/session_manager_client.h | 5 |
8 files changed, 31 insertions, 8 deletions
diff --git a/chrome/browser/chromeos/settings/device_settings_test_helper.cc b/chrome/browser/chromeos/settings/device_settings_test_helper.cc index 3704edb..712b356 100644 --- a/chrome/browser/chromeos/settings/device_settings_test_helper.cc +++ b/chrome/browser/chromeos/settings/device_settings_test_helper.cc @@ -104,6 +104,8 @@ bool DeviceSettingsTestHelper::HasObserver(const Observer* observer) const { return false; } +bool DeviceSettingsTestHelper::IsScreenLocked() const { return false; } + void DeviceSettingsTestHelper::EmitLoginPromptVisible() {} void DeviceSettingsTestHelper::RestartJob(int pid, diff --git a/chrome/browser/chromeos/settings/device_settings_test_helper.h b/chrome/browser/chromeos/settings/device_settings_test_helper.h index 14147a1..74a198f 100644 --- a/chrome/browser/chromeos/settings/device_settings_test_helper.h +++ b/chrome/browser/chromeos/settings/device_settings_test_helper.h @@ -88,6 +88,7 @@ class DeviceSettingsTestHelper : public SessionManagerClient { virtual void AddObserver(Observer* observer) override; virtual void RemoveObserver(Observer* observer) override; virtual bool HasObserver(const Observer* observer) const override; + virtual bool IsScreenLocked() const override; virtual void EmitLoginPromptVisible() override; virtual void RestartJob(int pid, const std::string& command_line) override; virtual void StartSession(const std::string& user_email) override; diff --git a/chrome/browser/idle_chromeos.cc b/chrome/browser/idle_chromeos.cc index 9505d05..7c289a7 100644 --- a/chrome/browser/idle_chromeos.cc +++ b/chrome/browser/idle_chromeos.cc @@ -4,9 +4,9 @@ #include "chrome/browser/idle.h" -#include "ash/session/session_state_delegate.h" -#include "ash/shell.h" #include "base/time/time.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/session_manager_client.h" #include "ui/base/user_activity/user_activity_detector.h" void CalculateIdleTime(IdleTimeCallback notify) { @@ -16,9 +16,6 @@ void CalculateIdleTime(IdleTimeCallback notify) { } bool CheckIdleStateIsLocked() { -#if defined(USE_ATHENA) - return false; -#else - return ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked(); -#endif + return chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> + IsScreenLocked(); } diff --git a/chromeos/dbus/fake_session_manager_client.cc b/chromeos/dbus/fake_session_manager_client.cc index f16e9c6..27fe2df 100644 --- a/chromeos/dbus/fake_session_manager_client.cc +++ b/chromeos/dbus/fake_session_manager_client.cc @@ -39,6 +39,10 @@ bool FakeSessionManagerClient::HasObserver(const Observer* observer) const { return observers_.HasObserver(observer); } +bool FakeSessionManagerClient::IsScreenLocked() const { + return false; +} + void FakeSessionManagerClient::EmitLoginPromptVisible() { } diff --git a/chromeos/dbus/fake_session_manager_client.h b/chromeos/dbus/fake_session_manager_client.h index c0e53aa..3d11691 100644 --- a/chromeos/dbus/fake_session_manager_client.h +++ b/chromeos/dbus/fake_session_manager_client.h @@ -29,6 +29,7 @@ class FakeSessionManagerClient : public SessionManagerClient { virtual void AddObserver(Observer* observer) override; virtual void RemoveObserver(Observer* observer) override; virtual bool HasObserver(const Observer* observer) const override; + virtual bool IsScreenLocked() const override; virtual void EmitLoginPromptVisible() override; virtual void RestartJob(int pid, const std::string& command_line) override; virtual void StartSession(const std::string& user_email) override; diff --git a/chromeos/dbus/mock_session_manager_client.h b/chromeos/dbus/mock_session_manager_client.h index cdc5d6d..3a88e52 100644 --- a/chromeos/dbus/mock_session_manager_client.h +++ b/chromeos/dbus/mock_session_manager_client.h @@ -22,6 +22,7 @@ class MockSessionManagerClient : public SessionManagerClient { MOCK_METHOD1(AddObserver, void(Observer*)); MOCK_METHOD1(RemoveObserver, void(Observer*)); MOCK_CONST_METHOD1(HasObserver, bool(const Observer*)); + MOCK_CONST_METHOD0(IsScreenLocked, bool(void)); MOCK_METHOD0(EmitLoginPromptVisible, void(void)); MOCK_METHOD2(RestartJob, void(int, const std::string&)); MOCK_METHOD1(StartSession, void(const std::string&)); diff --git a/chromeos/dbus/session_manager_client.cc b/chromeos/dbus/session_manager_client.cc index 6dc2dce..27adf8b 100644 --- a/chromeos/dbus/session_manager_client.cc +++ b/chromeos/dbus/session_manager_client.cc @@ -66,6 +66,7 @@ class SessionManagerClientImpl : public SessionManagerClient { public: SessionManagerClientImpl() : session_manager_proxy_(NULL), + screen_is_locked_(false), weak_ptr_factory_(this) {} virtual ~SessionManagerClientImpl() { @@ -88,6 +89,8 @@ class SessionManagerClientImpl : public SessionManagerClient { return observers_.HasObserver(observer); } + virtual bool IsScreenLocked() const override { return screen_is_locked_; } + virtual void EmitLoginPromptVisible() override { SimpleMethodCallToSessionManager( login_manager::kSessionManagerEmitLoginPromptVisible); @@ -517,10 +520,12 @@ class SessionManagerClientImpl : public SessionManagerClient { } void ScreenIsLockedReceived(dbus::Signal* signal) { + screen_is_locked_ = true; FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); } void ScreenIsUnlockedReceived(dbus::Signal* signal) { + screen_is_locked_ = false; FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); } @@ -568,6 +573,9 @@ class SessionManagerClientImpl : public SessionManagerClient { scoped_ptr<BlockingMethodCaller> blocking_method_caller_; ObserverList<Observer> observers_; + // Most recent screen-lock state received from session_manager. + bool screen_is_locked_; + // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; @@ -579,7 +587,7 @@ class SessionManagerClientImpl : public SessionManagerClient { // which does nothing. class SessionManagerClientStubImpl : public SessionManagerClient { public: - SessionManagerClientStubImpl() : delegate_(NULL) {} + SessionManagerClientStubImpl() : delegate_(NULL), screen_is_locked_(false) {} virtual ~SessionManagerClientStubImpl() {} // SessionManagerClient overrides @@ -596,6 +604,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient { virtual bool HasObserver(const Observer* observer) const override { return observers_.HasObserver(observer); } + virtual bool IsScreenLocked() const override { return screen_is_locked_; } virtual void EmitLoginPromptVisible() override {} virtual void RestartJob(int pid, const std::string& command_line) override {} virtual void StartSession(const std::string& user_email) override {} @@ -608,9 +617,11 @@ class SessionManagerClientStubImpl : public SessionManagerClient { delegate_->LockScreenForStub(); } virtual void NotifyLockScreenShown() override { + screen_is_locked_ = true; FOR_EACH_OBSERVER(Observer, observers_, ScreenIsLocked()); } virtual void NotifyLockScreenDismissed() override { + screen_is_locked_ = false; FOR_EACH_OBSERVER(Observer, observers_, ScreenIsUnlocked()); } virtual void RetrieveActiveSessions( @@ -732,6 +743,7 @@ class SessionManagerClientStubImpl : public SessionManagerClient { StubDelegate* delegate_; // Weak pointer; may be NULL. ObserverList<Observer> observers_; std::string device_policy_; + bool screen_is_locked_; DISALLOW_COPY_AND_ASSIGN(SessionManagerClientStubImpl); }; diff --git a/chromeos/dbus/session_manager_client.h b/chromeos/dbus/session_manager_client.h index 758f26e..dd6048d 100644 --- a/chromeos/dbus/session_manager_client.h +++ b/chromeos/dbus/session_manager_client.h @@ -65,6 +65,11 @@ class CHROMEOS_EXPORT SessionManagerClient : public DBusClient { virtual void RemoveObserver(Observer* observer) = 0; virtual bool HasObserver(const Observer* observer) const = 0; + // Returns the most recent screen-lock state received from session_manager. + // This mirrors the last Observer::ScreenIsLocked() or ScreenIsUnlocked() + // call. + virtual bool IsScreenLocked() const = 0; + // Kicks off an attempt to emit the "login-prompt-visible" upstart signal. virtual void EmitLoginPromptVisible() = 0; |