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

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

Issue 2644663003: Offer to open the startup pages after a crash. (Closed)
Patch Set: Added tests Created 3 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
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/session_crashed_bubble_view.h" 5 #include "chrome/browser/ui/views/session_crashed_bubble_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/metrics/metrics_reporting_state.h" 19 #include "chrome/browser/metrics/metrics_reporting_state.h"
20 #include "chrome/browser/prefs/session_startup_pref.h"
20 #include "chrome/browser/sessions/session_restore.h" 21 #include "chrome/browser/sessions/session_restore.h"
21 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
22 #include "chrome/browser/ui/browser_list_observer.h" 23 #include "chrome/browser/ui/browser_list_observer.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/browser/ui/views/frame/browser_view.h" 25 #include "chrome/browser/ui/views/frame/browser_view.h"
25 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" 26 #include "chrome/browser/ui/views/toolbar/app_menu_button.h"
26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 27 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
27 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
28 #include "chrome/grit/chromium_strings.h" 29 #include "chrome/grit/chromium_strings.h"
29 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 62
62 enum SessionCrashedBubbleHistogramValue { 63 enum SessionCrashedBubbleHistogramValue {
63 SESSION_CRASHED_BUBBLE_SHOWN, 64 SESSION_CRASHED_BUBBLE_SHOWN,
64 SESSION_CRASHED_BUBBLE_ERROR, 65 SESSION_CRASHED_BUBBLE_ERROR,
65 SESSION_CRASHED_BUBBLE_RESTORED, 66 SESSION_CRASHED_BUBBLE_RESTORED,
66 SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN, 67 SESSION_CRASHED_BUBBLE_ALREADY_UMA_OPTIN,
67 SESSION_CRASHED_BUBBLE_UMA_OPTIN, 68 SESSION_CRASHED_BUBBLE_UMA_OPTIN,
68 SESSION_CRASHED_BUBBLE_HELP, 69 SESSION_CRASHED_BUBBLE_HELP,
69 SESSION_CRASHED_BUBBLE_IGNORED, 70 SESSION_CRASHED_BUBBLE_IGNORED,
70 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN, 71 SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN,
72 SESSION_CRASHED_BUBBLE_STARTUP_PAGES,
71 SESSION_CRASHED_BUBBLE_MAX, 73 SESSION_CRASHED_BUBBLE_MAX,
72 }; 74 };
73 75
74 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) { 76 void RecordBubbleHistogramValue(SessionCrashedBubbleHistogramValue value) {
75 UMA_HISTOGRAM_ENUMERATION( 77 UMA_HISTOGRAM_ENUMERATION(
76 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX); 78 "SessionCrashed.Bubble", value, SESSION_CRASHED_BUBBLE_MAX);
77 } 79 }
78 80
79 // Whether or not the bubble UI should be used. 81 // Whether or not the bubble UI should be used.
80 // TODO(crbug.com/653966): Enable this on all desktop platforms. 82 // TODO(crbug.com/653966): Enable this on all desktop platforms.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 Browser* browser, 197 Browser* browser,
196 content::WebContents* web_contents, 198 content::WebContents* web_contents,
197 bool offer_uma_optin) 199 bool offer_uma_optin)
198 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 200 : BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
199 content::WebContentsObserver(web_contents), 201 content::WebContentsObserver(web_contents),
200 browser_(browser), 202 browser_(browser),
201 web_contents_(web_contents), 203 web_contents_(web_contents),
202 uma_option_(NULL), 204 uma_option_(NULL),
203 offer_uma_optin_(offer_uma_optin), 205 offer_uma_optin_(offer_uma_optin),
204 first_navigation_ignored_(false), 206 first_navigation_ignored_(false),
205 restored_(false) { 207 restored_(false),
208 startup_pages_(false) {
206 set_close_on_deactivate(false); 209 set_close_on_deactivate(false);
207 registrar_.Add( 210 registrar_.Add(
208 this, 211 this,
209 chrome::NOTIFICATION_TAB_CLOSING, 212 chrome::NOTIFICATION_TAB_CLOSING,
210 content::Source<content::NavigationController>(&( 213 content::Source<content::NavigationController>(&(
211 web_contents->GetController()))); 214 web_contents->GetController())));
212 browser->tab_strip_model()->AddObserver(this); 215 browser->tab_strip_model()->AddObserver(this);
213 } 216 }
214 217
215 SessionCrashedBubbleView::~SessionCrashedBubbleView() { 218 SessionCrashedBubbleView::~SessionCrashedBubbleView() {
216 browser_->tab_strip_model()->RemoveObserver(this); 219 browser_->tab_strip_model()->RemoveObserver(this);
217 } 220 }
218 221
219 base::string16 SessionCrashedBubbleView::GetWindowTitle() const { 222 base::string16 SessionCrashedBubbleView::GetWindowTitle() const {
220 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE); 223 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_BUBBLE_TITLE);
221 } 224 }
222 225
223 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const { 226 bool SessionCrashedBubbleView::ShouldShowWindowTitle() const {
224 return true; 227 return true;
225 } 228 }
226 229
227 bool SessionCrashedBubbleView::ShouldShowCloseButton() const { 230 bool SessionCrashedBubbleView::ShouldShowCloseButton() const {
228 return true; 231 return true;
229 } 232 }
230 233
231 void SessionCrashedBubbleView::OnWidgetDestroying(views::Widget* widget) { 234 void SessionCrashedBubbleView::OnWidgetDestroying(views::Widget* widget) {
232 if (!restored_) 235 if (!restored_ && !startup_pages_)
233 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_IGNORED); 236 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_IGNORED);
234 BubbleDialogDelegateView::OnWidgetDestroying(widget); 237 BubbleDialogDelegateView::OnWidgetDestroying(widget);
235 } 238 }
236 239
237 void SessionCrashedBubbleView::Init() { 240 void SessionCrashedBubbleView::Init() {
238 SetLayoutManager(new views::FillLayout()); 241 SetLayoutManager(new views::FillLayout());
239 242
240 // Description text label. 243 // Description text label.
241 views::Label* text_label = new views::Label( 244 views::Label* text_label = new views::Label(
242 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE)); 245 l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_MESSAGE));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 uma_layout->AddView(uma_label); 306 uma_layout->AddView(uma_label);
304 307
305 return uma_view; 308 return uma_view;
306 } 309 }
307 310
308 bool SessionCrashedBubbleView::Accept() { 311 bool SessionCrashedBubbleView::Accept() {
309 RestorePreviousSession(); 312 RestorePreviousSession();
310 return true; 313 return true;
311 } 314 }
312 315
316 bool SessionCrashedBubbleView::Cancel() {
317 OpenStartupPages();
sky 2017/01/24 23:00:40 On quick glance this looks wrong. It's worth a com
MAD 2017/01/25 19:48:53 Done.
318 return true;
319 }
320
313 bool SessionCrashedBubbleView::Close() { 321 bool SessionCrashedBubbleView::Close() {
314 // Don't default to Accept() just because that's the only choice. Instead, do 322 // Don't default to Accept() just because that's the only choice. Instead, do
315 // nothing. 323 // nothing.
316 return true; 324 return true;
317 } 325 }
318 326
319 int SessionCrashedBubbleView::GetDialogButtons() const { 327 int SessionCrashedBubbleView::GetDialogButtons() const {
320 return ui::DIALOG_BUTTON_OK; 328 int buttons = ui::DIALOG_BUTTON_OK;
329 if (SessionStartupPref::GetStartupPref(browser_->profile()).type ==
330 SessionStartupPref::URLS) {
331 buttons |= ui::DIALOG_BUTTON_CANCEL;
332 }
333 return buttons;
321 } 334 }
322 335
323 base::string16 SessionCrashedBubbleView::GetDialogButtonLabel( 336 base::string16 SessionCrashedBubbleView::GetDialogButtonLabel(
324 ui::DialogButton button) const { 337 ui::DialogButton button) const {
325 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON); 338 if (button == ui::DIALOG_BUTTON_OK)
339 return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON);
340 DCHECK(button == ui::DIALOG_BUTTON_CANCEL);
sky 2017/01/24 23:00:39 DCHECK_EQ
MAD 2017/01/25 19:48:53 Done.
341 DCHECK(SessionStartupPref::GetStartupPref(browser_->profile()).type ==
sky 2017/01/24 23:00:39 DCHECK_EQ: although I'm mildly worried about sync
MAD 2017/01/25 19:48:53 Done.
342 SessionStartupPref::URLS);
343 return l10n_util::GetStringUTF16(
344 IDS_SESSION_CRASHED_VIEW_STARTUP_PAGES_BUTTON);
326 } 345 }
327 346
328 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, 347 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
329 const gfx::Range& range, 348 const gfx::Range& range,
330 int event_flags) { 349 int event_flags) {
331 browser_->OpenURL(content::OpenURLParams( 350 browser_->OpenURL(content::OpenURLParams(
332 GURL("https://support.google.com/chrome/answer/96817"), 351 GURL("https://support.google.com/chrome/answer/96817"),
333 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 352 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
334 ui::PAGE_TRANSITION_LINK, false)); 353 ui::PAGE_TRANSITION_LINK, false));
335 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP); 354 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 int index) { 391 int index) {
373 if (web_contents_ == contents) 392 if (web_contents_ == contents)
374 CloseBubble(); 393 CloseBubble();
375 } 394 }
376 395
377 void SessionCrashedBubbleView::RestorePreviousSession() { 396 void SessionCrashedBubbleView::RestorePreviousSession() {
378 SessionRestore::RestoreSessionAfterCrash(browser_); 397 SessionRestore::RestoreSessionAfterCrash(browser_);
379 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); 398 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED);
380 restored_ = true; 399 restored_ = true;
381 400
401 MaybeEnableUMA();
402 CloseBubble();
403 }
404
405 void SessionCrashedBubbleView::OpenStartupPages() {
406 SessionRestore::OpenStartupPagesAfterCrash(browser_);
sky 2017/01/24 23:00:40 Restoring tabs has side effects. Please restore la
MAD 2017/01/25 19:48:53 Done.
407 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_STARTUP_PAGES);
408 startup_pages_ = true;
409
410 MaybeEnableUMA();
411 CloseBubble();
412 }
413
414 void SessionCrashedBubbleView::MaybeEnableUMA() {
382 // Record user's choice for opt-in in to UMA. 415 // Record user's choice for opt-in in to UMA.
383 // There's no opt-out choice in the crash restore bubble. 416 // There's no opt-out choice in the crash restore bubble.
384 if (uma_option_ && uma_option_->checked()) { 417 if (uma_option_ && uma_option_->checked()) {
385 ChangeMetricsReportingState(true); 418 ChangeMetricsReportingState(true);
386 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); 419 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN);
387 } 420 }
388 CloseBubble();
389 } 421 }
390 422
391 void SessionCrashedBubbleView::CloseBubble() { 423 void SessionCrashedBubbleView::CloseBubble() {
392 GetWidget()->Close(); 424 GetWidget()->Close();
393 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698