Chromium Code Reviews| Index: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| index 6bfece7f18862c5704c1ee453701bb69516d6d1c..501e85a5a40a3f0cf3d007b76e098c33c527dfc2 100644 |
| --- a/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| +++ b/chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc |
| @@ -36,12 +36,12 @@ |
| #include "ui/views/layout/layout_constants.h" |
| #include "ui/views/widget/widget.h" |
| +int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; |
| // Helpers -------------------------------------------------------------------- |
| namespace { |
| -const int kAutoSigninToastTimeout = 3; |
| const int kDesiredBubbleWidth = 370; |
| enum ColumnSetType { |
| @@ -245,7 +245,8 @@ void ManagePasswordsBubbleView::AccountChooserView::ButtonPressed( |
| // in. |
| class ManagePasswordsBubbleView::AutoSigninView |
| : public views::View, |
| - public views::ButtonListener { |
| + public views::ButtonListener, |
| + public views::WidgetObserver { |
| public: |
| explicit AutoSigninView(ManagePasswordsBubbleView* parent); |
| @@ -253,15 +254,26 @@ class ManagePasswordsBubbleView::AutoSigninView |
| // views::ButtonListener: |
| void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| + // views::WidgetObserver: |
| + // Tracks the state of the browser window. |
| + void OnWidgetActivationChanged(views::Widget* widget, bool active) override; |
| + void OnWidgetClosing(views::Widget* widget) override; |
| + |
| void OnTimer(); |
| + static base::TimeDelta GetTimeout() { |
| + return base::TimeDelta::FromSeconds( |
| + ManagePasswordsBubbleView::auto_signin_toast_timeout_); |
| + } |
| base::OneShotTimer<AutoSigninView> timer_; |
| ManagePasswordsBubbleView* parent_; |
| + ScopedObserver<views::Widget, views::WidgetObserver> observed_browser_; |
| }; |
|
sky
2015/03/20 19:52:26
niT: DISALLOW...
vasilii
2015/03/23 09:27:51
Done.
|
| ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( |
| ManagePasswordsBubbleView* parent) |
| - : parent_(parent) { |
| + : parent_(parent), |
| + observed_browser_(this) { |
| SetLayoutManager(new views::FillLayout); |
| CredentialsItemView* credential = new CredentialsItemView( |
| this, |
| @@ -272,8 +284,14 @@ ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( |
| AddChildView(credential); |
| parent_->set_initially_focused_view(credential); |
| - timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kAutoSigninToastTimeout), |
| - this, &AutoSigninView::OnTimer); |
| + Browser* browser = |
|
sky
2015/03/20 19:52:26
Because this is all async is it possible browser i
vasilii
2015/03/23 09:27:51
I don't think so. If it happens then everything cr
|
| + chrome::FindBrowserWithWebContents(parent_->web_contents()); |
| + DCHECK(browser); |
| + BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
| + observed_browser_.Add(browser_view->GetWidget()); |
| + |
| + if (browser_view->IsActive()) |
| + timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
| } |
| void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
| @@ -282,6 +300,17 @@ void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
| parent_->Close(); |
| } |
| +void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
| + views::Widget* widget, bool active) { |
| + if (active) |
|
sky
2015/03/20 19:52:26
if (active && !timer_.IsRunning()) ?
vasilii
2015/03/23 09:27:51
Done.
|
| + timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
| +} |
| + |
| +void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( |
| + views::Widget* widget) { |
| + observed_browser_.RemoveAll(); |
| +} |
| + |
| void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { |
| parent_->model()->OnAutoSignInToastTimeout(); |
| parent_->Close(); |