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

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: delegate 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"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/forced_reauthentication_dialog_delegate.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"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 return ChromeLayoutProvider::Get()->GetInsetsMetric( 80 return ChromeLayoutProvider::Get()->GetInsetsMetric(
79 views::INSETS_DIALOG_CONTENTS); 81 views::INSETS_DIALOG_CONTENTS);
80 } 82 }
81 }; 83 };
82 84
83 } // namespace 85 } // namespace
84 86
85 ForcedReauthenticationDialog::ForcedReauthenticationDialog( 87 ForcedReauthenticationDialog::ForcedReauthenticationDialog(
86 Browser* browser, 88 Browser* browser,
87 SigninManager* signin_manager, 89 SigninManager* signin_manager,
88 const base::TimeDelta& countdown_duration) 90 base::TimeDelta countdown_duration)
89 : browser_(browser), 91 : browser_(browser),
90 signin_manager_(signin_manager), 92 signin_manager_(signin_manager),
91 desired_close_time_(base::TimeTicks::Now() + countdown_duration) { 93 desired_close_time_(base::TimeTicks::Now() + countdown_duration),
94 weak_factory_(this) {
92 constrained_window::CreateBrowserModalDialogViews( 95 constrained_window::CreateBrowserModalDialogViews(
93 this, browser->window()->GetNativeWindow()) 96 this, browser->window()->GetNativeWindow())
94 ->Show(); 97 ->Show();
95 browser->window()->FlashFrame(true); 98 browser->window()->FlashFrame(true);
96 browser->window()->Activate(); 99 browser->window()->Activate();
97 } 100 }
98 101
99 ForcedReauthenticationDialog::~ForcedReauthenticationDialog() {} 102 ForcedReauthenticationDialog::~ForcedReauthenticationDialog() {}
100 103
101 // static 104 // static
102 ForcedReauthenticationDialog* ForcedReauthenticationDialog::ShowDialog( 105 ForcedReauthenticationDialog* ForcedReauthenticationDialog::ShowDialog(
103 Profile* profile, 106 Profile* profile,
104 SigninManager* signin_manager, 107 SigninManager* signin_manager,
105 const base::TimeDelta& countdown_duration) { 108 base::TimeDelta countdown_duration) {
106 Browser* browser = FindBrowserWithProfile(profile); 109 Browser* browser = FindBrowserWithProfile(profile);
107 if (browser == nullptr) { // If there is no browser, we can just sign 110 if (browser == nullptr) { // If there is no browser, we can just sign
108 // out profile directly. 111 // out profile directly.
109 Signout(signin_manager); 112 Signout(signin_manager);
110 return nullptr; 113 return nullptr;
111 } 114 }
112 115
113 return new ForcedReauthenticationDialog(browser, signin_manager, 116 return new ForcedReauthenticationDialog(browser, signin_manager,
114 countdown_duration); 117 countdown_duration);
115 } 118 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 dialog_layout->StartRow(0, 1); 230 dialog_layout->StartRow(0, 1);
228 const int kPreferredWidth = 440; 231 const int kPreferredWidth = 440;
229 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL, 232 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL,
230 views::GridLayout::FILL, kPreferredWidth, 233 views::GridLayout::FILL, kPreferredWidth,
231 explanation_label->GetHeightForWidth(kPreferredWidth)); 234 explanation_label->GetHeightForWidth(kPreferredWidth));
232 refresh_timer_.Start(FROM_HERE, 235 refresh_timer_.Start(FROM_HERE,
233 base::TimeDelta::FromSeconds(kRefreshTitleTimer), this, 236 base::TimeDelta::FromSeconds(kRefreshTitleTimer), this,
234 &ForcedReauthenticationDialog::OnCountDown); 237 &ForcedReauthenticationDialog::OnCountDown);
235 } 238 }
236 239
240 void ForcedReauthenticationDialog::CloseDialog() {
241 GetWidget()->Close();
242 }
243
237 void ForcedReauthenticationDialog::OnCountDown() { 244 void ForcedReauthenticationDialog::OnCountDown() {
238 if (desired_close_time_ <= base::TimeTicks::Now()) { 245 if (desired_close_time_ <= base::TimeTicks::Now()) {
239 Cancel(); 246 Cancel();
240 GetWidget()->Close(); 247 GetWidget()->Close();
241 } 248 }
242 GetWidget()->UpdateWindowTitle(); 249 GetWidget()->UpdateWindowTitle();
243 } 250 }
244 251
245 base::TimeDelta ForcedReauthenticationDialog::GetTimeRemaining() const { 252 base::TimeDelta ForcedReauthenticationDialog::GetTimeRemaining() const {
246 base::TimeTicks now = base::TimeTicks::Now(); 253 base::TimeTicks now = base::TimeTicks::Now();
247 if (desired_close_time_ <= now) 254 if (desired_close_time_ <= now)
248 return base::TimeDelta(); 255 return base::TimeDelta();
249 return desired_close_time_ - now; 256 return desired_close_time_ - now;
250 } 257 }
258
259 ForcedReauthenticationDialogDelegate::ForcedReauthenticationDialogDelegate() {}
260 ForcedReauthenticationDialogDelegate::~ForcedReauthenticationDialogDelegate() {}
261
262 void ForcedReauthenticationDialogDelegate::ShowDialog(
263 Profile* profile,
264 SigninManager* signin_manager,
265 base::TimeDelta countdown_duration) {
266 dialog_ = ForcedReauthenticationDialog::ShowDialog(profile, signin_manager,
267 countdown_duration)
268 ->AsWeakPtr();
269 }
270
271 void ForcedReauthenticationDialogDelegate::CloseDialog() {
272 if (dialog_)
273 dialog_->CloseDialog();
274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698