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

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

Issue 211543008: Show a modified outdated upgrade Bubble for non-enterprise users without auto-update (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review comments 1. 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 (c) 2013 The Chromium Authors. All rights reserved. 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 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/outdated_upgrade_bubble_view.h" 5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/path_service.h"
8 #include "chrome/browser/upgrade_detector.h" 9 #include "chrome/browser/upgrade_detector.h"
10 #include "chrome/installer/util/install_util.h"
9 #include "content/public/browser/page_navigator.h" 11 #include "content/public/browser/page_navigator.h"
10 #include "content/public/browser/user_metrics.h" 12 #include "content/public/browser/user_metrics.h"
11 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/controls/button/label_button.h" 18 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/controls/image_view.h" 19 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/grid_layout.h" 21 #include "ui/views/layout/grid_layout.h"
20 #include "ui/views/layout/layout_constants.h" 22 #include "ui/views/layout/layout_constants.h"
21 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
23 25
26 #if defined(OS_WIN)
27 #include "base/win/win_util.h"
28 #include "base/win/windows_version.h"
29 #include "ui/gfx/icon_util.h"
30 #endif
31
24 using views::GridLayout; 32 using views::GridLayout;
25 33
26 namespace { 34 namespace {
27 35
28 // Fixed width of the column holding the description label of the bubble. 36 // Fixed width of the column holding the description label of the bubble.
29 // TODO(mad): Make sure there is enough room for all languages. 37 // TODO(mad): Make sure there is enough room for all languages.
30 const int kWidthOfDescriptionText = 330; 38 const int kWidthOfDescriptionText = 330;
31 39
32 // We subtract 2 to account for the natural button padding, and 40 // We subtract 2 to account for the natural button padding, and
33 // to bring the separation visually in line with the row separation 41 // to bring the separation visually in line with the row separation
34 // height. 42 // height.
35 const int kButtonPadding = views::kRelatedButtonHSpacing - 2; 43 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
36 44
37 // The URL to be used to re-install Chrome when auto-update failed for too long. 45 // The URL to be used to re-install Chrome when auto-update failed for too long.
38 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL" 46 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL"
39 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et"; 47 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
40 48
41 // The maximum number of ignored bubble we track in the NumLaterPerReinstall 49 // The maximum number of ignored bubble we track in the NumLaterPerReinstall
42 // histogram. 50 // histogram.
43 const int kMaxIgnored = 50; 51 const int kMaxIgnored = 50;
44 // The number of buckets we want the NumLaterPerReinstall histogram to use. 52 // The number of buckets we want the NumLaterPerReinstall histogram to use.
45 const int kNumIgnoredBuckets = 5; 53 const int kNumIgnoredBuckets = 5;
46 54
55 // Adds an elevation icon to |button| when running a system level install.
56 void AddElevationIconIfNeeded(views::LabelButton* button) {
57 #if defined(OS_WIN)
58 if ((base::win::GetVersion() >= base::win::VERSION_VISTA) &&
59 base::win::UserAccountControlIsEnabled()) {
60 base::FilePath exe_path;
61 PathService::Get(base::FILE_EXE, &exe_path);
62 if (InstallUtil::IsPerUserInstall(exe_path.value().c_str()))
63 return;
64
65 // This code was lifted from chrome/browser/ui/views/infobars/infobar_view.
66 // TODO(mad): Investigate the possibility of moving it to a common place.
67 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) };
68 // Even with the runtime guard above, we have to use GetProcAddress() here,
69 // because otherwise the loader will try to resolve the function address on
70 // startup, which will break on XP.
71 typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID, UINT,
72 SHSTOCKICONINFO*);
73 GetStockIconInfo func = reinterpret_cast<GetStockIconInfo>(
74 GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetStockIconInfo"));
75 if (SUCCEEDED((*func)(SIID_SHIELD, SHGSI_ICON | SHGSI_SMALLICON,
76 &icon_info))) {
77 scoped_ptr<SkBitmap> icon(IconUtil::CreateSkBitmapFromHICON(
78 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON),
79 GetSystemMetrics(SM_CYSMICON))));
80 if (icon.get()) {
81 button->SetImage(views::Button::STATE_NORMAL,
82 gfx::ImageSkia::CreateFrom1xBitmap(*icon));
83 }
84 DestroyIcon(icon_info.hIcon);
85 }
86 }
87 #endif
88 }
89
47 } // namespace 90 } // namespace
48 91
49 // OutdatedUpgradeBubbleView --------------------------------------------------- 92 // OutdatedUpgradeBubbleView ---------------------------------------------------
50 93
51 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL; 94 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
52 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0; 95 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0;
53 96
54 // static 97 // static
55 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view, 98 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
56 content::PageNavigator* navigator) { 99 content::PageNavigator* navigator,
100 bool auto_update_enabled) {
57 if (IsShowing()) 101 if (IsShowing())
58 return; 102 return;
59 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, navigator); 103 upgrade_bubble_ = new OutdatedUpgradeBubbleView(
104 anchor_view, navigator, auto_update_enabled);
60 views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show(); 105 views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show();
61 content::RecordAction( 106 content::RecordAction(base::UserMetricsAction(
62 base::UserMetricsAction("OutdatedUpgradeBubble.Show")); 107 auto_update_enabled ? "OutdatedUpgradeBubble.Show"
108 : "OutdatedUpgradeBubble.ShowNoAU"));
63 } 109 }
64 110
65 bool OutdatedUpgradeBubbleView::IsAvailable() { 111 bool OutdatedUpgradeBubbleView::IsAvailable() {
66 // This should only work on non-Chrome OS desktop platforms. 112 // This should only work on non-Chrome OS desktop platforms.
67 #if defined(OS_WIN) || defined(OS_MACOSX) || \ 113 #if defined(OS_WIN) || defined(OS_MACOSX) || \
68 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 114 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
69 return true; 115 return true;
70 #else 116 #else
71 return false; 117 return false;
72 #endif 118 #endif
73 } 119 }
74 120
75 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { 121 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
76 if (!chose_to_reinstall_ && num_ignored_bubbles_ < kMaxIgnored) 122 if (!accepted_ && num_ignored_bubbles_ < kMaxIgnored)
77 ++num_ignored_bubbles_; 123 ++num_ignored_bubbles_;
78 } 124 }
79 125
80 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { 126 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
81 return reinstall_button_; 127 return accept_button_;
82 } 128 }
83 129
84 void OutdatedUpgradeBubbleView::WindowClosing() { 130 void OutdatedUpgradeBubbleView::WindowClosing() {
85 // Reset |upgrade_bubble_| here, not in destructor, because destruction is 131 // Reset |upgrade_bubble_| here, not in destructor, because destruction is
86 // asynchronous and ShowBubble may be called before full destruction and 132 // asynchronous and ShowBubble may be called before full destruction and
87 // would attempt to show a bubble that is closing. 133 // would attempt to show a bubble that is closing.
88 DCHECK_EQ(upgrade_bubble_, this); 134 DCHECK_EQ(upgrade_bubble_, this);
89 upgrade_bubble_ = NULL; 135 upgrade_bubble_ = NULL;
90 } 136 }
91 137
92 void OutdatedUpgradeBubbleView::Init() { 138 void OutdatedUpgradeBubbleView::Init() {
93 base::string16 product_name(
94 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 139 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
96 reinstall_button_ = new views::LabelButton( 140 accept_button_ = new views::LabelButton(
97 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); 141 this, l10n_util::GetStringUTF16(
98 reinstall_button_->SetStyle(views::Button::STYLE_BUTTON); 142 auto_update_enabled_ ? IDS_REINSTALL_APP : IDS_REENABLE_UPDATES));
99 reinstall_button_->SetIsDefault(true); 143 accept_button_->SetStyle(views::Button::STYLE_BUTTON);
100 reinstall_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); 144 accept_button_->SetIsDefault(true);
145 accept_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont));
146 AddElevationIconIfNeeded(accept_button_);
101 147
102 later_button_ = new views::LabelButton( 148 later_button_ = new views::LabelButton(
103 this, l10n_util::GetStringUTF16(IDS_LATER)); 149 this, l10n_util::GetStringUTF16(IDS_LATER));
104 later_button_->SetStyle(views::Button::STYLE_BUTTON); 150 later_button_->SetStyle(views::Button::STYLE_BUTTON);
105 151
106 views::Label* title_label = new views::Label( 152 views::Label* title_label = new views::Label(
107 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); 153 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE));
108 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); 154 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
109 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 155 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
110 156
111 views::Label* text_label = new views::Label( 157 views::Label* text_label = new views::Label(l10n_util::GetStringUTF16(
112 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); 158 auto_update_enabled_ ? IDS_UPGRADE_BUBBLE_TEXT
159 : IDS_UPGRADE_BUBBLE_REENABLE_TEXT));
113 text_label->SetMultiLine(true); 160 text_label->SetMultiLine(true);
114 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 161 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
115 162
116 views::ImageView* image_view = new views::ImageView(); 163 views::ImageView* image_view = new views::ImageView();
117 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH)); 164 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH));
118 165
119 GridLayout* layout = new GridLayout(this); 166 GridLayout* layout = new GridLayout(this);
120 SetLayoutManager(layout); 167 SetLayoutManager(layout);
121 168
122 const int kIconTitleColumnSetId = 0; 169 const int kIconTitleColumnSetId = 0;
(...skipping 27 matching lines...) Expand all
150 layout->AddView(image_view); 197 layout->AddView(image_view);
151 layout->AddView(title_label); 198 layout->AddView(title_label);
152 199
153 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 200 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
154 layout->StartRow(0, kTextColumnSetId); 201 layout->StartRow(0, kTextColumnSetId);
155 layout->AddView(text_label); 202 layout->AddView(text_label);
156 203
157 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 204 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
158 205
159 layout->StartRow(0, kButtonsColumnSetId); 206 layout->StartRow(0, kButtonsColumnSetId);
160 layout->AddView(reinstall_button_); 207 layout->AddView(accept_button_);
161 layout->AddView(later_button_); 208 layout->AddView(later_button_);
162 209
163 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 210 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
164 } 211 }
165 212
166 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView( 213 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(
167 views::View* anchor_view, content::PageNavigator* navigator) 214 views::View* anchor_view,
215 content::PageNavigator* navigator,
216 bool auto_update_enabled)
168 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 217 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
169 chose_to_reinstall_(false), 218 auto_update_enabled_(auto_update_enabled),
170 reinstall_button_(NULL), 219 accepted_(false),
220 accept_button_(NULL),
171 later_button_(NULL), 221 later_button_(NULL),
172 navigator_(navigator) { 222 navigator_(navigator) {
173 // Compensate for built-in vertical padding in the anchor view's image. 223 // Compensate for built-in vertical padding in the anchor view's image.
174 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 224 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
175 } 225 }
176 226
177 void OutdatedUpgradeBubbleView::ButtonPressed( 227 void OutdatedUpgradeBubbleView::ButtonPressed(
178 views::Button* sender, const ui::Event& event) { 228 views::Button* sender, const ui::Event& event) {
179 if (event.IsMouseEvent() && 229 if (event.IsMouseEvent() &&
180 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) { 230 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
181 return; 231 return;
182 } 232 }
183 HandleButtonPressed(sender); 233 HandleButtonPressed(sender);
184 } 234 }
185 235
186 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { 236 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
187 if (sender == reinstall_button_) { 237 if (sender == accept_button_) {
188 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); 238 accepted_ = true;
189 chose_to_reinstall_ = true; 239 if (auto_update_enabled_) {
190 UMA_HISTOGRAM_CUSTOM_COUNTS( 240 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install());
191 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_, 241 UMA_HISTOGRAM_CUSTOM_COUNTS(
192 0, kMaxIgnored, kNumIgnoredBuckets); 242 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_,
193 content::RecordAction( 243 0, kMaxIgnored, kNumIgnoredBuckets);
194 base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall")); 244 content::RecordAction(
195 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl), 245 base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall"));
196 content::Referrer(), 246 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl),
197 NEW_FOREGROUND_TAB, 247 content::Referrer(),
198 content::PAGE_TRANSITION_LINK, 248 NEW_FOREGROUND_TAB,
199 false)); 249 content::PAGE_TRANSITION_LINK,
250 false));
251 } else {
252 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install_no_au());
253 UMA_HISTOGRAM_CUSTOM_COUNTS(
254 "OutdatedUpgradeBubble.NumLaterPerEnableAU", num_ignored_bubbles_,
255 0, kMaxIgnored, kNumIgnoredBuckets);
256 content::RecordAction(
257 base::UserMetricsAction("OutdatedUpgradeBubble.EnableAU"));
258 // TODO(robertshield): Make a call to GoogleUpdateSettings to enable
259 // auto-update, and record enable_au bit to local state.
robertshield 2014/03/26 20:37:18 Actually since you've added the pref, you could se
MAD 2014/03/26 21:21:10 Actually, I thought it would be better if we added
robertshield 2014/03/26 21:45:09 I think we should set it regardless of whether the
260 }
200 } else { 261 } else {
201 DCHECK_EQ(later_button_, sender); 262 DCHECK_EQ(later_button_, sender);
202 content::RecordAction( 263 content::RecordAction(
203 base::UserMetricsAction("OutdatedUpgradeBubble.Later")); 264 base::UserMetricsAction("OutdatedUpgradeBubble.Later"));
204 } 265 }
205 GetWidget()->Close(); 266 GetWidget()->Close();
206 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698