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" | |
| 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 // TODO(jamescook): Maybe track time between sad tabs? | |
|
James Cook
2016/09/08 20:15:50
Feel free to nuke this -- it's not going to happen
Sidney San Martín
2016/09/09 01:36:00
Done :).
| |
| 29 | |
| 30 // This macro uses a static counter to track how many times it's hit in a | |
| 31 // session. See Tabs.SadTab.CrashCreated in histograms.xml for details. | |
| 32 #define UMA_SAD_TAB_COUNTER(NAME) \ | |
|
James Cook
2016/09/08 20:15:50
I wouldn't do this with a macro and string concate
Sidney San Martín
2016/09/09 01:36:00
The macro deals with creating a block with a stati
James Cook
2016/09/09 04:37:08
This is fine. However, please change NAME to |hist
Sidney San Martín
2016/09/09 15:39:44
Done.
| |
| 33 { \ | |
| 34 static int count = 0; \ | |
| 35 ++count; \ | |
| 36 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab." NAME, count); \ | |
| 37 } | |
| 38 | |
| 39 // This enum backs an UMA histogram, so it should be treated as append-only. | |
| 40 enum class SadTabEvent { | |
| 41 DISPLAYED, | |
| 42 BUTTON_CLICKED, | |
| 43 HELP_LINK_CLICKED, | |
| 44 MAX_SAD_TAB_EVENT | |
| 45 }; | |
| 46 | |
| 47 void RecordEvent(bool feedback, SadTabEvent event) { | |
| 48 if (feedback) { | |
| 49 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleFeedback", event, | |
|
James Cook
2016/09/08 20:15:50
I would call these either CreatedWithFeedback or D
Sidney San Martín
2016/09/09 01:36:00
These histograms are for other events (BUTTON_CLIC
James Cook
2016/09/09 04:37:08
Hrm, I missed that distinction when reading this c
Sidney San Martín
2016/09/09 15:39:44
Done. I like the idea of splitting it up.
| |
| 50 SadTabEvent::MAX_SAD_TAB_EVENT); | |
| 51 } else { | |
| 52 UMA_HISTOGRAM_ENUMERATION("Tabs.SadTab.StyleReload", event, | |
| 53 SadTabEvent::MAX_SAD_TAB_EVENT); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 static const int kCrashesBeforeFeedbackIsDisplayed = 1; | |
|
James Cook
2016/09/08 20:15:50
nit: static not needed in anonymous namespace
Sidney San Martín
2016/09/09 01:36:00
Good catch, removed.
| |
| 58 static const char kCategoryTagCrash[] = "Crash"; | |
| 59 | |
| 60 bool ShouldWantFeedback() { | |
| 61 static int total_crashes = 0; | |
| 62 return ++total_crashes > kCrashesBeforeFeedbackIsDisplayed; | |
|
James Cook
2016/09/08 20:15:50
Aside: I had no idea we had this feature. It seems
Sidney San Martín
2016/09/09 01:36:00
It's what we do on other platforms, but I bet it w
| |
| 63 } | |
| 64 | |
| 65 } // namespace | |
| 66 | |
| 8 namespace chrome { | 67 namespace chrome { |
| 9 | 68 |
| 10 // static | 69 // static |
| 11 bool SadTab::ShouldShow(base::TerminationStatus status) { | 70 bool SadTab::ShouldShow(base::TerminationStatus status) { |
| 12 return (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || | 71 switch (status) { |
| 13 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || | 72 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 14 #if defined(OS_CHROMEOS) | 73 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 15 status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || | 74 #if defined(OS_CHROMEOS) |
| 16 #endif | 75 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
| 17 status == base::TERMINATION_STATUS_PROCESS_CRASHED || | 76 #endif |
| 18 status == base::TERMINATION_STATUS_OOM); | 77 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 78 case base::TERMINATION_STATUS_OOM: | |
| 79 return true; | |
| 80 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | |
| 81 case base::TERMINATION_STATUS_STILL_RUNNING: | |
| 82 #if defined(OS_ANDROID) | |
| 83 case base::TERMINATION_STATUS_OOM_PROTECTED: | |
| 84 #endif | |
| 85 case base::TERMINATION_STATUS_LAUNCH_FAILED: | |
| 86 case base::TERMINATION_STATUS_MAX_ENUM: | |
| 87 return false; | |
|
Nico
2016/09/08 17:12:59
Nice change!
| |
| 88 } | |
| 89 NOTREACHED(); | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 SadTab::SadTab(content::WebContents* web_contents, SadTabKind kind) | |
|
James Cook
2016/09/08 20:15:50
nit: make function order in .cc file match declara
Sidney San Martín
2016/09/09 01:36:00
Done. I wonder how hard it would be to make `git c
James Cook
2016/09/09 04:37:08
Yeah, it's kind of a judgement call for me. If you
| |
| 94 : web_contents_(web_contents), | |
| 95 kind_(kind), | |
| 96 want_feedback_(ShouldWantFeedback()) { | |
| 97 switch (kind) { | |
| 98 case chrome::SAD_TAB_KIND_CRASHED: | |
| 99 UMA_SAD_TAB_COUNTER("CrashCreated"); | |
| 100 break; | |
| 101 case chrome::SAD_TAB_KIND_OOM: | |
| 102 UMA_SAD_TAB_COUNTER("OomCreated"); | |
| 103 break; | |
| 104 #if defined(OS_CHROMEOS) | |
| 105 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 106 UMA_SAD_TAB_COUNTER("KillCreated.OOM"); | |
| 107 { | |
| 108 const std::string spec = web_contents->GetURL().GetOrigin().spec(); | |
| 109 memory::OomMemoryDetails::Log( | |
| 110 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure()); | |
| 111 } | |
| 112 // Fall through | |
|
James Cook
2016/09/08 20:15:50
nit: Indent (unless this is the output of clang-fo
Sidney San Martín
2016/09/09 01:36:00
It is from clang-format, sadly.
Nico
2016/09/09 01:48:42
(I think if you switch the #endif and the comment
Sidney San Martín
2016/09/09 15:39:44
Done. I originally avoided doing this… but yeah, i
| |
| 113 #endif | |
| 114 case chrome::SAD_TAB_KIND_KILLED: | |
|
James Cook
2016/09/08 20:15:50
I would keep the LOG(WARNING) about kills. Kills a
Sidney San Martín
2016/09/09 01:36:00
I didn't know that! Thanks, done.
| |
| 115 UMA_SAD_TAB_COUNTER("KillCreated"); | |
| 116 break; | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 int SadTab::GetTitle() { | |
| 121 return IDS_SAD_TAB_TITLE; | |
| 122 } | |
| 123 | |
| 124 int SadTab::GetMessage() { | |
| 125 switch (kind_) { | |
| 126 #if defined(OS_CHROMEOS) | |
| 127 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 128 return IDS_KILLED_TAB_BY_OOM_MESSAGE; | |
| 129 #endif | |
| 130 case chrome::SAD_TAB_KIND_OOM: | |
| 131 return IDS_SAD_TAB_OOM_MESSAGE; | |
| 132 case chrome::SAD_TAB_KIND_CRASHED: | |
| 133 case chrome::SAD_TAB_KIND_KILLED: | |
| 134 return IDS_SAD_TAB_MESSAGE; | |
| 135 } | |
| 136 NOTREACHED(); | |
| 137 return 0; | |
| 138 } | |
| 139 | |
| 140 int SadTab::GetButtonTitle() { | |
| 141 return want_feedback_ ? IDS_CRASHED_TAB_FEEDBACK_LINK | |
| 142 : IDS_SAD_TAB_RELOAD_LABEL; | |
| 143 } | |
| 144 | |
| 145 int SadTab::GetHelpLinkTitle() { | |
| 146 return IDS_SAD_TAB_LEARN_MORE_LINK; | |
| 147 } | |
| 148 | |
| 149 const char* SadTab::GetHelpLinkURL() { | |
| 150 return want_feedback_ ? chrome::kCrashReasonFeedbackDisplayedURL | |
| 151 : chrome::kCrashReasonURL; | |
| 152 } | |
| 153 | |
| 154 void SadTab::RecordFirstPaint() { | |
| 155 #if DCHECK_IS_ON() | |
| 156 DCHECK(!recorded_paint_); | |
| 157 recorded_paint_ = true; | |
| 158 #endif | |
| 159 | |
| 160 switch (kind_) { | |
| 161 case chrome::SAD_TAB_KIND_CRASHED: | |
| 162 UMA_SAD_TAB_COUNTER("CrashDisplayed"); | |
| 163 break; | |
| 164 case chrome::SAD_TAB_KIND_OOM: | |
| 165 UMA_SAD_TAB_COUNTER("OomDisplayed"); | |
| 166 break; | |
| 167 #if defined(OS_CHROMEOS) | |
| 168 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | |
| 169 UMA_SAD_TAB_COUNTER("KillDisplayed.OOM"); | |
| 170 // Fallthrough | |
|
James Cook
2016/09/08 20:15:50
nit: ditto
| |
| 171 #endif | |
| 172 case chrome::SAD_TAB_KIND_KILLED: | |
| 173 UMA_SAD_TAB_COUNTER("KillDisplayed"); | |
| 174 break; | |
| 175 } | |
| 176 | |
| 177 RecordEvent(want_feedback_, SadTabEvent::DISPLAYED); | |
| 178 } | |
| 179 | |
| 180 void SadTab::PerformAction(SadTab::Action action) { | |
| 181 DCHECK(recorded_paint_); | |
| 182 switch (action) { | |
| 183 case Action::BUTTON: | |
| 184 RecordEvent(want_feedback_, SadTabEvent::BUTTON_CLICKED); | |
| 185 if (want_feedback_) { | |
| 186 chrome::ShowFeedbackPage( | |
| 187 chrome::FindBrowserWithWebContents(web_contents_), | |
| 188 l10n_util::GetStringUTF8(kind_ == chrome::SAD_TAB_KIND_CRASHED | |
| 189 ? IDS_CRASHED_TAB_FEEDBACK_MESSAGE | |
| 190 : IDS_KILLED_TAB_FEEDBACK_MESSAGE), | |
| 191 std::string(kCategoryTagCrash)); | |
| 192 } else { | |
| 193 web_contents_->GetController().Reload(true); | |
| 194 } | |
| 195 break; | |
| 196 case Action::HELP_LINK: | |
| 197 RecordEvent(want_feedback_, SadTabEvent::HELP_LINK_CLICKED); | |
| 198 content::OpenURLParams params(GURL(GetHelpLinkURL()), content::Referrer(), | |
| 199 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, | |
| 200 false); | |
| 201 web_contents_->OpenURL(params); | |
| 202 break; | |
| 203 } | |
| 19 } | 204 } |
| 20 | 205 |
| 21 } // namespace chrome | 206 } // namespace chrome |
| OLD | NEW |