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

Side by Side Diff: chrome/browser/ui/views/first_run_dialog.cc

Issue 182143002: Use the default dispatcher where possible for nested message loops. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar-fix Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/first_run_dialog.h" 5 #include "chrome/browser/ui/views/first_run_dialog.h"
6 6
7 #include "chrome/browser/first_run/first_run.h" 7 #include "chrome/browser/first_run/first_run.h"
8 #include "chrome/browser/platform_util.h" 8 #include "chrome/browser/platform_util.h"
9 #include "chrome/browser/shell_integration.h" 9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 // Use the widget's window itself so that the message loop 59 // Use the widget's window itself so that the message loop
60 // exists when the dialog is closed by some other means than 60 // exists when the dialog is closed by some other means than
61 // |Accept|. 61 // |Accept|.
62 // 62 //
63 // This is the same trick used in simple_message_box_views.cc, minus the 63 // This is the same trick used in simple_message_box_views.cc, minus the
64 // refcounting. 64 // refcounting.
65 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow(); 65 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow();
66 aura::client::DispatcherClient* client = 66 aura::client::DispatcherClient* client =
67 aura::client::GetDispatcherClient(anchor->GetRootWindow()); 67 aura::client::GetDispatcherClient(anchor->GetRootWindow());
68 client->RunWithDispatcher(dialog, anchor); 68 client->RunWithDispatcher(NULL, anchor);
69 dialog_shown = true; 69 dialog_shown = true;
70 } 70 }
71 #endif // defined(GOOGLE_CHROME_BUILD) 71 #endif // defined(GOOGLE_CHROME_BUILD)
72 72
73 return dialog_shown; 73 return dialog_shown;
74 } 74 }
75 75
76 FirstRunDialog::FirstRunDialog(Profile* profile) 76 FirstRunDialog::FirstRunDialog(Profile* profile)
77 : profile_(profile), 77 : profile_(profile),
78 make_default_(NULL), 78 make_default_(NULL),
79 report_crashes_(NULL), 79 report_crashes_(NULL) {
80 should_show_dialog_(true) {
81 GridLayout* layout = GridLayout::CreatePanel(this); 80 GridLayout* layout = GridLayout::CreatePanel(this);
82 SetLayoutManager(layout); 81 SetLayoutManager(layout);
83 82
84 const int related_y = views::kRelatedControlVerticalSpacing; 83 const int related_y = views::kRelatedControlVerticalSpacing;
85 84
86 views::ColumnSet* column_set = layout->AddColumnSet(0); 85 views::ColumnSet* column_set = layout->AddColumnSet(0);
87 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 86 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
88 GridLayout::USE_PREF, 0, 0); 87 GridLayout::USE_PREF, 0, 0);
89 88
90 layout->StartRow(0, 0); 89 layout->StartRow(0, 0);
91 make_default_ = new views::Checkbox(l10n_util::GetStringUTF16( 90 make_default_ = new views::Checkbox(l10n_util::GetStringUTF16(
92 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER)); 91 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER));
93 make_default_->SetChecked(true); 92 make_default_->SetChecked(true);
94 layout->AddView(make_default_); 93 layout->AddView(make_default_);
95 94
96 layout->StartRowWithPadding(0, 0, 0, related_y); 95 layout->StartRowWithPadding(0, 0, 0, related_y);
97 report_crashes_ = new views::Checkbox(l10n_util::GetStringUTF16( 96 report_crashes_ = new views::Checkbox(l10n_util::GetStringUTF16(
98 IDS_OPTIONS_ENABLE_LOGGING)); 97 IDS_OPTIONS_ENABLE_LOGGING));
99 layout->AddView(report_crashes_); 98 layout->AddView(report_crashes_);
100 } 99 }
101 100
102 FirstRunDialog::~FirstRunDialog() { 101 FirstRunDialog::~FirstRunDialog() {
103 } 102 }
104 103
104 void FirstRunDialog::Done() {
105 aura::Window* window = GetWidget()->GetNativeView();
106 aura::client::DispatcherClient* client =
107 aura::client::GetDispatcherClient(window->GetRootWindow());
108 client->QuitNestedMessageLoop();
109 }
110
105 views::View* FirstRunDialog::CreateExtraView() { 111 views::View* FirstRunDialog::CreateExtraView() {
106 views::Link* link = new views::Link(l10n_util::GetStringUTF16( 112 views::Link* link = new views::Link(l10n_util::GetStringUTF16(
107 IDS_LEARN_MORE)); 113 IDS_LEARN_MORE));
108 link->set_listener(this); 114 link->set_listener(this);
109 return link; 115 return link;
110 } 116 }
111 117
112 void FirstRunDialog::OnClosed() { 118 void FirstRunDialog::OnClosed() {
113 should_show_dialog_ = false;
114 first_run::SetShouldShowWelcomePage(); 119 first_run::SetShouldShowWelcomePage();
120 Done();
115 } 121 }
116 122
117 bool FirstRunDialog::Accept() { 123 bool FirstRunDialog::Accept() {
118 should_show_dialog_ = false;
119 GetWidget()->Hide(); 124 GetWidget()->Hide();
120 125
121 if (report_crashes_ && report_crashes_->checked()) { 126 if (report_crashes_ && report_crashes_->checked()) {
122 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) 127 if (GoogleUpdateSettings::SetCollectStatsConsent(true))
123 breakpad::InitCrashReporter(std::string()); 128 breakpad::InitCrashReporter(std::string());
124 } else { 129 } else {
125 GoogleUpdateSettings::SetCollectStatsConsent(false); 130 GoogleUpdateSettings::SetCollectStatsConsent(false);
126 } 131 }
127 132
128 if (make_default_ && make_default_->checked()) 133 if (make_default_ && make_default_->checked())
129 ShellIntegration::SetAsDefaultBrowser(); 134 ShellIntegration::SetAsDefaultBrowser();
130 135
136 Done();
131 return true; 137 return true;
132 } 138 }
133 139
134 int FirstRunDialog::GetDialogButtons() const { 140 int FirstRunDialog::GetDialogButtons() const {
135 return ui::DIALOG_BUTTON_OK; 141 return ui::DIALOG_BUTTON_OK;
136 } 142 }
137 143
138 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) { 144 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) {
139 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL)); 145 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL));
140 } 146 }
141
142 uint32_t FirstRunDialog::Dispatch(const base::NativeEvent& event) {
143 uint32_t action = POST_DISPATCH_PERFORM_DEFAULT;
144 if (!should_show_dialog_)
145 action |= POST_DISPATCH_QUIT_LOOP;
146 return action;
147 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_dialog.h ('k') | chrome/browser/ui/views/simple_message_box_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698