1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_ 6 #define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_ 7 8 #include <string> 9 10 #include "base/lazy_instance.h" 11 #include "base/macros.h" 12 #include "base/observer_list.h" 13 14 namespace gfx { 15 class Image; 16 } 17 18 class Profile; 19 20 // ScreenlockBridge brings together the screenLockPrivate API and underlying 21 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other 22 // platforms, it delegates calls to UserManagerUI (and friends). 23 class ScreenlockBridge { 24 public: 25 class Observer { 26 public: 27 // Invoked after the screen is locked. 28 virtual void OnScreenDidLock() = 0; 29 // Invoked after the screen lock is dismissed. 30 virtual void OnScreenDidUnlock() = 0; 31 protected: ~Observer()32 virtual ~Observer() {} 33 }; 34 35 class LockHandler { 36 public: 37 // Supported authentication types. Keep in sync with the enum in 38 // user_pod_row.js. 39 enum AuthType { 40 OFFLINE_PASSWORD = 0, 41 ONLINE_SIGN_IN = 1, 42 NUMERIC_PIN = 2, 43 USER_CLICK = 3, 44 }; 45 46 // Displays |message| in a banner on the lock screen. 47 virtual void ShowBannerMessage(const std::string& message) = 0; 48 49 // Shows a custom icon in the user pod on the lock screen. 50 virtual void ShowUserPodCustomIcon(const std::string& user_email, 51 const gfx::Image& icon) = 0; 52 53 // Hides the custom icon in user pod for a user. 54 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0; 55 56 // (Re)enable lock screen UI. 57 virtual void EnableInput() = 0; 58 59 // Set the authentication type to be used on the lock screen. 60 virtual void SetAuthType(const std::string& user_email, 61 AuthType auth_type, 62 const std::string& auth_value) = 0; 63 64 // Returns the authentication type used for a user. 65 virtual AuthType GetAuthType(const std::string& user_email) const = 0; 66 67 // Unlock from easy unlock app for a user. 68 virtual void Unlock(const std::string& user_email) = 0; 69 70 protected: ~LockHandler()71 virtual ~LockHandler() {} 72 }; 73 74 static ScreenlockBridge* Get(); 75 static std::string GetAuthenticatedUserEmail(Profile* profile); 76 77 void SetLockHandler(LockHandler* lock_handler); 78 79 bool IsLocked() const; 80 void Lock(Profile* profile); 81 void Unlock(Profile* profile); 82 83 void AddObserver(Observer* observer); 84 void RemoveObserver(Observer* observer); 85 lock_handler()86 LockHandler* lock_handler() { return lock_handler_; } 87 88 private: 89 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>; 90 friend struct base::DefaultDeleter<ScreenlockBridge>; 91 92 ScreenlockBridge(); 93 ~ScreenlockBridge(); 94 95 LockHandler* lock_handler_; // Not owned 96 ObserverList<Observer, true> observers_; 97 98 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge); 99 }; 100 101 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_ 102