Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(570)

Side by Side Diff: chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.cc

Issue 668213003: Reauthenticate the user before launching Smart Lock setup app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bind user context to lifetime of setup app Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 namespace {
25
26 void EndReauthAttempt();
27
28 // Performs the actual reauth flow and returns the user context it obtains.
29 class ReauthHandler : public content::NotificationObserver,
30 public chromeos::AuthStatusConsumer {
31 public:
32 explicit ReauthHandler(EasyUnlockReauth::UserContextCallback callback)
33 : callback_(callback) {}
34
35 virtual ~ReauthHandler() {}
36
37 bool Start() {
38 ScreenLocker* screen_locker = ScreenLocker::default_screen_locker();
39 if (screen_locker && screen_locker->locked()) {
40 DCHECK(false) << "Screen should not be locked when attempting reauth.";
tbarzic 2014/11/01 23:21:44 notreached instead of DCHECK(false)
Tim Song 2014/11/03 19:10:43 Done.
41 return false;
42 }
43
44 // Only primary profile's can set up Easy Unlock right now.
tbarzic 2014/11/01 23:21:44 s/profile's/user
Tim Song 2014/11/03 19:10:43 Done.
45 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
46 if (user_manager->GetPrimaryUser() != user_manager->GetActiveUser() ||
47 user_manager->GetUnlockUsers().size() != 1) {
48 DCHECK(false) << "Only primary users in non-multiprofile sessions are "
tbarzic 2014/10/31 18:24:09 no DCHECK; afaik this is realistic possibility.
Tim Song 2014/11/01 03:16:52 This should be rare, so let's fall back to the har
xiyuan 2014/11/01 03:51:37 I think Toni meant to replace the DCHECK with a LO
Tim Song 2014/11/01 04:57:39 Done. Sorry, I misread this comment.
49 << "currently supported for reauth.";
50 return false;
51 }
52
53 notification_registrar_.Add(this,
54 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
55 content::NotificationService::AllSources());
56
57 SessionManagerClient* session_manager =
58 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
59 session_manager->RequestLockScreen();
60 return true;
61 }
62
63 // content::NotificationObserver
64 void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) {
67 CHECK(type == chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED);
68 bool is_screen_locked = *content::Details<bool>(details).ptr();
69 DCHECK(is_screen_locked);
70 notification_registrar_.RemoveAll();
71
72 // TODO(tengs): Add an explicit reauth state to the locker and account
73 // picker, so we can customize the UI.
74 ScreenLocker* screen_locker = ScreenLocker::default_screen_locker();
75 screen_locker->SetLoginStatusConsumer(this);
76
77 // Show tooltip explaining reauth.
78 ScreenlockBridge::UserPodCustomIconOptions icon_options;
79 icon_options.SetIcon(ScreenlockBridge::USER_POD_CUSTOM_ICON_NONE);
80 icon_options.SetTooltip(
81 l10n_util::GetStringUTF16(
82 IDS_SMART_LOCK_SCREENLOCK_TOOLTIP_HARDLOCK_REAUTH_USER),
83 true);
84
85 const user_manager::UserList& lock_users = screen_locker->users();
86 DCHECK(lock_users.size() == 1);
87 ScreenlockBridge::Get()->lock_handler()->ShowUserPodCustomIcon(
88 lock_users[0]->email(), icon_options);
89 }
90
91 // chromeos::AuthStatusConsumer:
92 virtual void OnAuthSuccess(
93 const chromeos::UserContext& user_context) override {
94 callback_.Run(user_context);
95 // Schedule deletion.
96 base::MessageLoopForUI::current()->PostTask(FROM_HERE,
97 base::Bind(&EndReauthAttempt));
98 }
99
100 virtual void OnAuthFailure(const chromeos::AuthFailure& error) override {}
101
102 private:
103 content::NotificationRegistrar notification_registrar_;
104 EasyUnlockReauth::UserContextCallback callback_;
105
106 DISALLOW_COPY_AND_ASSIGN(ReauthHandler);
107 };
108
109 ReauthHandler* g_reauth_handler = NULL;
110
111 void EndReauthAttempt() {
112 DCHECK(base::MessageLoopForUI::IsCurrent());
113 DCHECK(g_reauth_handler);
114 if (g_reauth_handler)
115 delete g_reauth_handler;
116 g_reauth_handler = NULL;
117 }
118
119 } // namespace
120
121 // static.
122 bool EasyUnlockReauth::ReauthForUserContext(
123 base::Callback<void(const UserContext&)> callback) {
124 DCHECK(base::MessageLoopForUI::IsCurrent());
125 if (g_reauth_handler)
126 return false;
127
128 g_reauth_handler = new ReauthHandler(callback);
129 return g_reauth_handler->Start();
130 }
131
132 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698