Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/cros/screen_lock_library.h" | 5 #include "chrome/browser/chromeos/cros/screen_lock_library.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 9 #include "base/observer_list.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
| 12 #include "third_party/cros/chromeos_screen_lock.h" | |
| 11 | 13 |
| 12 namespace chromeos { | 14 namespace chromeos { |
| 13 | 15 |
| 14 // This class handles the interaction with the ChromeOS screen lock APIs. | |
| 15 class ScreenLockLibraryImpl : public ScreenLockLibrary { | 16 class ScreenLockLibraryImpl : public ScreenLockLibrary { |
| 16 public: | 17 public: |
| 17 ScreenLockLibraryImpl() { | 18 ScreenLockLibraryImpl() { |
| 18 if (CrosLibrary::Get()->EnsureLoaded()) { | 19 if (CrosLibrary::Get()->EnsureLoaded()) |
| 19 Init(); | 20 Init(); |
| 20 } | |
| 21 } | 21 } |
| 22 | 22 |
| 23 ~ScreenLockLibraryImpl() { | 23 ~ScreenLockLibraryImpl() { |
| 24 if (screen_lock_connection_) { | 24 if (screen_lock_connection_) |
| 25 chromeos::DisconnectScreenLock(screen_lock_connection_); | 25 chromeos::DisconnectScreenLock(screen_lock_connection_); |
|
tfarina
2011/07/28 00:10:52
After disconnecting, the PowerLibraryImpl sets its
| |
| 26 } | |
| 27 } | 26 } |
| 28 | 27 |
| 29 void AddObserver(Observer* observer) { | 28 void AddObserver(Observer* observer) { |
| 30 observers_.AddObserver(observer); | 29 observers_.AddObserver(observer); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void RemoveObserver(Observer* observer) { | 32 void RemoveObserver(Observer* observer) { |
| 34 observers_.RemoveObserver(observer); | 33 observers_.RemoveObserver(observer); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void NotifyScreenLockRequested() { | 36 void NotifyScreenLockRequested() { |
| 38 chromeos::NotifyScreenLockRequested(); | 37 chromeos::NotifyScreenLockRequested(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void NotifyScreenLockCompleted() { | 40 void NotifyScreenLockCompleted() { |
| 42 chromeos::NotifyScreenLockCompleted(); | 41 chromeos::NotifyScreenLockCompleted(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void NotifyScreenUnlockRequested() { | 44 void NotifyScreenUnlockRequested() { |
| 46 chromeos::NotifyScreenUnlockRequested(); | 45 chromeos::NotifyScreenUnlockRequested(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void NotifyScreenUnlockCompleted() { | 48 void NotifyScreenUnlockCompleted() { |
| 50 chromeos::NotifyScreenUnlockCompleted(); | 49 chromeos::NotifyScreenUnlockCompleted(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 private: | 52 private: |
| 54 void Init() { | 53 void Init() { |
| 55 screen_lock_connection_ = chromeos::MonitorScreenLock( | 54 screen_lock_connection_ = |
| 56 &ScreenLockedHandler, this); | 55 chromeos::MonitorScreenLock(&ScreenLockedHandler, this); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void LockScreen() { | 58 void LockScreen() { |
| 60 // Make sure we run on UI thread. | 59 // Make sure we run on UI thread. |
| 61 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 60 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 62 BrowserThread::PostTask( | 61 BrowserThread::PostTask( |
| 63 BrowserThread::UI, FROM_HERE, | 62 BrowserThread::UI, FROM_HERE, |
| 64 NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen)); | 63 NewRunnableMethod(this, &ScreenLockLibraryImpl::LockScreen)); |
| 65 return; | 64 return; |
| 66 } | 65 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 return new ScreenLockLibraryStubImpl(); | 131 return new ScreenLockLibraryStubImpl(); |
| 133 else | 132 else |
| 134 return new ScreenLockLibraryImpl(); | 133 return new ScreenLockLibraryImpl(); |
| 135 } | 134 } |
| 136 | 135 |
| 137 } // namespace chromeos | 136 } // namespace chromeos |
| 138 | 137 |
| 139 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 138 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
| 140 // won't be deleted until it's last InvokeLater is run. | 139 // won't be deleted until it's last InvokeLater is run. |
| 141 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ScreenLockLibraryImpl); | 140 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::ScreenLockLibraryImpl); |
| OLD | NEW |