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

Side by Side Diff: chrome/browser/first_run/try_chrome_dialog_view.cc

Issue 12321061: Pulling user experiment code from BrowserDistribution to a new class. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Stylistic fixes; adding ...IfRequired() suffix to LaunchUserExperiment() and InactiveUserToastExper… Created 7 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
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/first_run/try_chrome_dialog_view.h" 5 #include "chrome/browser/first_run/try_chrome_dialog_view.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "chrome/browser/process_singleton.h" 12 #include "chrome/browser/process_singleton.h"
13 #include "chrome/installer/util/browser_distribution.h" 13 #include "chrome/installer/util/user_experiment.h"
14 #include "grit/chromium_strings.h" 14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
17 #include "grit/ui_resources.h" 17 #include "grit/ui_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
21 #include "ui/views/controls/button/checkbox.h" 21 #include "ui/views/controls/button/checkbox.h"
22 #include "ui/views/controls/button/image_button.h" 22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/controls/button/radio_button.h" 23 #include "ui/views/controls/button/radio_button.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 views::GridLayout::USE_PREF, 0, 0); 167 views::GridLayout::USE_PREF, 0, 0);
168 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 168 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
169 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 169 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
170 views::GridLayout::USE_PREF, 0, 0); 170 views::GridLayout::USE_PREF, 0, 0);
171 171
172 // First row. 172 // First row.
173 layout->StartRow(0, 0); 173 layout->StartRow(0, 0);
174 layout->AddView(icon); 174 layout->AddView(icon);
175 175
176 // Find out what experiment we are conducting. 176 // Find out what experiment we are conducting.
177 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 177 installer::user_experiment::ExperimentDetails experiment;
178 if (!dist) { 178 if (!installer::user_experiment::CreateExperimentDetails(flavor_,
179 NOTREACHED() << "Cannot determine browser distribution"; 179 &experiment) ||
180 return DIALOG_ERROR;
181 }
182 BrowserDistribution::UserExperiment experiment;
183 if (!dist->GetExperimentDetails(&experiment, flavor_) ||
184 !experiment.heading) { 180 !experiment.heading) {
185 NOTREACHED() << "Cannot determine which headline to show."; 181 NOTREACHED() << "Cannot determine which headline to show.";
186 return DIALOG_ERROR; 182 return DIALOG_ERROR;
187 } 183 }
188 views::Label* label = new views::Label( 184 views::Label* label = new views::Label(
189 l10n_util::GetStringUTF16(experiment.heading)); 185 l10n_util::GetStringUTF16(experiment.heading));
190 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 186 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
191 label->SetMultiLine(true); 187 label->SetMultiLine(true);
192 label->SizeToFit(200); 188 label->SizeToFit(200);
193 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 189 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 13 matching lines...) Expand all
207 layout->StartRowWithPadding(0, 1, 0, 10); 203 layout->StartRowWithPadding(0, 1, 0, 10);
208 try_chrome_ = new views::RadioButton( 204 try_chrome_ = new views::RadioButton(
209 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); 205 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID);
210 try_chrome_->SetChecked(true); 206 try_chrome_->SetChecked(true);
211 try_chrome_->set_tag(BT_TRY_IT_RADIO); 207 try_chrome_->set_tag(BT_TRY_IT_RADIO);
212 try_chrome_->set_listener(this); 208 try_chrome_->set_listener(this);
213 layout->AddView(try_chrome_); 209 layout->AddView(try_chrome_);
214 210
215 // Decide if the don't bug me is a button or a radio button. 211 // Decide if the don't bug me is a button or a radio button.
216 bool dont_bug_me_button = 212 bool dont_bug_me_button =
217 ((experiment.flags & BrowserDistribution::kDontBugMeAsButton) != 0); 213 !!(experiment.flags & installer::user_experiment::kDontBugMeAsButton);
218 214
219 // Optional third and fourth row. 215 // Optional third and fourth row.
220 if (!dont_bug_me_button) { 216 if (!dont_bug_me_button) {
221 layout->StartRow(0, 1); 217 layout->StartRow(0, 1);
222 dont_try_chrome_ = new views::RadioButton( 218 dont_try_chrome_ = new views::RadioButton(
223 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); 219 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID);
224 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); 220 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO);
225 dont_try_chrome_->set_listener(this); 221 dont_try_chrome_->set_listener(this);
226 layout->AddView(dont_try_chrome_); 222 layout->AddView(dont_try_chrome_);
227 } 223 }
228 if (experiment.flags & BrowserDistribution::kUninstall) { 224 if (experiment.flags & installer::user_experiment::kUninstall) {
229 layout->StartRow(0, 2); 225 layout->StartRow(0, 2);
230 kill_chrome_ = new views::RadioButton( 226 kill_chrome_ = new views::RadioButton(
231 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); 227 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID);
232 layout->AddView(kill_chrome_); 228 layout->AddView(kill_chrome_);
233 } 229 }
234 230
235 views::Button* accept_button = new views::NativeTextButton( 231 views::Button* accept_button = new views::NativeTextButton(
236 this, l10n_util::GetStringUTF16(IDS_OK)); 232 this, l10n_util::GetStringUTF16(IDS_OK));
237 accept_button->set_tag(BT_OK_BUTTON); 233 accept_button->set_tag(BT_OK_BUTTON);
238 234
239 views::Separator* separator = NULL; 235 views::Separator* separator = NULL;
240 if (experiment.flags & BrowserDistribution::kMakeDefault) { 236 if (experiment.flags & installer::user_experiment::kMakeDefault) {
241 // In this flavor we have some veritical space, then a separator line 237 // In this flavor we have some veritical space, then a separator line
242 // and the 'make default' checkbox and the OK button on the same row. 238 // and the 'make default' checkbox and the OK button on the same row.
243 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 239 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
244 layout->StartRow(0, 6); 240 layout->StartRow(0, 6);
245 separator = new views::Separator; 241 separator = new views::Separator;
246 layout->AddView(separator); 242 layout->AddView(separator);
247 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 243 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
248 244
249 layout->StartRow(0, 7); 245 layout->StartRow(0, 7);
250 make_default_ = new views::Checkbox( 246 make_default_ = new views::Checkbox(
251 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); 247 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT));
252 make_default_->SetChecked(true); 248 make_default_->SetChecked(true);
253 layout->AddView(make_default_); 249 layout->AddView(make_default_);
254 layout->AddView(accept_button); 250 layout->AddView(accept_button);
255 } else { 251 } else {
256 // On this other flavor there is no checkbox, the OK button and possibly 252 // On this other flavor there is no checkbox, the OK button and possibly
257 // the cancel button are in the same row. 253 // the cancel button are in the same row.
258 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); 254 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10);
259 layout->AddView(accept_button); 255 layout->AddView(accept_button);
260 if (dont_bug_me_button) { 256 if (dont_bug_me_button) {
261 // The dialog needs a "Don't bug me" as a button or as a radio button, 257 // The dialog needs a "Don't bug me" as a button or as a radio button,
262 // this the button case. 258 // this the button case.
263 views::Button* cancel_button = new views::NativeTextButton( 259 views::Button* cancel_button = new views::NativeTextButton(
264 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); 260 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
265 cancel_button->set_tag(BT_CLOSE_BUTTON); 261 cancel_button->set_tag(BT_CLOSE_BUTTON);
266 layout->AddView(cancel_button); 262 layout->AddView(cancel_button);
267 } 263 }
268 } 264 }
269 265
270 if (experiment.flags & BrowserDistribution::kWhyLink) { 266 if (experiment.flags & installer::user_experiment::kWhyLink) {
271 layout->StartRowWithPadding(0, 4, 0, 10); 267 layout->StartRowWithPadding(0, 4, 0, 10);
272 views::Link* link = new views::Link( 268 views::Link* link = new views::Link(
273 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); 269 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));
274 link->set_listener(this); 270 link->set_listener(this);
275 layout->AddView(link); 271 layout->AddView(link);
276 } 272 }
277 273
278 // We resize the window according to the layout manager. This takes into 274 // We resize the window according to the layout manager. This takes into
279 // account the differences between XP and Vista fonts and buttons. 275 // account the differences between XP and Vista fonts and buttons.
280 layout->Layout(root_view); 276 layout->Layout(root_view);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 result_ = TRY_CHROME_AS_DEFAULT; 371 result_ = TRY_CHROME_AS_DEFAULT;
376 } 372 }
377 373
378 popup_->Close(); 374 popup_->Close();
379 MessageLoop::current()->Quit(); 375 MessageLoop::current()->Quit();
380 } 376 }
381 377
382 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { 378 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
383 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); 379 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
384 } 380 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_installer_util.gypi » ('j') | chrome/installer/util/user_experiment.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698