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

Side by Side Diff: chrome/browser/ui/views/profiles/forced_reauthentication_dialog.cc

Issue 2944713003: After signin token check failed, show force reauth dialog and start window closing countdown. (Closed)
Patch Set: rebase from master Created 3 years, 6 months 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/profiles/forced_reauthentication_dialog.h" 5 #include "chrome/browser/ui/views/profiles/forced_reauthentication_dialog.h"
6 6
7 #include <map>
7 #include <memory> 8 #include <memory>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/i18n/message_formatter.h" 12 #include "base/i18n/message_formatter.h"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_dialogs.h"
16 #include "chrome/browser/ui/browser_list.h" 18 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 19 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" 20 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/views/frame/browser_view.h" 22 #include "chrome/browser/ui/views/frame/browser_view.h"
21 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" 23 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
22 #include "chrome/grit/chromium_strings.h" 24 #include "chrome/grit/chromium_strings.h"
23 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
24 #include "components/constrained_window/constrained_window_views.h" 26 #include "components/constrained_window/constrained_window_views.h"
25 #include "components/signin/core/browser/signin_manager.h" 27 #include "components/signin/core/browser/signin_manager.h"
26 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/views/background.h" 29 #include "ui/views/background.h"
28 #include "ui/views/border.h" 30 #include "ui/views/border.h"
29 #include "ui/views/controls/styled_label.h" 31 #include "ui/views/controls/styled_label.h"
30 #include "ui/views/layout/grid_layout.h" 32 #include "ui/views/layout/grid_layout.h"
31 #include "ui/views/view.h" 33 #include "ui/views/view.h"
32 #include "ui/views/window/dialog_client_view.h" 34 #include "ui/views/window/dialog_client_view.h"
33 35
34 namespace { 36 namespace {
35 37
36 // Refresh title of the dialog every second. 38 // Refresh title of the dialog every second.
37 constexpr int kRefreshTitleTimer = 1; 39 constexpr int kRefreshTitleTimer = 1;
38 40
41 base::LazyInstance<std::map<Profile*, ForcedReauthenticationDialog*>>::
42 DestructorAtExit g_dialogs = LAZY_INSTANCE_INITIALIZER;
43
39 // If browser windows are going to be closed soon, close browser window before 44 // If browser windows are going to be closed soon, close browser window before
40 // showing sign in dialog because there might not be enough time for user to 45 // showing sign in dialog because there might not be enough time for user to
41 // finish sign in. 46 // finish sign in.
42 constexpr int kCloseDirectlyTimer = 60; 47 constexpr int kCloseDirectlyTimer = 60;
43 48
44 void Signout(SigninManager* signin_manager) { 49 void Signout(SigninManager* signin_manager) {
45 signin_manager->SignOut( 50 signin_manager->SignOut(
46 signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN, 51 signin_metrics::AUTHENTICATION_FAILED_WITH_FORCE_SIGNIN,
47 signin_metrics::SignoutDelete::KEEPING); 52 signin_metrics::SignoutDelete::KEEPING);
48 } 53 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 : browser_(browser), 94 : browser_(browser),
90 signin_manager_(signin_manager), 95 signin_manager_(signin_manager),
91 desired_close_time_(base::TimeTicks::Now() + countdown_duration) { 96 desired_close_time_(base::TimeTicks::Now() + countdown_duration) {
92 constrained_window::CreateBrowserModalDialogViews( 97 constrained_window::CreateBrowserModalDialogViews(
93 this, browser->window()->GetNativeWindow()) 98 this, browser->window()->GetNativeWindow())
94 ->Show(); 99 ->Show();
95 browser->window()->FlashFrame(true); 100 browser->window()->FlashFrame(true);
96 browser->window()->Activate(); 101 browser->window()->Activate();
97 } 102 }
98 103
99 ForcedReauthenticationDialog::~ForcedReauthenticationDialog() {} 104 ForcedReauthenticationDialog::~ForcedReauthenticationDialog() {
105 g_dialogs.Get().erase(browser_->profile());
106 }
100 107
101 // static 108 // static
102 ForcedReauthenticationDialog* ForcedReauthenticationDialog::ShowDialog( 109 ForcedReauthenticationDialog* ForcedReauthenticationDialog::ShowDialog(
103 Profile* profile, 110 Profile* profile,
104 SigninManager* signin_manager, 111 SigninManager* signin_manager,
105 const base::TimeDelta& countdown_duration) { 112 const base::TimeDelta& countdown_duration) {
106 Browser* browser = FindBrowserWithProfile(profile); 113 Browser* browser = FindBrowserWithProfile(profile);
107 if (browser == nullptr) { // If there is no browser, we can just sign 114 if (browser == nullptr) { // If there is no browser, we can just sign
108 // out profile directly. 115 // out profile directly.
109 Signout(signin_manager); 116 Signout(signin_manager);
110 return nullptr; 117 return nullptr;
111 } 118 }
112 119
113 return new ForcedReauthenticationDialog(browser, signin_manager, 120 ForcedReauthenticationDialog* dialog = new ForcedReauthenticationDialog(
114 countdown_duration); 121 browser, signin_manager, countdown_duration);
122 g_dialogs.Get()[profile] = dialog;
123 return dialog;
115 } 124 }
116 125
117 bool ForcedReauthenticationDialog::Accept() { 126 bool ForcedReauthenticationDialog::Accept() {
118 if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) { 127 if (GetTimeRemaining() < base::TimeDelta::FromSeconds(kCloseDirectlyTimer)) {
119 Signout(signin_manager_); 128 Signout(signin_manager_);
120 } else { 129 } else {
121 browser_->signin_view_controller()->ShowModalSignin( 130 browser_->signin_view_controller()->ShowModalSignin(
122 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_, 131 profiles::BubbleViewMode::BUBBLE_VIEW_MODE_GAIA_REAUTH, browser_,
123 signin_metrics::AccessPoint::ACCESS_POINT_FORCE_SIGNIN_WARNING); 132 signin_metrics::AccessPoint::ACCESS_POINT_FORCE_SIGNIN_WARNING);
124 } 133 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 250 }
242 GetWidget()->UpdateWindowTitle(); 251 GetWidget()->UpdateWindowTitle();
243 } 252 }
244 253
245 base::TimeDelta ForcedReauthenticationDialog::GetTimeRemaining() const { 254 base::TimeDelta ForcedReauthenticationDialog::GetTimeRemaining() const {
246 base::TimeTicks now = base::TimeTicks::Now(); 255 base::TimeTicks now = base::TimeTicks::Now();
247 if (desired_close_time_ <= now) 256 if (desired_close_time_ <= now)
248 return base::TimeDelta(); 257 return base::TimeDelta();
249 return desired_close_time_ - now; 258 return desired_close_time_ - now;
250 } 259 }
260
261 namespace chrome {
262 void ShowForcedReauthenticationDialog(
263 Profile* profile,
264 SigninManager* signin_manager,
265 const base::TimeDelta& countdown_duration) {
266 ForcedReauthenticationDialog::ShowDialog(profile, signin_manager,
267 countdown_duration);
268 }
269
270 void HideForcedReauthenticationDialog(Profile* profile) {
271 auto it = g_dialogs.Get().find(profile);
272 if (it != g_dialogs.Get().end()) {
273 it->second->GetWidget()->Close();
274 }
275 }
276
277 } // namespace chrome
OLDNEW
« chrome/browser/ui/browser_dialogs.h ('K') | « chrome/browser/ui/browser_dialogs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698