OLD | NEW |
---|---|
(Empty) | |
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 #include "base/bind.h" | |
6 #include "base/message_loop/message_loop.h" | |
7 #include "chrome/browser/chrome_notification_types.h" | |
8 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h" | |
9 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | |
10 #include "chrome/browser/signin/screenlock_bridge.h" | |
11 #include "chrome/grit/generated_resources.h" | |
12 #include "chromeos/dbus/dbus_thread_manager.h" | |
13 #include "chromeos/dbus/session_manager_client.h" | |
14 #include "chromeos/login/auth/auth_status_consumer.h" | |
15 #include "chromeos/login/auth/user_context.h" | |
16 #include "content/public/browser/notification_details.h" | |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 #include "content/public/browser/notification_service.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 | |
22 namespace chromeos { | |
23 | |
24 // Performs the actual reauth flow and returns the user context it obtains. | |
25 class EasyUnlockReauth::ReauthHandler : public content::NotificationObserver, | |
26 public chromeos::AuthStatusConsumer { | |
27 public: | |
28 explicit ReauthHandler(EasyUnlockReauth::UserContextCallback callback) | |
29 : callback_(callback) {} | |
30 | |
31 virtual ~ReauthHandler() {} | |
32 | |
33 bool Start() { | |
34 ScreenLocker* screen_locker = ScreenLocker::default_screen_locker(); | |
35 if (screen_locker && screen_locker->locked()) { | |
36 DCHECK(false) << "Screen should not be locked when attempting reauth."; | |
37 return false; | |
38 } | |
39 | |
40 // Only primary profile's can set up Easy Unlock right now. | |
tbarzic
2014/10/27 21:44:43
the comment doesn't really match the logic.
I don'
xiyuan
2014/10/28 20:38:03
Yep, let's do primary user check here since we onl
Tim Song
2014/10/31 17:57:37
Done.
| |
41 if (!user_manager::UserManager::Get()->CanCurrentUserLock()) { | |
42 DCHECK(false) << "Only primary users are currently supported for reauth."; | |
43 return false; | |
44 } | |
45 | |
46 notification_registrar_.Add(this, | |
47 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | |
48 content::NotificationService::AllSources()); | |
49 | |
50 SessionManagerClient* session_manager = | |
51 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); | |
52 session_manager->RequestLockScreen(); | |
53 return true; | |
54 } | |
55 | |
56 // content::NotificationObserver | |
57 void Observe(int type, | |
58 const content::NotificationSource& source, | |
59 const content::NotificationDetails& details) { | |
60 CHECK(type == chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED); | |
61 bool is_screen_locked = *content::Details<bool>(details).ptr(); | |
62 DCHECK(is_screen_locked); | |
63 notification_registrar_.RemoveAll(); | |
64 | |
65 // TODO(tengs): Add an explicit reauth state to the locker and account | |
66 // picker, so we can customize the UI. | |
67 ScreenLocker* screen_locker = ScreenLocker::default_screen_locker(); | |
68 screen_locker->SetLoginStatusConsumer(this); | |
69 | |
70 // Show tooltip explaining reauth. | |
71 ScreenlockBridge::UserPodCustomIconOptions icon_options; | |
72 icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE); | |
73 icon_options.SetTooltip( | |
74 l10n_util::GetStringUTF16( | |
75 IDS_SMART_LOCK_SCREENLOCK_TOOLTIP_HARDLOCK_REAUTH_USER), | |
76 true); | |
77 | |
78 const user_manager::UserList& lock_users = screen_locker->users(); | |
79 DCHECK(lock_users.size() == 1); | |
tbarzic
2014/10/27 21:44:43
I don't think this necessary holds
xiyuan
2014/10/28 20:38:03
We probably should pass in the reauth user and pic
Tim Song
2014/10/31 17:57:36
I plan on introducing a new Reauth state to the sc
| |
80 ScreenlockBridge::Get()->lock_handler()->ShowUserPodCustomIcon( | |
81 lock_users[0]->email(), icon_options); | |
82 } | |
83 | |
84 // chromeos::AuthStatusConsumer: | |
85 virtual void OnAuthSuccess( | |
86 const chromeos::UserContext& user_context) override { | |
87 callback_.Run(user_context); | |
88 // Schedule deletion. | |
89 base::MessageLoopForUI::current()->PostTask( | |
90 FROM_HERE, base::Bind(&EasyUnlockReauth::EndReauthAttempt)); | |
91 } | |
92 | |
93 virtual void OnAuthFailure(const chromeos::AuthFailure& error) override {} | |
94 | |
95 private: | |
96 content::NotificationRegistrar notification_registrar_; | |
97 EasyUnlockReauth::UserContextCallback callback_; | |
98 | |
99 DISALLOW_COPY_AND_ASSIGN(ReauthHandler); | |
100 }; | |
101 | |
102 EasyUnlockReauth::ReauthHandler* EasyUnlockReauth::reauth_handler_ = NULL; | |
103 | |
104 // static. | |
105 bool EasyUnlockReauth::ReauthForUserContext( | |
106 base::Callback<void(const UserContext&)> callback) { | |
107 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
108 if (reauth_handler_) | |
109 return false; | |
110 | |
111 reauth_handler_ = new ReauthHandler(callback); | |
112 return reauth_handler_->Start(); | |
113 } | |
114 | |
115 // static. | |
116 void EasyUnlockReauth::EndReauthAttempt() { | |
117 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
118 DCHECK(reauth_handler_); | |
119 if (reauth_handler_) | |
120 delete reauth_handler_; | |
121 reauth_handler_ = NULL; | |
122 } | |
123 | |
124 } // namespace chromeos | |
OLD | NEW |