Chromium Code Reviews| 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.h" |
|
Ilya Sherman
2016/08/22 20:52:13
nit: histogram_macros
Sidney San Martín
2016/08/25 00:55:11
Done.
| |
| 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 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab." NAME, ++count); \ | |
|
Ilya Sherman
2016/08/22 20:52:13
nit: Please move the increment statement to a sepa
| |
| 37 } | |
| 38 | |
| 39 enum class SadTabEvent { | |
|
Ilya Sherman
2016/08/22 20:52:12
Please document that this enum is used to back an
Sidney San Martín
2016/08/25 00:55:11
Done — borrowed an existing comment.
| |
| 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) { | |
|
Ilya Sherman
2016/08/22 20:52:13
What determines whether the feedback style or relo
Sidney San Martín
2016/08/25 00:55:11
The first sad tab you see in a session will be rel
| |
| 48 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleFeedback", event, | |
| 49 SadTabEvent::MAX_SAD_TAB_EVENT); | |
| 50 } else { | |
| 51 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleReload", event, | |
| 52 SadTabEvent::MAX_SAD_TAB_EVENT); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 static const int kCrashesBeforeFeedbackIsDisplayed = 1; | |
| 57 static const char kCategoryTagCrash[] = "Crash"; | |
| 58 | |
| 59 bool ShouldWantFeedback() { | |
| 60 static int total_crashes = 0; | |
| 61 return ++total_crashes > kCrashesBeforeFeedbackIsDisplayed; | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 7 | 65 |
| 8 namespace chrome { | 66 namespace chrome { |
| 9 | 67 |
| 10 // static | 68 // static |
| 11 bool SadTab::ShouldShow(base::TerminationStatus status) { | 69 bool SadTab::ShouldShow(base::TerminationStatus status) { |
| 12 return (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || | 70 switch (status) { |
| 13 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || | 71 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 72 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | |
| 14 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
| 15 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || | 74 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 16 #endif | 75 #endif |
| 17 status == base::TERMINATION_STATUS_PROCESS_CRASHED || | 76 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 18 status == base::TERMINATION_STATUS_OOM); | 77 case base::TERMINATION_STATUS_OOM: |
| 78 return true; | |
| 79 default: | |
| 80 return false; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 SadTab::SadTab(content::WebContents* web_contents, SadTabKind kind) | |
| 85 : web_contents_(web_contents), | |
| 86 kind_(kind), | |
| 87 want_feedback_(ShouldWantFeedback()) { | |
| 88 switch (kind) { | |
| 89 case chrome::SAD_TAB_KIND_CRASHED: | |
| 90 UMA_SAD_TAB_COUNTER("CrashCreated"); | |
| 91 break; | |
| 92 case chrome::SAD_TAB_KIND_OOM: | |
| 93 UMA_SAD_TAB_COUNTER("OomCreated"); | |
| 94 break; | |
| 95 #if defined(OS_CHROMEOS) | |
| 96 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 97 UMA_SAD_TAB_COUNTER("KillCreated.OOM"); | |
| 98 { | |
| 99 const std::string spec = web_contents->GetURL().GetOrigin().spec(); | |
| 100 memory::OomMemoryDetails::Log( | |
| 101 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure()); | |
| 102 } | |
| 103 // Fall through | |
| 104 #endif | |
| 105 case chrome::SAD_TAB_KIND_KILLED: | |
| 106 UMA_SAD_TAB_COUNTER("KillCreated"); | |
| 107 break; | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 int SadTab::GetTitle() { | |
| 112 return IDS_SAD_TAB_TITLE; | |
| 113 } | |
| 114 | |
| 115 int SadTab::GetMessage() { | |
| 116 switch (kind_) { | |
| 117 #if defined(OS_CHROMEOS) | |
| 118 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 119 return IDS_KILLED_TAB_BY_OOM_MESSAGE; | |
| 120 #endif | |
| 121 case chrome::SAD_TAB_KIND_OOM: | |
| 122 return IDS_SAD_TAB_OOM_MESSAGE; | |
| 123 default: | |
| 124 return IDS_SAD_TAB_MESSAGE; | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 int SadTab::GetButtonTitle() { | |
| 129 return want_feedback_ ? IDS_CRASHED_TAB_FEEDBACK_LINK | |
| 130 : IDS_SAD_TAB_RELOAD_LABEL; | |
| 131 } | |
| 132 | |
| 133 int SadTab::GetHelpLinkTitle() { | |
| 134 return IDS_SAD_TAB_LEARN_MORE_LINK; | |
| 135 } | |
| 136 | |
| 137 const char* SadTab::GetHelpLinkURL() { | |
| 138 return want_feedback_ ? chrome::kCrashReasonFeedbackDisplayedURL | |
| 139 : chrome::kCrashReasonURL; | |
| 140 } | |
| 141 | |
| 142 void SadTab::RecordFirstPaint() { | |
| 143 #if DCHECK_IS_ON() | |
| 144 DLOG_ASSERT(!recorded_paint_); | |
| 145 recorded_paint_ = true; | |
| 146 #endif | |
| 147 | |
| 148 switch (kind_) { | |
| 149 case chrome::SAD_TAB_KIND_CRASHED: | |
| 150 UMA_SAD_TAB_COUNTER("CrashDisplayed"); | |
| 151 break; | |
| 152 case chrome::SAD_TAB_KIND_OOM: | |
| 153 UMA_SAD_TAB_COUNTER("OomDisplayed"); | |
| 154 break; | |
| 155 #if defined(OS_CHROMEOS) | |
| 156 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 157 UMA_SAD_TAB_COUNTER("KillDisplayed.OOM"); | |
| 158 // Fallthrough | |
| 159 #endif | |
| 160 case chrome::SAD_TAB_KIND_KILLED: | |
| 161 UMA_SAD_TAB_COUNTER("KillDisplayed"); | |
| 162 break; | |
| 163 } | |
| 164 | |
| 165 RecordEvent(want_feedback_, SadTabEvent::DISPLAYED); | |
| 166 } | |
| 167 | |
| 168 void SadTab::PerformAction(SadTab::Action action) { | |
| 169 DLOG_ASSERT(recorded_paint_); | |
| 170 switch (action) { | |
| 171 case Action::BUTTON: | |
| 172 RecordEvent(want_feedback_, SadTabEvent::BUTTON_CLICKED); | |
| 173 if (want_feedback_) { | |
| 174 chrome::ShowFeedbackPage( | |
|
Sidney San Martín
2016/08/22 05:54:51
ShowFeedbackPage looks like a no-op on Chromium bu
| |
| 175 chrome::FindBrowserWithWebContents(web_contents_), | |
| 176 l10n_util::GetStringUTF8(kind_ == chrome::SAD_TAB_KIND_CRASHED | |
| 177 ? IDS_CRASHED_TAB_FEEDBACK_MESSAGE | |
| 178 : IDS_KILLED_TAB_FEEDBACK_MESSAGE), | |
| 179 std::string(kCategoryTagCrash)); | |
| 180 } else { | |
| 181 web_contents_->GetController().Reload(true); | |
| 182 } | |
| 183 break; | |
| 184 case Action::HELP_LINK: | |
| 185 RecordEvent(want_feedback_, SadTabEvent::HELP_LINK_CLICKED); | |
| 186 content::OpenURLParams params(GURL(GetHelpLinkURL()), content::Referrer(), | |
| 187 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | |
| 188 false); | |
| 189 web_contents_->OpenURL(params); | |
| 190 break; | |
| 191 } | |
| 19 } | 192 } |
| 20 | 193 |
| 21 } // namespace chrome | 194 } // namespace chrome |
| OLD | NEW |