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_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
10 #include "base/strings/string16.h"
11 #include "chrome/browser/signin/screenlock_bridge.h"
15 // Profile specific class responsible for updating screenlock UI for the user
16 // associated with the profile when their Easy Unlock state changes.
17 class EasyUnlockScreenlockStateHandler
: public ScreenlockBridge::Observer
{
19 // Available Easy Unlock states.
21 // Easy Unlock is not enabled, or the screen is not locked.
23 // Bluetooth is not on.
25 // Easy Unlock is in process of turning on Bluetooth.
26 STATE_BLUETOOTH_CONNECTING
,
27 // No phones eligible to unlock the device can be found.
29 // A phone eligible to unlock the device is found, but cannot be
31 STATE_PHONE_NOT_AUTHENTICATED
,
32 // A phone eligible to unlock the device is found, but it's locked.
34 // A phone eligible to unlock the device is found, but does not have lock
36 STATE_PHONE_UNLOCKABLE
,
37 // A phone eligible to unlock the device is found, but it's not close enough
38 // to be allowed to unlock the device.
39 STATE_PHONE_NOT_NEARBY
,
40 // An Easy Unlock enabled phone is found, but it is not allowed to unlock
41 // the device because it does not support reporting it's lock screen state.
42 STATE_PHONE_UNSUPPORTED
,
43 // The device can be unlocked using Easy Unlock.
49 NO_HARDLOCK
= 0, // Hard lock is not enforced. This is default.
50 USER_HARDLOCK
= 1 << 0, // Hard lock is requested by user.
51 PAIRING_CHANGED
= 1 << 1, // Hard lock because pairing data is changed.
52 NO_PAIRING
= 1 << 2, // Hard lock because there is no pairing data.
53 LOGIN_FAILED
= 1 << 3 // Transient hard lock caused by login attempt
54 // failure. Reset when screen is unlocked.
57 // |user_email|: The email for the user associated with the profile to which
58 // this class is attached.
59 // |initial_hardlock_state|: The initial hardlock state.
60 // |screenlock_bridge|: The screenlock bridge used to update the screen lock
62 EasyUnlockScreenlockStateHandler(const std::string
& user_email
,
63 HardlockState initial_hardlock_state
,
64 ScreenlockBridge
* screenlock_bridge
);
65 ~EasyUnlockScreenlockStateHandler() override
;
67 // Returns true if handler is not in INACTIVE state.
68 bool IsActive() const;
70 // Whether the handler is in state that is allowed just after auth failure
71 // (i.e. the state that would cause auth failure rather than one caused by an
73 bool InStateValidOnRemoteAuthFailure() const;
75 // Changes internal state to |new_state| and updates the user's screenlock
77 void ChangeState(State new_state
);
79 // Updates the screenlock state.
80 void SetHardlockState(HardlockState new_state
);
82 // Shows the hardlock UI if the hardlock_state_ is not NO_HARDLOCK.
83 void MaybeShowHardlockUI();
85 // Marks the current screenlock state as the one for trial Easy Unlock run.
88 State
state() const { return state_
; }
91 // ScreenlockBridge::Observer:
92 void OnScreenDidLock() override
;
93 void OnScreenDidUnlock() override
;
94 void OnFocusedUserChanged(const std::string
& user_id
) override
;
96 // Forces refresh of the Easy Unlock screenlock UI.
97 void RefreshScreenlockState();
99 void ShowHardlockUI();
101 // Updates icon's tooltip options.
102 // |trial_run|: Whether the trial Easy Unlock run is in progress.
103 void UpdateTooltipOptions(
105 ScreenlockBridge::UserPodCustomIconOptions
* icon_options
);
107 // Gets the name to be used for the device. The name depends on the device
108 // type (example values: Chromebook and Chromebox).
109 base::string16
GetDeviceName();
111 // Updates the screenlock auth type if it has to be changed.
112 void UpdateScreenlockAuthType();
115 std::string user_email_
;
116 ScreenlockBridge
* screenlock_bridge_
;
118 // State of hardlock.
119 HardlockState hardlock_state_
;
120 bool hardlock_ui_shown_
;
122 // Whether this is the trial Easy Unlock run. If this is the case, a
123 // tutorial message should be shown and hard-locking be disabled. The trial
124 // run should be set if the screen was locked by the Easy Unlock setup app.
127 DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler
);
130 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_