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.
5 #ifndef CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
6 #define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
10 #include "base/basictypes.h"
11 #include "base/lazy_instance.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "base/strings/string16.h"
16 #include "base/values.h"
21 // ScreenlockBridge brings together the screenLockPrivate API and underlying
22 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
23 // platforms, it delegates calls to UserManagerUI (and friends).
24 // TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
25 // used solely for the lock screen anymore.
26 class ScreenlockBridge
{
30 // Invoked after the screen is locked.
31 virtual void OnScreenDidLock() = 0;
32 // Invoked after the screen lock is dismissed.
33 virtual void OnScreenDidUnlock() = 0;
34 // Invoked when the user focused on the lock screen changes.
35 virtual void OnFocusedUserChanged(const std::string
& user_id
) = 0;
37 virtual ~Observer() {}
40 // User pod icons supported by lock screen / signin screen UI.
41 enum UserPodCustomIcon
{
42 USER_POD_CUSTOM_ICON_NONE
,
43 USER_POD_CUSTOM_ICON_HARDLOCKED
,
44 USER_POD_CUSTOM_ICON_LOCKED
,
45 USER_POD_CUSTOM_ICON_UNLOCKED
,
46 USER_POD_CUSTOM_ICON_SPINNER
49 // Class containing parameters describing the custom icon that should be
50 // shown on a user's screen lock pod next to the input field.
51 class UserPodCustomIconOptions
{
53 UserPodCustomIconOptions();
54 ~UserPodCustomIconOptions();
56 // Converts parameters to a dictionary values that can be sent to the
58 scoped_ptr
<base::DictionaryValue
> ToDictionaryValue() const;
60 // Sets the icon that should be shown in the UI.
61 void SetIcon(UserPodCustomIcon icon
);
63 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
64 // shown with the icon.
65 void SetTooltip(const base::string16
& tooltip
, bool autoshow
);
67 // If hardlock on click is set, clicking the icon in the screenlock will
68 // go to state where password is required for unlock.
69 void SetHardlockOnClick();
72 UserPodCustomIcon icon_
;
74 base::string16 tooltip_
;
75 bool autoshow_tooltip_
;
77 bool hardlock_on_click_
;
79 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions
);
84 // Supported authentication types. Keep in sync with the enum in
91 EXPAND_THEN_USER_CLICK
= 4,
92 FORCE_OFFLINE_PASSWORD
= 5
95 // Displays |message| in a banner on the lock screen.
96 virtual void ShowBannerMessage(const base::string16
& message
) = 0;
98 // Shows a custom icon in the user pod on the lock screen.
99 virtual void ShowUserPodCustomIcon(
100 const std::string
& user_email
,
101 const UserPodCustomIconOptions
& icon
) = 0;
103 // Hides the custom icon in user pod for a user.
104 virtual void HideUserPodCustomIcon(const std::string
& user_email
) = 0;
106 // (Re)enable lock screen UI.
107 virtual void EnableInput() = 0;
109 // Set the authentication type to be used on the lock screen.
110 virtual void SetAuthType(const std::string
& user_email
,
112 const base::string16
& auth_value
) = 0;
114 // Returns the authentication type used for a user.
115 virtual AuthType
GetAuthType(const std::string
& user_email
) const = 0;
117 // Unlock from easy unlock app for a user.
118 virtual void Unlock(const std::string
& user_email
) = 0;
120 // Attempts to login the user using an easy unlock key.
121 virtual void AttemptEasySignin(const std::string
& user_email
,
122 const std::string
& secret
,
123 const std::string
& key_label
) = 0;
126 virtual ~LockHandler() {}
129 static ScreenlockBridge
* Get();
130 static std::string
GetAuthenticatedUserEmail(Profile
* profile
);
132 void SetLockHandler(LockHandler
* lock_handler
);
133 void SetFocusedUser(const std::string
& user_id
);
135 bool IsLocked() const;
136 void Lock(Profile
* profile
);
137 void Unlock(Profile
* profile
);
139 void AddObserver(Observer
* observer
);
140 void RemoveObserver(Observer
* observer
);
142 LockHandler
* lock_handler() { return lock_handler_
; }
144 std::string
focused_user_id() const { return focused_user_id_
; }
147 friend struct base::DefaultLazyInstanceTraits
<ScreenlockBridge
>;
148 friend struct base::DefaultDeleter
<ScreenlockBridge
>;
153 LockHandler
* lock_handler_
; // Not owned
154 // The last focused user's id.
155 std::string focused_user_id_
;
156 ObserverList
<Observer
, true> observers_
;
158 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge
);
161 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_