OLD | NEW |
---|---|
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" | 5 #include "base/metrics/histogram_macros.h" |
6 #include "chrome/browser/net/referrer.h" | |
7 #include "chrome/browser/ui/browser_finder.h" | |
8 #include "chrome/browser/ui/chrome_pages.h" | |
6 #include "chrome/browser/ui/sad_tab.h" | 9 #include "chrome/browser/ui/sad_tab.h" |
10 #include "chrome/common/url_constants.h" | |
11 #include "chrome/grit/generated_resources.h" | |
12 #include "components/feedback/feedback_util.h" | |
13 #include "components/strings/grit/components_strings.h" | |
14 #include "content/public/browser/navigation_controller.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "grit/components_strings.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 // They use the same counting approach and bucket sizes as the tab discard | |
26 // events in memory::OomPriorityManager so they can be directly compared. | |
27 | |
28 // TODO(jamescook): Maybe track time between sad tabs? | |
29 | |
30 // This macro uses a a static counter to add to the next numbered bucket each | |
31 // time it's hit, to keep track of how many sad tabs of a given kind users see | |
32 // per session. For details, see Tabs.SadTab.CrashCreated in histograms.xml. | |
33 #define UMA_SAD_TAB_COUNTER(NAME) \ | |
34 { \ | |
35 static int count = 0; \ | |
36 ++count; \ | |
37 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab." NAME, count); \ | |
38 } | |
39 | |
40 // This enum backs a UMA histogram, so it should be treated as append-only. | |
41 enum class SadTabEvent { | |
42 DISPLAYED, | |
43 BUTTON_CLICKED, | |
44 HELP_LINK_CLICKED, | |
45 MAX_SAD_TAB_EVENT | |
46 }; | |
47 | |
48 void RecordEvent(bool feedback, SadTabEvent event) { | |
49 if (feedback) { | |
50 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleFeedback", event, | |
51 SadTabEvent::MAX_SAD_TAB_EVENT); | |
52 } else { | |
53 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleReload", event, | |
54 SadTabEvent::MAX_SAD_TAB_EVENT); | |
55 } | |
56 } | |
57 | |
58 static const int kCrashesBeforeFeedbackIsDisplayed = 1; | |
59 static const char kCategoryTagCrash[] = "Crash"; | |
60 | |
61 bool ShouldWantFeedback() { | |
62 static int total_crashes = 0; | |
63 return ++total_crashes > kCrashesBeforeFeedbackIsDisplayed; | |
64 } | |
65 | |
66 } // namespace | |
7 | 67 |
8 namespace chrome { | 68 namespace chrome { |
9 | 69 |
10 // static | 70 // static |
11 bool SadTab::ShouldShow(base::TerminationStatus status) { | 71 bool SadTab::ShouldShow(base::TerminationStatus status) { |
12 return (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || | 72 switch (status) { |
13 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || | 73 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
74 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | |
14 #if defined(OS_CHROMEOS) | 75 #if defined(OS_CHROMEOS) |
15 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || | 76 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
16 #endif | 77 #endif |
17 status == base::TERMINATION_STATUS_PROCESS_CRASHED || | 78 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
18 status == base::TERMINATION_STATUS_OOM); | 79 case base::TERMINATION_STATUS_OOM: |
80 return true; | |
81 default: | |
Will Harris
2016/08/26 16:44:50
remove default, if possible
Sidney San Martín
2016/08/30 19:31:57
Done.
| |
82 return false; | |
83 } | |
84 } | |
85 | |
86 SadTab::SadTab(content::WebContents* web_contents, SadTabKind kind) | |
87 : web_contents_(web_contents), | |
88 kind_(kind), | |
89 want_feedback_(ShouldWantFeedback()) { | |
90 switch (kind) { | |
91 case chrome::SAD_TAB_KIND_CRASHED: | |
92 UMA_SAD_TAB_COUNTER("CrashCreated"); | |
93 break; | |
94 case chrome::SAD_TAB_KIND_OOM: | |
95 UMA_SAD_TAB_COUNTER("OomCreated"); | |
96 break; | |
97 #if defined(OS_CHROMEOS) | |
98 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
99 UMA_SAD_TAB_COUNTER("KillCreated.OOM"); | |
100 { | |
101 const std::string spec = web_contents->GetURL().GetOrigin().spec(); | |
102 memory::OomMemoryDetails::Log( | |
103 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure()); | |
104 } | |
105 // Fall through | |
106 #endif | |
107 case chrome::SAD_TAB_KIND_KILLED: | |
108 UMA_SAD_TAB_COUNTER("KillCreated"); | |
109 break; | |
110 } | |
111 } | |
112 | |
113 int SadTab::GetTitle() { | |
114 return IDS_SAD_TAB_TITLE; | |
115 } | |
116 | |
117 int SadTab::GetMessage() { | |
118 switch (kind_) { | |
119 #if defined(OS_CHROMEOS) | |
120 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
121 return IDS_KILLED_TAB_BY_OOM_MESSAGE; | |
122 #endif | |
123 case chrome::SAD_TAB_KIND_OOM: | |
124 return IDS_SAD_TAB_OOM_MESSAGE; | |
125 default: | |
Will Harris
2016/08/26 16:44:50
can you remove the default clause so additions to
Sidney San Martín
2016/08/30 19:31:57
Done.
| |
126 return IDS_SAD_TAB_MESSAGE; | |
127 } | |
128 } | |
129 | |
130 int SadTab::GetButtonTitle() { | |
131 return want_feedback_ ? IDS_CRASHED_TAB_FEEDBACK_LINK | |
132 : IDS_SAD_TAB_RELOAD_LABEL; | |
133 } | |
134 | |
135 int SadTab::GetHelpLinkTitle() { | |
136 return IDS_SAD_TAB_LEARN_MORE_LINK; | |
137 } | |
138 | |
139 const char* SadTab::GetHelpLinkURL() { | |
140 return want_feedback_ ? chrome::kCrashReasonFeedbackDisplayedURL | |
141 : chrome::kCrashReasonURL; | |
142 } | |
143 | |
144 void SadTab::RecordFirstPaint() { | |
145 #if DCHECK_IS_ON() | |
146 DLOG_ASSERT(!recorded_paint_); | |
147 recorded_paint_ = true; | |
148 #endif | |
149 | |
150 switch (kind_) { | |
151 case chrome::SAD_TAB_KIND_CRASHED: | |
152 UMA_SAD_TAB_COUNTER("CrashDisplayed"); | |
153 break; | |
154 case chrome::SAD_TAB_KIND_OOM: | |
155 UMA_SAD_TAB_COUNTER("OomDisplayed"); | |
156 break; | |
157 #if defined(OS_CHROMEOS) | |
158 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
159 UMA_SAD_TAB_COUNTER("KillDisplayed.OOM"); | |
160 // Fallthrough | |
161 #endif | |
162 case chrome::SAD_TAB_KIND_KILLED: | |
163 UMA_SAD_TAB_COUNTER("KillDisplayed"); | |
164 break; | |
165 } | |
166 | |
167 RecordEvent(want_feedback_, SadTabEvent::DISPLAYED); | |
168 } | |
169 | |
170 void SadTab::PerformAction(SadTab::Action action) { | |
171 DLOG_ASSERT(recorded_paint_); | |
172 switch (action) { | |
173 case Action::BUTTON: | |
174 RecordEvent(want_feedback_, SadTabEvent::BUTTON_CLICKED); | |
175 if (want_feedback_) { | |
176 chrome::ShowFeedbackPage( | |
177 chrome::FindBrowserWithWebContents(web_contents_), | |
178 l10n_util::GetStringUTF8(kind_ == chrome::SAD_TAB_KIND_CRASHED | |
179 ? IDS_CRASHED_TAB_FEEDBACK_MESSAGE | |
180 : IDS_KILLED_TAB_FEEDBACK_MESSAGE), | |
181 std::string(kCategoryTagCrash)); | |
182 } else { | |
183 web_contents_->GetController().Reload(true); | |
184 } | |
185 break; | |
186 case Action::HELP_LINK: | |
187 RecordEvent(want_feedback_, SadTabEvent::HELP_LINK_CLICKED); | |
188 content::OpenURLParams params(GURL(GetHelpLinkURL()), content::Referrer(), | |
189 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | |
190 false); | |
191 web_contents_->OpenURL(params); | |
192 break; | |
193 } | |
19 } | 194 } |
20 | 195 |
21 } // namespace chrome | 196 } // namespace chrome |
OLD | NEW |