359b09b5a253dfe46e3debaca4d248d0294b8b1c
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / easy_unlock_screenlock_state_handler.h
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_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
6 #define CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_
7
8 #include <string>
9
10 #include "base/strings/string16.h"
11 #include "base/timer/timer.h"
12 #include "chrome/browser/signin/screenlock_bridge.h"
13
14 class PrefService;
15
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
46   };
47
48   // |user_email|: The email for the user associated with the profile to which
49   //     this class is attached.
50   // |pref_service|: The profile preferences.
51   // |screenlock_bridge|: The screenlock bridge used to update the screen lock
52   //     state.
53   EasyUnlockScreenlockStateHandler(const std::string& user_email,
54                                    PrefService* pref_service,
55                                    ScreenlockBridge* screenlock_bridge);
56   virtual ~EasyUnlockScreenlockStateHandler();
57
58   // Changes internal state to |new_state| and updates the user's screenlock
59   // accordingly.
60   void ChangeState(State new_state);
61
62  private:
63   // ScreenlockBridge::Observer:
64   virtual void OnScreenDidLock() OVERRIDE;
65   virtual void OnScreenDidUnlock() OVERRIDE;
66   virtual void OnFocusedUserChanged(const std::string& user_id) OVERRIDE;
67
68   // Updates icon's tooltip options.
69   // |trial_run|: Whether the trial Easy Unlock run is in progress.
70   void UpdateTooltipOptions(
71       bool trial_run,
72       ScreenlockBridge::UserPodCustomIconOptions* icon_options);
73
74   // Whether this is the first, trial Easy Unlock run. If this is the case, a
75   // tutorial message should be shown and hard-locking be disabled in
76   // Authenticated state. The trial run will be active if Easy Unlock never
77   // entered Authenticated state (across sessions).
78   bool IsTrialRun();
79
80   // Sets user preference that marks trial run completed.
81   void MarkTrialRunComplete();
82
83   // Gets the name to be used for the device. The name depends on the device
84   // type (example values: Chromebook and Chromebox).
85   base::string16 GetDeviceName();
86
87   // Updates the screenlock auth type if it has to be changed.
88   void UpdateScreenlockAuthType();
89
90   State state_;
91   std::string user_email_;
92   PrefService* pref_service_;
93   ScreenlockBridge* screenlock_bridge_;
94
95   DISALLOW_COPY_AND_ASSIGN(EasyUnlockScreenlockStateHandler);
96 };
97
98 #endif  // CHROME_BROWSER_SIGNIN_EASY_UNLOCK_SCREENLOCK_STATE_HANDLER_H_