OLD | NEW |
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 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_VIEW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 15 #include "chrome/browser/ui/forced_reauthentication_dialog.h" |
14 #include "ui/views/controls/button/button.h" | 16 #include "ui/views/controls/button/button.h" |
15 #include "ui/views/window/dialog_delegate.h" | 17 #include "ui/views/window/dialog_delegate.h" |
16 | 18 |
17 class Browser; | 19 class Browser; |
18 class Profile; | 20 class Profile; |
19 class SigninManager; | 21 class SigninManager; |
20 | 22 |
21 // A modal dialog that displays a warning message of the auth failure | 23 // A modal dialog that displays a warning message of the auth failure |
22 // and ask user to sign in again. | 24 // and ask user to sign in again. |
23 class ForcedReauthenticationDialog : public views::DialogDelegateView { | 25 class ForcedReauthenticationDialogView : public views::DialogDelegateView { |
24 public: | 26 public: |
25 ~ForcedReauthenticationDialog() override; | 27 ~ForcedReauthenticationDialogView() override; |
26 | 28 |
27 // Shows a warning dialog for |profile|. If there are no Browser windows | 29 // Shows a warning dialog for |profile|. If there are no Browser windows |
28 // associated with |profile|, signs out the profile immediately, otherwise the | 30 // associated with |profile|, signs out the profile immediately, otherwise the |
29 // user can clicks accept to sign in again. Dialog will be closed after | 31 // user can clicks accept to sign in again. Dialog will be closed after |
30 // |countdown_duration| seconds. | 32 // |countdown_duration| seconds. |
31 // Dialog will delete itself after closing. | 33 // Dialog will delete itself after closing. |
32 static ForcedReauthenticationDialog* ShowDialog( | 34 static ForcedReauthenticationDialogView* ShowDialog( |
33 Profile* profile, | 35 Profile* profile, |
34 SigninManager* signin_manager, | 36 SigninManager* signin_manager, |
35 const base::TimeDelta& countdown_duration); | 37 base::TimeDelta countdown_duration); |
36 | 38 |
37 // override views::DialogDelegateView | 39 // override views::DialogDelegateView |
38 bool Accept() override; | 40 bool Accept() override; |
39 bool Cancel() override; | 41 bool Cancel() override; |
40 void WindowClosing() override; | 42 void WindowClosing() override; |
41 base::string16 GetWindowTitle() const override; | 43 base::string16 GetWindowTitle() const override; |
42 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; | 44 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; |
43 ui::ModalType GetModalType() const override; | 45 ui::ModalType GetModalType() const override; |
44 | 46 |
45 // override views::View | 47 // override views::View |
46 void AddedToWidget() override; | 48 void AddedToWidget() override; |
47 | 49 |
| 50 // Close the dialog |
| 51 void CloseDialog(); |
| 52 |
| 53 base::WeakPtr<ForcedReauthenticationDialogView> AsWeakPtr() { |
| 54 return weak_factory_.GetWeakPtr(); |
| 55 } |
| 56 |
48 private: | 57 private: |
49 // Show the dialog for |browser|. The dialog will delete itself after closing. | 58 // Show the dialog for |browser|. The dialog will delete itself after closing. |
50 ForcedReauthenticationDialog(Browser* browser, | 59 ForcedReauthenticationDialogView(Browser* browser, |
51 SigninManager* signin_manager, | 60 SigninManager* signin_manager, |
52 const base::TimeDelta& countdown_duration); | 61 base::TimeDelta countdown_duration); |
53 | 62 |
54 void OnCountDown(); | 63 void OnCountDown(); |
55 base::TimeDelta GetTimeRemaining() const; | 64 base::TimeDelta GetTimeRemaining() const; |
56 | 65 |
57 Browser* browser_; | 66 Browser* browser_; |
58 SigninManager* signin_manager_; | 67 SigninManager* signin_manager_; |
59 | 68 |
60 const base::TimeTicks desired_close_time_; | 69 const base::TimeTicks desired_close_time_; |
61 | 70 |
62 // The timer which is used to refresh the dialog title to display the | 71 // The timer which is used to refresh the dialog title to display the |
63 // remaining time. | 72 // remaining time. |
64 base::RepeatingTimer refresh_timer_; | 73 base::RepeatingTimer refresh_timer_; |
65 | 74 |
66 DISALLOW_COPY_AND_ASSIGN(ForcedReauthenticationDialog); | 75 base::WeakPtrFactory<ForcedReauthenticationDialogView> weak_factory_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ForcedReauthenticationDialogView); |
67 }; | 78 }; |
68 | 79 |
69 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_H_ | 80 class ForcedReauthenticationDialogImpl : public ForcedReauthenticationDialog { |
| 81 public: |
| 82 ForcedReauthenticationDialogImpl(); |
| 83 ~ForcedReauthenticationDialogImpl() override; |
| 84 |
| 85 // override ForcedReauthenticationDialog |
| 86 void ShowDialog(Profile* profile, |
| 87 SigninManager* signin_manager, |
| 88 base::TimeDelta countdown_duration) override; |
| 89 |
| 90 private: |
| 91 base::WeakPtr<ForcedReauthenticationDialogView> dialog_view_; |
| 92 }; |
| 93 |
| 94 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_FORCED_REAUTHENTICATION_DIALOG_VIEW_
H_ |
OLD | NEW |