Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / screenlock_bridge.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_SCREENLOCK_BRIDGE_H_
6 #define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
7
8 #include "base/callback_forward.h"
9 #include "base/lazy_instance.h"
10 #include "base/macros.h"
11 #include "base/observer_list.h"
12
13 namespace gfx {
14 class Image;
15 }
16
17 class Profile;
18
19 // ScreenlockBridge brings together the screenLockPrivate API and underlying
20 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
21 // platforms, it delegates calls to UserManagerUI (and friends).
22 class ScreenlockBridge {
23  public:
24   class Observer {
25    public:
26     // Invoked after the screen is locked.
27     virtual void OnScreenDidLock() = 0;
28     // Invoked after the screen lock is dismissed.
29     virtual void OnScreenDidUnlock() = 0;
30    protected:
31     virtual ~Observer() {}
32   };
33
34   class LockHandler {
35    public:
36     // Supported authentication types. Keep in sync with the enum in
37     // user_pod_row.js.
38     enum AuthType {
39       OFFLINE_PASSWORD = 0,
40       ONLINE_SIGN_IN = 1,
41       NUMERIC_PIN = 2,
42       USER_CLICK = 3,
43     };
44
45     // Displays |message| in a banner on the lock screen.
46     virtual void ShowBannerMessage(const std::string& message) = 0;
47
48     // Shows a button inside the user pod on the lock screen with an icon.
49     // |callback| is invoked when the icon is clicked. This is deprecated now.
50     virtual void ShowUserPodButton(const std::string& user_email,
51                                    const gfx::Image& icon,
52                                    const base::Closure& callback) = 0;
53
54     // Hides the user pod button for a user.
55     virtual void HideUserPodButton(const std::string& user_email) = 0;
56
57     // (Re)enable lock screen UI.
58     virtual void EnableInput() = 0;
59
60     // Set the authentication type to be used on the lock screen.
61     virtual void SetAuthType(const std::string& user_email,
62                              AuthType auth_type,
63                              const std::string& auth_value) = 0;
64
65     // Returns the authentication type used for a user.
66     virtual AuthType GetAuthType(const std::string& user_email) const = 0;
67
68     // Unlock from easy unlock app for a user.
69     virtual void Unlock(const std::string& user_email) = 0;
70
71    protected:
72     virtual ~LockHandler() {}
73   };
74
75   static ScreenlockBridge* Get();
76   static std::string GetAuthenticatedUserEmail(Profile* profile);
77
78   void SetLockHandler(LockHandler* lock_handler);
79
80   bool IsLocked() const;
81   void Lock(Profile* profile);
82   void Unlock(Profile* profile);
83
84   void AddObserver(Observer* observer);
85   void RemoveObserver(Observer* observer);
86
87   LockHandler* lock_handler() { return lock_handler_; }
88
89  private:
90   friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
91   friend struct base::DefaultDeleter<ScreenlockBridge>;
92
93   ScreenlockBridge();
94   ~ScreenlockBridge();
95
96   LockHandler* lock_handler_;  // Not owned
97   ObserverList<Observer, true> observers_;
98
99   DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
100 };
101
102 #endif  // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_