OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/importer/import_lock_dialog_view.h" | 5 #include "chrome/browser/ui/views/importer/import_lock_dialog_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 using base::UserMetricsAction; | 23 using base::UserMetricsAction; |
24 | 24 |
25 namespace importer { | 25 namespace importer { |
26 | 26 |
27 void ShowImportLockDialog(gfx::NativeWindow parent, | 27 void ShowImportLockDialog(gfx::NativeWindow parent, |
28 const base::Callback<void(bool)>& callback) { | 28 const base::Callback<void(bool)>& callback) { |
29 ImportLockDialogView::Show(parent, callback); | 29 ImportLockDialogView::Show(parent, callback); |
30 content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); | 30 content::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); |
31 } | 31 } |
32 | 32 |
33 void HideImportLockDialog() { | |
34 ImportLockDialogView::Hide(); | |
35 } | |
36 | |
33 } // namespace importer | 37 } // namespace importer |
34 | 38 |
39 // For storing widget ptr on creation of dialog widget | |
40 // using method CreateDialogWidget. | |
41 namespace { | |
42 static views::Widget* g_widget = nullptr; | |
43 } | |
44 | |
45 // static | |
46 void ImportLockDialogView::Hide() { | |
47 if (g_widget) | |
48 g_widget->Close(); | |
Ilya Sherman
2017/03/30 22:14:32
Should you set g_widget to nullptr here?
nikhil.sahni
2017/03/31 15:21:25
Done.
| |
49 } | |
50 | |
35 // static | 51 // static |
36 void ImportLockDialogView::Show(gfx::NativeWindow parent, | 52 void ImportLockDialogView::Show(gfx::NativeWindow parent, |
37 const base::Callback<void(bool)>& callback) { | 53 const base::Callback<void(bool)>& callback) { |
38 views::DialogDelegate::CreateDialogWidget( | 54 g_widget = views::DialogDelegate::CreateDialogWidget( |
39 new ImportLockDialogView(callback), NULL, NULL)->Show(); | 55 new ImportLockDialogView(callback), NULL, NULL); |
56 g_widget->Show(); | |
40 } | 57 } |
41 | 58 |
42 ImportLockDialogView::ImportLockDialogView( | 59 ImportLockDialogView::ImportLockDialogView( |
43 const base::Callback<void(bool)>& callback) | 60 const base::Callback<void(bool)>& callback) |
44 : description_label_(NULL), | 61 : description_label_(NULL), |
45 callback_(callback) { | 62 callback_(callback) { |
46 description_label_ = new views::Label( | 63 description_label_ = new views::Label( |
47 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)); | 64 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)); |
48 description_label_->SetMultiLine(true); | 65 description_label_->SetMultiLine(true); |
49 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 66 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
(...skipping 23 matching lines...) Expand all Loading... | |
73 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL); | 90 IDS_IMPORTER_LOCK_OK : IDS_IMPORTER_LOCK_CANCEL); |
74 } | 91 } |
75 | 92 |
76 base::string16 ImportLockDialogView::GetWindowTitle() const { | 93 base::string16 ImportLockDialogView::GetWindowTitle() const { |
77 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE); | 94 return l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TITLE); |
78 } | 95 } |
79 | 96 |
80 bool ImportLockDialogView::Accept() { | 97 bool ImportLockDialogView::Accept() { |
81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 98 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
82 base::Bind(callback_, true)); | 99 base::Bind(callback_, true)); |
100 g_widget = nullptr; | |
Ilya Sherman
2017/03/30 22:14:32
What about if the user cancels the dialog instead?
nikhil.sahni
2017/03/31 15:21:25
In case of CANCEL even the IMPORT Dialog gets clos
Ilya Sherman
2017/04/04 05:39:52
Yes, I think implementing ImportLockDialogView::On
nikhil.sahni
2017/04/04 09:21:40
Done.
| |
83 return true; | 101 return true; |
84 } | 102 } |
85 | 103 |
86 bool ImportLockDialogView::Cancel() { | 104 bool ImportLockDialogView::Cancel() { |
87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 105 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
88 base::Bind(callback_, false)); | 106 base::Bind(callback_, false)); |
89 return true; | 107 return true; |
90 } | 108 } |
OLD | NEW |