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

Side by Side Diff: chrome/browser/ui/sad_tab.cc

Issue 2261793002: Bring the feedback button to the Mac sad tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Address second wave of comments, turn off feedback in non-Chrome builds Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/sad_tab.h ('k') | chrome/browser/ui/sad_tab_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "build/build_config.h"
6 #include "chrome/browser/ui/sad_tab.h" 5 #include "chrome/browser/ui/sad_tab.h"
7 6
7 #include "base/metrics/histogram_macros.h"
8 #include "chrome/browser/net/referrer.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/chrome_pages.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "components/feedback/feedback_util.h"
14 #include "components/strings/grit/components_strings.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/web_contents.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/memory/oom_memory_details.h"
21 #endif
22
23 namespace {
24
25 // These stats should use the same counting approach and bucket size as tab
26 // discard events in memory::OomPriorityManager so they can be directly
27 // compared.
28
29 // This macro uses a static counter to track how many times it's hit in a
30 // session. See Tabs.SadTab.CrashCreated in histograms.xml for details.
31 #define UMA_SAD_TAB_COUNTER(histogram_name) \
32 { \
33 static int count = 0; \
34 ++count; \
35 UMA_HISTOGRAM_COUNTS_1000(histogram_name, count); \
36 }
37
38 // This enum backs an UMA histogram, so it should be treated as append-only.
39 enum SadTabEvent {
40 DISPLAYED,
41 BUTTON_CLICKED,
42 HELP_LINK_CLICKED,
43 MAX_SAD_TAB_EVENT
44 };
45
46 void RecordEvent(bool feedback, SadTabEvent event) {
47 if (feedback) {
48 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.Feedback.Event", event,
49 SadTabEvent::MAX_SAD_TAB_EVENT);
50 } else {
51 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.Reload.Event", event,
52 SadTabEvent::MAX_SAD_TAB_EVENT);
53 }
54 }
55
56 const char kCategoryTagCrash[] = "Crash";
57
58 bool ShouldShowFeedbackButton() {
59 #if defined(GOOGLE_CHROME_BUILD)
60 const int kCrashesBeforeFeedbackIsDisplayed = 1;
61
62 static int total_crashes = 0;
63 return ++total_crashes > kCrashesBeforeFeedbackIsDisplayed;
64 #else
65 return false;
66 #endif
67 }
68
69 } // namespace
70
8 namespace chrome { 71 namespace chrome {
9 72
10 // static 73 // static
11 bool SadTab::ShouldShow(base::TerminationStatus status) { 74 bool SadTab::ShouldShow(base::TerminationStatus status) {
12 return (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || 75 switch (status) {
13 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || 76 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
14 #if defined(OS_CHROMEOS) 77 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
15 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || 78 #if defined(OS_CHROMEOS)
16 #endif 79 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
17 status == base::TERMINATION_STATUS_PROCESS_CRASHED || 80 #endif
18 status == base::TERMINATION_STATUS_OOM); 81 case base::TERMINATION_STATUS_PROCESS_CRASHED:
82 case base::TERMINATION_STATUS_OOM:
83 return true;
84 case base::TERMINATION_STATUS_NORMAL_TERMINATION:
85 case base::TERMINATION_STATUS_STILL_RUNNING:
86 #if defined(OS_ANDROID)
87 case base::TERMINATION_STATUS_OOM_PROTECTED:
88 #endif
89 case base::TERMINATION_STATUS_LAUNCH_FAILED:
90 case base::TERMINATION_STATUS_MAX_ENUM:
91 return false;
92 }
93 NOTREACHED();
94 return false;
95 }
96
97 int SadTab::GetTitle() {
98 return IDS_SAD_TAB_TITLE;
99 }
100
101 int SadTab::GetMessage() {
102 switch (kind_) {
103 #if defined(OS_CHROMEOS)
104 case chrome::SAD_TAB_KIND_KILLED_BY_OOM:
105 return IDS_KILLED_TAB_BY_OOM_MESSAGE;
106 #endif
107 case chrome::SAD_TAB_KIND_OOM:
108 return IDS_SAD_TAB_OOM_MESSAGE;
109 case chrome::SAD_TAB_KIND_CRASHED:
110 case chrome::SAD_TAB_KIND_KILLED:
111 return IDS_SAD_TAB_MESSAGE;
112 }
113 NOTREACHED();
114 return 0;
115 }
116
117 int SadTab::GetButtonTitle() {
118 return show_feedback_button_ ? IDS_CRASHED_TAB_FEEDBACK_LINK
119 : IDS_SAD_TAB_RELOAD_LABEL;
120 }
121
122 int SadTab::GetHelpLinkTitle() {
123 return IDS_SAD_TAB_LEARN_MORE_LINK;
124 }
125
126 const char* SadTab::GetHelpLinkURL() {
127 return show_feedback_button_ ? chrome::kCrashReasonFeedbackDisplayedURL
128 : chrome::kCrashReasonURL;
129 }
130
131 void SadTab::RecordFirstPaint() {
132 DCHECK(!recorded_paint_);
133 recorded_paint_ = true;
134
135 switch (kind_) {
136 case chrome::SAD_TAB_KIND_CRASHED:
137 UMA_SAD_TAB_COUNTER("Tabs.SadTab.CrashDisplayed");
138 break;
139 case chrome::SAD_TAB_KIND_OOM:
140 UMA_SAD_TAB_COUNTER("Tabs.SadTab.OomDisplayed");
141 break;
142 #if defined(OS_CHROMEOS)
143 case chrome::SAD_TAB_KIND_KILLED_BY_OOM:
144 UMA_SAD_TAB_COUNTER("Tabs.SadTab.KillDisplayed.OOM");
145 #endif
146 // Fallthrough
147 case chrome::SAD_TAB_KIND_KILLED:
148 UMA_SAD_TAB_COUNTER("Tabs.SadTab.KillDisplayed");
149 break;
150 }
151
152 RecordEvent(show_feedback_button_, SadTabEvent::DISPLAYED);
153 }
154
155 void SadTab::PerformAction(SadTab::Action action) {
156 DCHECK(recorded_paint_);
157 switch (action) {
158 case Action::BUTTON:
159 RecordEvent(show_feedback_button_, SadTabEvent::BUTTON_CLICKED);
160 if (show_feedback_button_) {
161 chrome::ShowFeedbackPage(
162 chrome::FindBrowserWithWebContents(web_contents_),
163 l10n_util::GetStringUTF8(kind_ == chrome::SAD_TAB_KIND_CRASHED
164 ? IDS_CRASHED_TAB_FEEDBACK_MESSAGE
165 : IDS_KILLED_TAB_FEEDBACK_MESSAGE),
166 std::string(kCategoryTagCrash));
167 } else {
168 web_contents_->GetController().Reload(true);
169 }
170 break;
171 case Action::HELP_LINK:
172 RecordEvent(show_feedback_button_, SadTabEvent::HELP_LINK_CLICKED);
173 content::OpenURLParams params(GURL(GetHelpLinkURL()), content::Referrer(),
174 WindowOpenDisposition::CURRENT_TAB,
175 ui::PAGE_TRANSITION_LINK, false);
176 web_contents_->OpenURL(params);
177 break;
178 }
179 }
180
181 SadTab::SadTab(content::WebContents* web_contents, SadTabKind kind)
182 : web_contents_(web_contents),
183 kind_(kind),
184 show_feedback_button_(ShouldShowFeedbackButton()),
185 recorded_paint_(false) {
186 switch (kind) {
187 case chrome::SAD_TAB_KIND_CRASHED:
188 UMA_SAD_TAB_COUNTER("Tabs.SadTab.CrashCreated");
189 break;
190 case chrome::SAD_TAB_KIND_OOM:
191 UMA_SAD_TAB_COUNTER("Tabs.SadTab.OomCreated");
192 break;
193 #if defined(OS_CHROMEOS)
194 case chrome::SAD_TAB_KIND_KILLED_BY_OOM:
195 UMA_SAD_TAB_COUNTER("Tabs.SadTab.KillCreated.OOM");
196 {
197 const std::string spec = web_contents->GetURL().GetOrigin().spec();
198 memory::OomMemoryDetails::Log(
199 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure());
200 }
201 #endif
202 // Fall through
203 case chrome::SAD_TAB_KIND_KILLED:
204 UMA_SAD_TAB_COUNTER("Tabs.SadTab.KillCreated");
205 LOG(WARNING) << "Tab Killed: "
206 << web_contents->GetURL().GetOrigin().spec();
207 break;
208 }
19 } 209 }
20 210
21 } // namespace chrome 211 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/sad_tab.h ('k') | chrome/browser/ui/sad_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698