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

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: Reupload with --similarity=90 to prevent patch failure in try jobs. Created 7 years, 10 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
« no previous file with comments | « no previous file | chrome/chrome_installer_util.gypi » ('j') | chrome/installer/setup/setup_main.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 dont_try_chrome_(NULL), 72 dont_try_chrome_(NULL),
73 make_default_(NULL), 73 make_default_(NULL),
74 result_(COUNT) { 74 result_(COUNT) {
75 } 75 }
76 76
77 TryChromeDialogView::~TryChromeDialogView() { 77 TryChromeDialogView::~TryChromeDialogView() {
78 } 78 }
79 79
80 TryChromeDialogView::Result TryChromeDialogView::ShowModal( 80 TryChromeDialogView::Result TryChromeDialogView::ShowModal(
81 ProcessSingleton* process_singleton) { 81 ProcessSingleton* process_singleton) {
82 using installer::UserExperiment;
83
82 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
83 85
84 views::ImageView* icon = new views::ImageView(); 86 views::ImageView* icon = new views::ImageView();
85 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia()); 87 icon->SetImage(rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_32).ToImageSkia());
86 gfx::Size icon_size = icon->GetPreferredSize(); 88 gfx::Size icon_size = icon->GetPreferredSize();
87 89
88 popup_ = new views::Widget; 90 popup_ = new views::Widget;
89 if (!popup_) { 91 if (!popup_) {
90 NOTREACHED(); 92 NOTREACHED();
91 return DIALOG_ERROR; 93 return DIALOG_ERROR;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 views::GridLayout::USE_PREF, 0, 0); 169 views::GridLayout::USE_PREF, 0, 0);
168 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 170 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
169 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, 171 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
170 views::GridLayout::USE_PREF, 0, 0); 172 views::GridLayout::USE_PREF, 0, 0);
171 173
172 // First row. 174 // First row.
173 layout->StartRow(0, 0); 175 layout->StartRow(0, 0);
174 layout->AddView(icon); 176 layout->AddView(icon);
175 177
176 // Find out what experiment we are conducting. 178 // Find out what experiment we are conducting.
177 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 179 UserExperiment::ExperimentDetails experiment;
178 if (!dist) { 180 if (!UserExperiment::CreateExperimentDetails(&experiment, flavor_) ||
179 NOTREACHED() << "Cannot determine browser distribution";
180 return DIALOG_ERROR;
181 }
182 BrowserDistribution::UserExperiment experiment;
183 if (!dist->GetExperimentDetails(&experiment, flavor_) ||
184 !experiment.heading) { 181 !experiment.heading) {
185 NOTREACHED() << "Cannot determine which headline to show."; 182 NOTREACHED() << "Cannot determine which headline to show.";
186 return DIALOG_ERROR; 183 return DIALOG_ERROR;
187 } 184 }
188 views::Label* label = new views::Label( 185 views::Label* label = new views::Label(
189 l10n_util::GetStringUTF16(experiment.heading)); 186 l10n_util::GetStringUTF16(experiment.heading));
190 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 187 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
191 label->SetMultiLine(true); 188 label->SetMultiLine(true);
192 label->SizeToFit(200); 189 label->SizeToFit(200);
193 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 190 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 13 matching lines...) Expand all
207 layout->StartRowWithPadding(0, 1, 0, 10); 204 layout->StartRowWithPadding(0, 1, 0, 10);
208 try_chrome_ = new views::RadioButton( 205 try_chrome_ = new views::RadioButton(
209 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); 206 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID);
210 try_chrome_->SetChecked(true); 207 try_chrome_->SetChecked(true);
211 try_chrome_->set_tag(BT_TRY_IT_RADIO); 208 try_chrome_->set_tag(BT_TRY_IT_RADIO);
212 try_chrome_->set_listener(this); 209 try_chrome_->set_listener(this);
213 layout->AddView(try_chrome_); 210 layout->AddView(try_chrome_);
214 211
215 // Decide if the don't bug me is a button or a radio button. 212 // Decide if the don't bug me is a button or a radio button.
216 bool dont_bug_me_button = 213 bool dont_bug_me_button =
217 ((experiment.flags & BrowserDistribution::kDontBugMeAsButton) != 0); 214 ((experiment.flags & UserExperiment::kDontBugMeAsButton) != 0);
218 215
219 // Optional third and fourth row. 216 // Optional third and fourth row.
220 if (!dont_bug_me_button) { 217 if (!dont_bug_me_button) {
221 layout->StartRow(0, 1); 218 layout->StartRow(0, 1);
222 dont_try_chrome_ = new views::RadioButton( 219 dont_try_chrome_ = new views::RadioButton(
223 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); 220 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID);
224 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); 221 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO);
225 dont_try_chrome_->set_listener(this); 222 dont_try_chrome_->set_listener(this);
226 layout->AddView(dont_try_chrome_); 223 layout->AddView(dont_try_chrome_);
227 } 224 }
228 if (experiment.flags & BrowserDistribution::kUninstall) { 225 if (experiment.flags & UserExperiment::kUninstall) {
229 layout->StartRow(0, 2); 226 layout->StartRow(0, 2);
230 kill_chrome_ = new views::RadioButton( 227 kill_chrome_ = new views::RadioButton(
231 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); 228 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID);
232 layout->AddView(kill_chrome_); 229 layout->AddView(kill_chrome_);
233 } 230 }
234 231
235 views::Button* accept_button = new views::NativeTextButton( 232 views::Button* accept_button = new views::NativeTextButton(
236 this, l10n_util::GetStringUTF16(IDS_OK)); 233 this, l10n_util::GetStringUTF16(IDS_OK));
237 accept_button->set_tag(BT_OK_BUTTON); 234 accept_button->set_tag(BT_OK_BUTTON);
238 235
239 views::Separator* separator = NULL; 236 views::Separator* separator = NULL;
240 if (experiment.flags & BrowserDistribution::kMakeDefault) { 237 if (experiment.flags & UserExperiment::kMakeDefault) {
241 // In this flavor we have some veritical space, then a separator line 238 // 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. 239 // and the 'make default' checkbox and the OK button on the same row.
243 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 240 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
244 layout->StartRow(0, 6); 241 layout->StartRow(0, 6);
245 separator = new views::Separator; 242 separator = new views::Separator;
246 layout->AddView(separator); 243 layout->AddView(separator);
247 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 244 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
248 245
249 layout->StartRow(0, 7); 246 layout->StartRow(0, 7);
250 make_default_ = new views::Checkbox( 247 make_default_ = new views::Checkbox(
251 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); 248 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT));
252 make_default_->SetChecked(true); 249 make_default_->SetChecked(true);
253 layout->AddView(make_default_); 250 layout->AddView(make_default_);
254 layout->AddView(accept_button); 251 layout->AddView(accept_button);
255 } else { 252 } else {
256 // On this other flavor there is no checkbox, the OK button and possibly 253 // On this other flavor there is no checkbox, the OK button and possibly
257 // the cancel button are in the same row. 254 // the cancel button are in the same row.
258 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); 255 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10);
259 layout->AddView(accept_button); 256 layout->AddView(accept_button);
260 if (dont_bug_me_button) { 257 if (dont_bug_me_button) {
261 // The dialog needs a "Don't bug me" as a button or as a radio button, 258 // The dialog needs a "Don't bug me" as a button or as a radio button,
262 // this the button case. 259 // this the button case.
263 views::Button* cancel_button = new views::NativeTextButton( 260 views::Button* cancel_button = new views::NativeTextButton(
264 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); 261 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL));
265 cancel_button->set_tag(BT_CLOSE_BUTTON); 262 cancel_button->set_tag(BT_CLOSE_BUTTON);
266 layout->AddView(cancel_button); 263 layout->AddView(cancel_button);
267 } 264 }
268 } 265 }
269 266
270 if (experiment.flags & BrowserDistribution::kWhyLink) { 267 if (experiment.flags & UserExperiment::kWhyLink) {
271 layout->StartRowWithPadding(0, 4, 0, 10); 268 layout->StartRowWithPadding(0, 4, 0, 10);
272 views::Link* link = new views::Link( 269 views::Link* link = new views::Link(
273 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); 270 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY));
274 link->set_listener(this); 271 link->set_listener(this);
275 layout->AddView(link); 272 layout->AddView(link);
276 } 273 }
277 274
278 // We resize the window according to the layout manager. This takes into 275 // We resize the window according to the layout manager. This takes into
279 // account the differences between XP and Vista fonts and buttons. 276 // account the differences between XP and Vista fonts and buttons.
280 layout->Layout(root_view); 277 layout->Layout(root_view);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 result_ = TRY_CHROME_AS_DEFAULT; 372 result_ = TRY_CHROME_AS_DEFAULT;
376 } 373 }
377 374
378 popup_->Close(); 375 popup_->Close();
379 MessageLoop::current()->Quit(); 376 MessageLoop::current()->Quit();
380 } 377 }
381 378
382 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { 379 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) {
383 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); 380 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW);
384 } 381 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_installer_util.gypi » ('j') | chrome/installer/setup/setup_main.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698