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

Side by Side Diff: chrome/browser/ui/views/importer/import_lock_dialog_view.cc

Issue 2769383002: Firefox overlay is seen opened even if Import Overlay is Cancelled.
Patch Set: Implemented Widget Observer and Addressed Review Comments. Created 3 years, 8 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 (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/metrics/user_metrics.h" 9 #include "base/metrics/user_metrics.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 12 matching lines...) Expand all
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 base::RecordAction(UserMetricsAction("ImportLockDialogView_Shown")); 30 base::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.
Ilya Sherman 2017/04/04 16:47:13 nit: Please move this comment to be within the nam
nikhil.sahni 2017/04/05 06:07:55 Done.
41 namespace {
42 static views::Widget* g_widget = nullptr;
43 }
Ilya Sherman 2017/04/04 16:47:13 nit: Please move this to the top of the file, just
nikhil.sahni 2017/04/05 06:07:55 Done.
44
45 // static
46 void ImportLockDialogView::Hide() {
47 if (g_widget) {
48 g_widget->Close();
49 g_widget = nullptr;
Ilya Sherman 2017/04/04 16:47:13 nit: This line should now be unnecessary, since th
nikhil.sahni 2017/04/05 06:07:55 Done.
50 }
51 }
Ilya Sherman 2017/04/04 16:47:13 nit: Please move this to be below the Show() funct
nikhil.sahni 2017/04/05 06:07:54 Done.
52
35 // static 53 // static
36 void ImportLockDialogView::Show(gfx::NativeWindow parent, 54 void ImportLockDialogView::Show(gfx::NativeWindow parent,
37 const base::Callback<void(bool)>& callback) { 55 const base::Callback<void(bool)>& callback) {
38 views::DialogDelegate::CreateDialogWidget( 56 ImportLockDialogView* import_lock_dialog_view =
Ilya Sherman 2017/04/04 16:47:13 Optional nit: I'd name this simply "view" or "dial
nikhil.sahni 2017/04/05 06:07:54 Done.
39 new ImportLockDialogView(callback), NULL, NULL)->Show(); 57 new ImportLockDialogView(callback);
58 g_widget = views::DialogDelegate::CreateDialogWidget(import_lock_dialog_view,
59 NULL, NULL);
60 g_widget->Show();
61 g_widget->AddObserver(import_lock_dialog_view);
Ilya Sherman 2017/04/04 16:47:13 nit: Please add the observer before showing the wi
nikhil.sahni 2017/04/05 06:07:55 Done.
40 } 62 }
41 63
42 ImportLockDialogView::ImportLockDialogView( 64 ImportLockDialogView::ImportLockDialogView(
43 const base::Callback<void(bool)>& callback) 65 const base::Callback<void(bool)>& callback)
44 : description_label_(NULL), 66 : description_label_(NULL),
45 callback_(callback) { 67 callback_(callback) {
46 description_label_ = new views::Label( 68 description_label_ = new views::Label(
47 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT)); 69 l10n_util::GetStringUTF16(IDS_IMPORTER_LOCK_TEXT));
48 description_label_->SetMultiLine(true); 70 description_label_->SetMultiLine(true);
49 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 71 description_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
50 AddChildView(description_label_); 72 AddChildView(description_label_);
51 } 73 }
52 74
53 ImportLockDialogView::~ImportLockDialogView() { 75 ImportLockDialogView::~ImportLockDialogView() {
54 } 76 }
55 77
78 void ImportLockDialogView::OnWidgetDestroying(views::Widget* widget) {
Ilya Sherman 2017/04/04 16:47:13 nit: Please also add DCHECK_EQ(widget, g_widget);
nikhil.sahni 2017/04/05 06:07:54 Done.
79 g_widget = nullptr;
80 widget->RemoveObserver(this);
81 }
82
56 gfx::Size ImportLockDialogView::GetPreferredSize() const { 83 gfx::Size ImportLockDialogView::GetPreferredSize() const {
57 return gfx::Size(views::Widget::GetLocalizedContentsSize( 84 return gfx::Size(views::Widget::GetLocalizedContentsSize(
58 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS, 85 IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
59 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES)); 86 IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
60 } 87 }
61 88
62 void ImportLockDialogView::Layout() { 89 void ImportLockDialogView::Layout() {
63 gfx::Rect bounds(GetLocalBounds()); 90 gfx::Rect bounds(GetLocalBounds());
64 bounds.Inset(views::kButtonHEdgeMarginNew, 91 bounds.Inset(views::kButtonHEdgeMarginNew,
65 LayoutDelegate::Get()->GetMetric( 92 LayoutDelegate::Get()->GetMetric(
(...skipping 15 matching lines...) Expand all
81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 108 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
82 base::Bind(callback_, true)); 109 base::Bind(callback_, true));
83 return true; 110 return true;
84 } 111 }
85 112
86 bool ImportLockDialogView::Cancel() { 113 bool ImportLockDialogView::Cancel() {
87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 114 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
88 base::Bind(callback_, false)); 115 base::Bind(callback_, false));
89 return true; 116 return true;
90 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698