Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / signin / easy_unlock_screenlock_state_handler.h
bloba86af96eb4d2c6726c22c729e0e6bb4dffa08467
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_
8 #include <string>
10 #include "base/strings/string16.h"
11 #include "base/timer/timer.h"
12 #include "chrome/browser/signin/screenlock_bridge.h"
14 class PrefService;
16 // Profile specific class responsible for updating screenlock UI for the user
17 // associated with the profile when their Easy Unlock state changes.
18 class EasyUnlockScreenlockStateHandler : public ScreenlockBridge::Observer {
19 public:
20 // Available Easy Unlock states.
21 enum State {
22 // Easy Unlock is not enabled, or the screen is not locked.
23 STATE_INACTIVE,
24 // Bluetooth is not on.
25 STATE_NO_BLUETOOTH,
26 // Easy Unlock is in process of turning on Bluetooth.
27 STATE_BLUETOOTH_CONNECTING,
28 // No phones eligible to unlock the device can be found.
29 STATE_NO_PHONE,
30 // A phone eligible to unlock the device is found, but cannot be
31 // authenticated.
32 STATE_PHONE_NOT_AUTHENTICATED,
33 // A phone eligible to unlock the device is found, but it's locked.
34 STATE_PHONE_LOCKED,
35 // A phone eligible to unlock the device is found, but does not have lock
36 // screen enabled.
37 STATE_PHONE_UNLOCKABLE,
38 // A phone eligible to unlock the device is found, but it's not close enough
39 // to be allowed to unlock the device.
40 STATE_PHONE_NOT_NEARBY,
41 // An Easy Unlock enabled phone is found, but it is not allowed to unlock
42 // the device because it does not support reporting it's lock screen state.
43 STATE_PHONE_UNSUPPORTED,
44 // The device can be unlocked using Easy Unlock.
45 STATE_AUTHENTICATED
48 // Hard lock states.
49 enum HardlockState {
50 NO_HARDLOCK = 0, // Hard lock is not enforced. This is default.
51 USER_HARDLOCK = 1 << 0, // Hard lock is requested by user.
52 PAIRING_CHANGED = 1 << 1, // Hard lock because pairing data is changed.
53 NO_PAIRING = 1 << 2 // Hard lock because there is no pairing data.
56 // |user_email|: The email for the user associated with the profile to which
57 // this class is attached.
58 // |initial_hardlock_state|: The initial hardlock state.
59 // |screenlock_bridge|: The screenlock bridge used to update the screen lock
60 // state.
61 EasyUnlockScreenlockStateHandler(const std::string& user_email,
62 HardlockState initial_hardlock_state,
63 ScreenlockBridge* screenlock_bridge);
64 virtual ~EasyUnlockScreenlockStateHandler();
66 // Returns true if handler is not in INACTIVE state.
67 bool IsActive() const;
69 // Changes internal state to |new_state| and updates the user's screenlock
70 // accordingly.
71 void ChangeState(State new_state);
73 // Updates the screenlock state.
74 void SetHardlockState(HardlockState new_state);
76 // Shows the hardlock UI if the hardlock_state_ is not NO_HARDLOCK.
77 void MaybeShowHardlockUI();
79 // Marks the current screenlock state as the one for trial Easy Unlock run.
80 void SetTrialRun();
82 private:
83 // ScreenlockBridge::Observer:
84 virtual void OnScreenDidLock() override;
85 virtual void OnScreenDidUnlock() override;
86 virtual void OnFocusedUserChanged(const std::string& user_id) override;
88 // Forces refresh of the Easy Unlock screenlock UI.
89 void RefreshScreenlockState();
91 void ShowHardlockUI();
93 // Updates icon's tooltip options.
94 // |trial_run|: Whether the trial Easy Unlock run is in progress.
95 void UpdateTooltipOptions(
96 bool trial_run,
97 ScreenlockBridge::UserPodCustomIconOptions* icon_options);
99 // Gets the name to be used for the device. The name depends on the device
100 // type (example values: Chromebook and Chromebox).
101 base::string16 GetDeviceName();
103 // Updates the screenlock auth type if it has to be changed.
104 void UpdateScreenlockAuthType();
106 State state_;
107 std::string user_email_;
108 ScreenlockBridge* screenlock_bridge_;
110 // State of hardlock.
111 HardlockState hardlock_state_;
112 bool hardlock_ui_shown_;
114 // Whether this is the trial Easy Unlock run. If this is the case, a
115 // tutorial message should be shown and hard-locking be disabled. The trial
116 // run should be set if the screen was locked by the Easy Unlock setup app.
117 bool is_trial_run_;
119 DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler);
122 #endif // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_