Revert "Only store leading 13 bits of password hash."
[chromium-blink-merge.git] / chrome / browser / ui / views / outdated_upgrade_bubble_view.cc
blobbf78be05b8c44d97dbf9fe869de95b1ff50c65d4
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
7 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/ui/views/elevation_icon_setter.h"
11 #include "chrome/browser/upgrade_detector.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/grit/chromium_strings.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/page_navigator.h"
17 #include "content/public/browser/user_metrics.h"
18 #include "grit/theme_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/views/controls/button/label_button.h"
22 #include "ui/views/controls/image_view.h"
23 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_constants.h"
26 #include "ui/views/widget/widget.h"
27 #include "url/gurl.h"
29 #if defined(OS_WIN)
30 #include "chrome/installer/util/google_update_util.h"
31 #endif
33 namespace {
35 // Fixed width of the column holding the description label of the bubble.
36 // TODO(mad): Make sure there is enough room for all languages.
37 const int kWidthOfDescriptionText = 330;
39 // We subtract 2 to account for the natural button padding, and
40 // to bring the separation visually in line with the row separation
41 // height.
42 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
44 // The URL to be used to re-install Chrome when auto-update failed for too long.
45 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL"
46 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
48 // The maximum number of ignored bubble we track in the NumLaterPerReinstall
49 // histogram.
50 const int kMaxIgnored = 50;
51 // The number of buckets we want the NumLaterPerReinstall histogram to use.
52 const int kNumIgnoredBuckets = 5;
54 } // namespace
56 // OutdatedUpgradeBubbleView ---------------------------------------------------
58 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
59 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0;
61 // static
62 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
63 content::PageNavigator* navigator,
64 bool auto_update_enabled) {
65 if (IsShowing())
66 return;
67 upgrade_bubble_ = new OutdatedUpgradeBubbleView(
68 anchor_view, navigator, auto_update_enabled);
69 views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show();
70 content::RecordAction(auto_update_enabled ?
71 base::UserMetricsAction("OutdatedUpgradeBubble.Show") :
72 base::UserMetricsAction("OutdatedUpgradeBubble.ShowNoAU"));
75 bool OutdatedUpgradeBubbleView::IsAvailable() {
76 // This should only work on non-Chrome OS desktop platforms.
77 #if defined(OS_WIN) || defined(OS_MACOSX) || \
78 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
79 return true;
80 #else
81 return false;
82 #endif
85 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
86 if (!accepted_ && num_ignored_bubbles_ < kMaxIgnored)
87 ++num_ignored_bubbles_;
89 // Ensure |elevation_icon_setter_| is destroyed before |accept_button_|.
90 elevation_icon_setter_.reset();
93 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
94 return accept_button_;
97 void OutdatedUpgradeBubbleView::WindowClosing() {
98 // Reset |upgrade_bubble_| here, not in destructor, because destruction is
99 // asynchronous and ShowBubble may be called before full destruction and
100 // would attempt to show a bubble that is closing.
101 DCHECK_EQ(upgrade_bubble_, this);
102 upgrade_bubble_ = NULL;
105 void OutdatedUpgradeBubbleView::Init() {
106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
107 accept_button_ = new views::LabelButton(
108 this, l10n_util::GetStringUTF16(
109 auto_update_enabled_ ? IDS_REINSTALL_APP : IDS_REENABLE_UPDATES));
110 accept_button_->SetStyle(views::Button::STYLE_BUTTON);
111 accept_button_->SetIsDefault(true);
112 accept_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont));
113 elevation_icon_setter_.reset(new ElevationIconSetter(accept_button_));
115 later_button_ = new views::LabelButton(
116 this, l10n_util::GetStringUTF16(IDS_LATER));
117 later_button_->SetStyle(views::Button::STYLE_BUTTON);
119 views::Label* title_label = new views::Label(
120 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE));
121 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
122 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
124 views::Label* text_label = new views::Label(l10n_util::GetStringUTF16(
125 auto_update_enabled_ ? IDS_UPGRADE_BUBBLE_TEXT
126 : IDS_UPGRADE_BUBBLE_REENABLE_TEXT));
127 text_label->SetMultiLine(true);
128 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
130 views::ImageView* image_view = new views::ImageView();
131 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH));
133 views::GridLayout* layout = new views::GridLayout(this);
134 SetLayoutManager(layout);
136 const int kIconTitleColumnSetId = 0;
137 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
139 // Top (icon-title) row.
140 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
141 views::GridLayout::USE_PREF, 0, 0);
142 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
143 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0,
144 views::GridLayout::USE_PREF, 0, 0);
145 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
147 // Middle (text) row.
148 const int kTextColumnSetId = 1;
149 cs = layout->AddColumnSet(kTextColumnSetId);
150 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
151 views::GridLayout::FIXED, kWidthOfDescriptionText, 0);
153 // Bottom (buttons) row.
154 const int kButtonsColumnSetId = 2;
155 cs = layout->AddColumnSet(kButtonsColumnSetId);
156 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
157 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::TRAILING, 0,
158 views::GridLayout::USE_PREF, 0, 0);
159 cs->AddPaddingColumn(0, kButtonPadding);
160 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::TRAILING, 0,
161 views::GridLayout::USE_PREF, 0, 0);
163 layout->StartRow(0, kIconTitleColumnSetId);
164 layout->AddView(image_view);
165 layout->AddView(title_label);
167 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
168 layout->StartRow(0, kTextColumnSetId);
169 layout->AddView(text_label);
171 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
173 layout->StartRow(0, kButtonsColumnSetId);
174 layout->AddView(accept_button_);
175 layout->AddView(later_button_);
177 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
180 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(
181 views::View* anchor_view,
182 content::PageNavigator* navigator,
183 bool auto_update_enabled)
184 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
185 auto_update_enabled_(auto_update_enabled),
186 accepted_(false),
187 accept_button_(NULL),
188 later_button_(NULL),
189 navigator_(navigator) {
190 // Compensate for built-in vertical padding in the anchor view's image.
191 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
194 void OutdatedUpgradeBubbleView::ButtonPressed(
195 views::Button* sender, const ui::Event& event) {
196 if (event.IsMouseEvent() &&
197 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
198 return;
200 HandleButtonPressed(sender);
203 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
204 if (sender == accept_button_) {
205 accepted_ = true;
206 if (auto_update_enabled_) {
207 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install());
208 UMA_HISTOGRAM_CUSTOM_COUNTS(
209 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_,
210 0, kMaxIgnored, kNumIgnoredBuckets);
211 content::RecordAction(
212 base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall"));
213 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl),
214 content::Referrer(),
215 NEW_FOREGROUND_TAB,
216 ui::PAGE_TRANSITION_LINK,
217 false));
218 #if defined(OS_WIN)
219 } else {
220 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install_no_au());
221 UMA_HISTOGRAM_CUSTOM_COUNTS(
222 "OutdatedUpgradeBubble.NumLaterPerEnableAU", num_ignored_bubbles_,
223 0, kMaxIgnored, kNumIgnoredBuckets);
224 content::RecordAction(
225 base::UserMetricsAction("OutdatedUpgradeBubble.EnableAU"));
226 // Record that the autoupdate flavour of the dialog has been shown.
227 if (g_browser_process->local_state()) {
228 g_browser_process->local_state()->SetBoolean(
229 prefs::kAttemptedToEnableAutoupdate, true);
232 // Re-enable updates by shelling out to setup.exe in the blocking pool.
233 content::BrowserThread::PostBlockingPoolTask(
234 FROM_HERE,
235 base::Bind(&google_update::ElevateIfNeededToReenableUpdates));
236 #endif // defined(OS_WIN)
238 } else {
239 DCHECK_EQ(later_button_, sender);
240 content::RecordAction(
241 base::UserMetricsAction("OutdatedUpgradeBubble.Later"));
243 GetWidget()->Close();