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

Unified Diff: chrome/browser/ui/views/session_crashed_bubble_view.cc

Issue 2644663003: Offer to open the startup pages after a crash. (Closed)
Patch Set: Missed an unsaved file :-( 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/session_crashed_bubble_view.cc
diff --git a/chrome/browser/ui/views/session_crashed_bubble_view.cc b/chrome/browser/ui/views/session_crashed_bubble_view.cc
index 0954fcaaa20a3f54add2878984b90b2395249829..769d58512c0314b9e4945d1a8dbd896416902e67 100644
--- a/chrome/browser/ui/views/session_crashed_bubble_view.cc
+++ b/chrome/browser/ui/views/session_crashed_bubble_view.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
+#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_list_observer.h"
@@ -68,6 +69,7 @@ enum SessionCrashedBubbleHistogramValue {
SESSION_CRASHED_BUBBLE_HELP,
SESSION_CRASHED_BUBBLE_IGNORED,
SESSION_CRASHED_BUBBLE_OPTIN_BAR_SHOWN,
+ SESSION_CRASHED_BUBBLE_STARTUP_PAGES,
SESSION_CRASHED_BUBBLE_MAX,
};
@@ -202,7 +204,7 @@ SessionCrashedBubbleView::SessionCrashedBubbleView(
uma_option_(NULL),
offer_uma_optin_(offer_uma_optin),
first_navigation_ignored_(false),
- restored_(false) {
+ ignored_(true) {
set_close_on_deactivate(false);
registrar_.Add(
this,
@@ -229,7 +231,7 @@ bool SessionCrashedBubbleView::ShouldShowCloseButton() const {
}
void SessionCrashedBubbleView::OnWidgetDestroying(views::Widget* widget) {
- if (!restored_)
+ if (ignored_)
RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_IGNORED);
BubbleDialogDelegateView::OnWidgetDestroying(widget);
}
@@ -310,6 +312,13 @@ bool SessionCrashedBubbleView::Accept() {
return true;
}
+// The cancel button is used as an option to open the startup pages instead of
+// restoring the previous session.
+bool SessionCrashedBubbleView::Cancel() {
+ OpenStartupPages();
+ return true;
+}
+
bool SessionCrashedBubbleView::Close() {
// Don't default to Accept() just because that's the only choice. Instead, do
// nothing.
@@ -317,12 +326,25 @@ bool SessionCrashedBubbleView::Close() {
}
int SessionCrashedBubbleView::GetDialogButtons() const {
- return ui::DIALOG_BUTTON_OK;
+ int buttons = ui::DIALOG_BUTTON_OK;
+ // Offer the option to open the startup pages using the cancel button, but
+ // only when the user has selected the URLS option, and set at least one url.
+ SessionStartupPref session_startup_pref =
+ SessionStartupPref::GetStartupPref(browser_->profile());
+ if (session_startup_pref.type == SessionStartupPref::URLS &&
+ !session_startup_pref.urls.empty()) {
+ buttons |= ui::DIALOG_BUTTON_CANCEL;
+ }
+ return buttons;
}
base::string16 SessionCrashedBubbleView::GetDialogButtonLabel(
ui::DialogButton button) const {
- return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON);
+ if (button == ui::DIALOG_BUTTON_OK)
+ return l10n_util::GetStringUTF16(IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON);
+ DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button);
+ return l10n_util::GetStringUTF16(
+ IDS_SESSION_CRASHED_VIEW_STARTUP_PAGES_BUTTON);
}
void SessionCrashedBubbleView::StyledLabelLinkClicked(views::StyledLabel* label,
@@ -375,17 +397,34 @@ void SessionCrashedBubbleView::TabDetachedAt(content::WebContents* contents,
}
void SessionCrashedBubbleView::RestorePreviousSession() {
- SessionRestore::RestoreSessionAfterCrash(browser_);
+ ignored_ = false;
+ MaybeEnableUMA();
+ CloseBubble();
+
RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_RESTORED);
- restored_ = true;
+ // Restoring tabs has side effects, so it's preferable to do it after the
+ // bubble was closed.
+ SessionRestore::RestoreSessionAfterCrash(browser_);
+}
+
+void SessionCrashedBubbleView::OpenStartupPages() {
+ ignored_ = false;
+ MaybeEnableUMA();
+ CloseBubble();
+ RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_STARTUP_PAGES);
+ // Opening tabs has side effects, so it's preferable to do it after the bubble
+ // was closed.
+ SessionRestore::OpenStartupPagesAfterCrash(browser_);
+}
+
+void SessionCrashedBubbleView::MaybeEnableUMA() {
// Record user's choice for opt-in in to UMA.
// There's no opt-out choice in the crash restore bubble.
if (uma_option_ && uma_option_->checked()) {
ChangeMetricsReportingState(true);
RecordBubbleHistogramValue(SESSION_CRASHED_BUBBLE_UMA_OPTIN);
}
- CloseBubble();
}
void SessionCrashedBubbleView::CloseBubble() {

Powered by Google App Engine
This is Rietveld 408576698