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

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: Typo fix Created 3 years, 11 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();
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(SessionStartupPref::GetStartupPref(browser_->profile()).type ==
Georges Khalil 2017/01/24 17:18:29 nit: Not sure if it's worth it, but also a DCHECK(
MAD 2017/01/24 18:24:18 Done.
341 SessionStartupPref::URLS);
342 return l10n_util::GetStringUTF16(
343 IDS_SESSION_CRASHED_VIEW_STARTUP_PAGES_BUTTON);
326 } 344 }
327 345
328 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label, 346 void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
329 const gfx::Range& range, 347 const gfx::Range& range,
330 int event_flags) { 348 int event_flags) {
331 browser_->OpenURL(content::OpenURLParams( 349 browser_->OpenURL(content::OpenURLParams(
332 GURL("https://support.google.com/chrome/answer/96817"), 350 GURL("https://support.google.com/chrome/answer/96817"),
333 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 351 content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
334 ui::PAGE_TRANSITION_LINK, false)); 352 ui::PAGE_TRANSITION_LINK, false));
335 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP); 353 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_HELP);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 int index) { 390 int index) {
373 if (web_contents_ == contents) 391 if (web_contents_ == contents)
374 CloseBubble(); 392 CloseBubble();
375 } 393 }
376 394
377 void SessionCrashedBubbleView::RestorePreviousSession() { 395 void SessionCrashedBubbleView::RestorePreviousSession() {
378 SessionRestore::RestoreSessionAfterCrash(browser_); 396 SessionRestore::RestoreSessionAfterCrash(browser_);
379 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED); 397 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED);
380 restored_ = true; 398 restored_ = true;
381 399
400 MaybeEnableUMA();
401 CloseBubble();
402 }
403
404 void SessionCrashedBubbleView::OpenStartupPages() {
405 SessionRestore::OpenStartupPagesAfterCrash(browser_);
406 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_STARTUP_PAGES);
407 startup_pages_ = true;
408
409 MaybeEnableUMA();
410 CloseBubble();
411 }
412
413 void SessionCrashedBubbleView::MaybeEnableUMA() {
382 // Record user's choice for opt-in in to UMA. 414 // Record user's choice for opt-in in to UMA.
383 // There's no opt-out choice in the crash restore bubble. 415 // There's no opt-out choice in the crash restore bubble.
384 if (uma_option_ && uma_option_->checked()) { 416 if (uma_option_ && uma_option_->checked()) {
385 ChangeMetricsReportingState(true); 417 ChangeMetricsReportingState(true);
386 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN); 418 RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN);
387 } 419 }
388 CloseBubble();
389 } 420 }
390 421
391 void SessionCrashedBubbleView::CloseBubble() { 422 void SessionCrashedBubbleView::CloseBubble() {
392 GetWidget()->Close(); 423 GetWidget()->Close();
393 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698