Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Unified Diff: chrome/browser/chromeos/cros/screen_lock_library.cc

Issue 3076029: Allow chrome for cros to be started with a username / password (Closed)
Patch Set: Only declare StubLogin on cros builds Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/cros/screen_lock_library.cc
diff --git a/chrome/browser/chromeos/cros/screen_lock_library.cc b/chrome/browser/chromeos/cros/screen_lock_library.cc
index 731ec438d72738bf4d1d0b542f4e17b9ba87ed50..011568328c8851e2a65d178c8911682c219a3d06 100644
--- a/chrome/browser/chromeos/cros/screen_lock_library.cc
+++ b/chrome/browser/chromeos/cros/screen_lock_library.cc
@@ -9,135 +9,170 @@
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
-// Allows InvokeLater without adding refcounting. This class is a Singleton and
-// won't be deleted until it's last InvokeLater is run.
-DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ScreenLockLibraryImpl);
-
namespace chromeos {
-ScreenLockLibraryImpl::ScreenLockLibraryImpl() {
- if (CrosLibrary::Get()->EnsureLoaded()) {
- Init();
+// This class handles the interaction with the ChromeOS screen lock APIs.
+class ScreenLockLibraryImpl : public ScreenLockLibrary {
+ public:
+ ScreenLockLibraryImpl() {
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ Init();
+ }
}
-}
-ScreenLockLibraryImpl::~ScreenLockLibraryImpl() {
- if (screen_lock_connection_) {
- chromeos::DisconnectScreenLock(screen_lock_connection_);
+ ~ScreenLockLibraryImpl() {
+ if (screen_lock_connection_) {
+ chromeos::DisconnectScreenLock(screen_lock_connection_);
+ }
}
-}
-void ScreenLockLibraryImpl::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
+ void AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+ }
-void ScreenLockLibraryImpl::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
+ void RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+ }
-void ScreenLockLibraryImpl::NotifyScreenLockRequested() {
- // Make sure we run on IO thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &ScreenLockLibraryImpl::NotifyScreenLockRequested));
- return;
+ void NotifyScreenLockRequested() {
+ // Make sure we run on IO thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &ScreenLockLibraryImpl::NotifyScreenLockRequested));
+ return;
+ }
+ chromeos::NotifyScreenLockRequested();
}
- chromeos::NotifyScreenLockRequested();
-}
-void ScreenLockLibraryImpl::NotifyScreenLockCompleted() {
- // Make sure we run on IO thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &ScreenLockLibraryImpl::NotifyScreenLockCompleted));
- return;
+ void NotifyScreenLockCompleted() {
+ // Make sure we run on IO thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &ScreenLockLibraryImpl::NotifyScreenLockCompleted));
+ return;
+ }
+ chromeos::NotifyScreenLockCompleted();
}
- chromeos::NotifyScreenLockCompleted();
-}
-void ScreenLockLibraryImpl::NotifyScreenUnlockRequested() {
- // Make sure we run on IO thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &ScreenLockLibraryImpl::NotifyScreenUnlockRequested));
- return;
+ void NotifyScreenUnlockRequested() {
+ // Make sure we run on IO thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &ScreenLockLibraryImpl::NotifyScreenUnlockRequested));
+ return;
+ }
+ chromeos::NotifyScreenUnlockRequested();
}
- chromeos::NotifyScreenUnlockRequested();
-}
-void ScreenLockLibraryImpl::NotifyScreenUnlockCompleted() {
- // Make sure we run on IO thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &ScreenLockLibraryImpl::NotifyScreenUnlockCompleted));
- return;
+ void NotifyScreenUnlockCompleted() {
+ // Make sure we run on IO thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &ScreenLockLibraryImpl::NotifyScreenUnlockCompleted));
+ return;
+ }
+ chromeos::NotifyScreenUnlockCompleted();
}
- chromeos::NotifyScreenUnlockCompleted();
-}
-void ScreenLockLibraryImpl::Init() {
- screen_lock_connection_ = chromeos::MonitorScreenLock(
- &ScreenLockedHandler, this);
-}
+ private:
+ void Init() {
+ screen_lock_connection_ = chromeos::MonitorScreenLock(
+ &ScreenLockedHandler, this);
+ }
-void ScreenLockLibraryImpl::LockScreen() {
- // Make sure we run on UI thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen));
- return;
+ void LockScreen() {
+ // Make sure we run on UI thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen));
+ return;
+ }
+ FOR_EACH_OBSERVER(Observer, observers_, LockScreen(this));
}
- FOR_EACH_OBSERVER(Observer, observers_, LockScreen(this));
-}
-void ScreenLockLibraryImpl::UnlockScreen() {
- // Make sure we run on UI thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreen));
- return;
+ void UnlockScreen() {
+ // Make sure we run on UI thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreen));
+ return;
+ }
+ FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen(this));
}
- FOR_EACH_OBSERVER(Observer, observers_, UnlockScreen(this));
-}
-void ScreenLockLibraryImpl::UnlockScreenFailed() {
- // Make sure we run on UI thread.
- if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
- ChromeThread::PostTask(
- ChromeThread::UI, FROM_HERE,
- NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreenFailed));
- return;
+ void UnlockScreenFailed() {
+ // Make sure we run on UI thread.
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &ScreenLockLibraryImpl::UnlockScreenFailed));
+ return;
+ }
+ FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed(this));
}
- FOR_EACH_OBSERVER(Observer, observers_, UnlockScreenFailed(this));
-}
-// static
-void ScreenLockLibraryImpl::ScreenLockedHandler(void* object,
- ScreenLockEvent event) {
- ScreenLockLibraryImpl* self = static_cast<ScreenLockLibraryImpl*>(object);
- switch (event) {
- case chromeos::LockScreen:
- self->LockScreen();
- break;
- case chromeos::UnlockScreen:
- self->UnlockScreen();
- break;
- case chromeos::UnlockScreenFailed:
- self->UnlockScreenFailed();
- break;
- default:
- NOTREACHED();
+ static void ScreenLockedHandler(void* object, ScreenLockEvent event) {
+ ScreenLockLibraryImpl* self = static_cast<ScreenLockLibraryImpl*>(object);
+ switch (event) {
+ case chromeos::LockScreen:
+ self->LockScreen();
+ break;
+ case chromeos::UnlockScreen:
+ self->UnlockScreen();
+ break;
+ case chromeos::UnlockScreenFailed:
+ self->UnlockScreenFailed();
+ break;
+ default:
+ NOTREACHED();
+ }
}
+
+ ObserverList<Observer> observers_;
+
+ // A reference to the screen lock api
+ chromeos::ScreenLockConnection screen_lock_connection_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScreenLockLibraryImpl);
+};
+
+class ScreenLockLibraryStubImpl : public ScreenLockLibrary {
+ public:
+ ScreenLockLibraryStubImpl() {}
+ ~ScreenLockLibraryStubImpl() {}
+ void AddObserver(Observer* observer) {}
+ void RemoveObserver(Observer* observer) {}
+ void NotifyScreenLockRequested() {}
+ void NotifyScreenLockCompleted() {}
+ void NotifyScreenUnlockRequested() {}
+ void NotifyScreenUnlockCompleted() {}
+};
+
+// static
+ScreenLockLibrary* ScreenLockLibrary::GetImpl(bool stub) {
+ if (stub)
+ return new ScreenLockLibraryStubImpl();
+ else
+ return new ScreenLockLibraryImpl();
}
} // namespace chromeos
+
+// Allows InvokeLater without adding refcounting. This class is a Singleton and
+// won't be deleted until it's last InvokeLater is run.
+DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ScreenLockLibraryImpl);
+
« no previous file with comments | « chrome/browser/chromeos/cros/screen_lock_library.h ('k') | chrome/browser/chromeos/cros/speech_synthesis_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698