| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/sad_tab_view.h" | 5 #include "chrome/browser/ui/views/sad_tab_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const int kMaxContentWidth = 600; | 45 const int kMaxContentWidth = 600; |
| 46 const int kMinColumnWidth = 120; | 46 const int kMinColumnWidth = 120; |
| 47 const char kCategoryTagCrash[] = "Crash"; | 47 const char kCategoryTagCrash[] = "Crash"; |
| 48 const int kCrashesBeforeFeedbackIsDisplayed = 1; | 48 const int kCrashesBeforeFeedbackIsDisplayed = 1; |
| 49 | 49 |
| 50 void RecordKillCreated() { | 50 void RecordKillCreated() { |
| 51 static int killed = 0; | 51 static int killed = 0; |
| 52 killed++; | 52 killed++; |
| 53 UMA_HISTOGRAM_CUSTOM_COUNTS( | 53 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.KillCreated", killed); |
| 54 "Tabs.SadTab.KillCreated", killed, 1, 1000, 50); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 void RecordKillDisplayed() { | 56 void RecordKillDisplayed() { |
| 58 static int killed = 0; | 57 static int killed = 0; |
| 59 killed++; | 58 killed++; |
| 60 UMA_HISTOGRAM_CUSTOM_COUNTS( | 59 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.KillDisplayed", killed); |
| 61 "Tabs.SadTab.KillDisplayed", killed, 1, 1000, 50); | |
| 62 } | 60 } |
| 63 | 61 |
| 64 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
| 65 void RecordKillCreatedOOM() { | 63 void RecordKillCreatedOOM() { |
| 66 static int oom_killed = 0; | 64 static int oom_killed = 0; |
| 67 oom_killed++; | 65 oom_killed++; |
| 68 UMA_HISTOGRAM_CUSTOM_COUNTS( | 66 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.KillCreated.OOM", oom_killed); |
| 69 "Tabs.SadTab.KillCreated.OOM", oom_killed, 1, 1000, 50); | |
| 70 } | 67 } |
| 71 | 68 |
| 72 void RecordKillDisplayedOOM() { | 69 void RecordKillDisplayedOOM() { |
| 73 static int oom_killed = 0; | 70 static int oom_killed = 0; |
| 74 oom_killed++; | 71 oom_killed++; |
| 75 UMA_HISTOGRAM_CUSTOM_COUNTS( | 72 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.KillDisplayed.OOM", oom_killed); |
| 76 "Tabs.SadTab.KillDisplayed.OOM", oom_killed, 1, 1000, 50); | |
| 77 } | 73 } |
| 78 #endif | 74 #endif |
| 79 | 75 |
| 80 } // namespace | 76 } // namespace |
| 81 | 77 |
| 82 int SadTabView::total_crashes_ = 0; | 78 int SadTabView::total_crashes_ = 0; |
| 83 | 79 |
| 84 SadTabView::SadTabView(WebContents* web_contents, chrome::SadTabKind kind) | 80 SadTabView::SadTabView(WebContents* web_contents, chrome::SadTabKind kind) |
| 85 : web_contents_(web_contents), | 81 : web_contents_(web_contents), |
| 86 kind_(kind), | 82 kind_(kind), |
| 87 painted_(false), | 83 painted_(false), |
| 88 message_(nullptr), | 84 message_(nullptr), |
| 89 help_link_(nullptr), | 85 help_link_(nullptr), |
| 90 action_button_(nullptr), | 86 action_button_(nullptr), |
| 91 title_(nullptr), | 87 title_(nullptr), |
| 92 help_message_(nullptr) { | 88 help_message_(nullptr) { |
| 93 DCHECK(web_contents); | 89 DCHECK(web_contents); |
| 94 | 90 |
| 95 // These stats should use the same counting approach and bucket size used for | 91 // These stats should use the same counting approach and bucket size used for |
| 96 // tab discard events in memory::OomPriorityManager so they can be directly | 92 // tab discard events in memory::OomPriorityManager so they can be directly |
| 97 // compared. | 93 // compared. |
| 98 // TODO(jamescook): Maybe track time between sad tabs? | 94 // TODO(jamescook): Maybe track time between sad tabs? |
| 99 total_crashes_++; | 95 total_crashes_++; |
| 100 | 96 |
| 101 switch (kind_) { | 97 switch (kind_) { |
| 102 case chrome::SAD_TAB_KIND_CRASHED: { | 98 case chrome::SAD_TAB_KIND_CRASHED: { |
| 103 static int crashed = 0; | 99 static int crashed = 0; |
| 104 crashed++; | 100 crashed++; |
| 105 UMA_HISTOGRAM_CUSTOM_COUNTS( | 101 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.CrashCreated", crashed); |
| 106 "Tabs.SadTab.CrashCreated", crashed, 1, 1000, 50); | |
| 107 break; | 102 break; |
| 108 } | 103 } |
| 109 case chrome::SAD_TAB_KIND_KILLED: { | 104 case chrome::SAD_TAB_KIND_KILLED: { |
| 110 RecordKillCreated(); | 105 RecordKillCreated(); |
| 111 LOG(WARNING) << "Tab Killed: " | 106 LOG(WARNING) << "Tab Killed: " |
| 112 << web_contents->GetURL().GetOrigin().spec(); | 107 << web_contents->GetURL().GetOrigin().spec(); |
| 113 break; | 108 break; |
| 114 } | 109 } |
| 110 case chrome::SAD_TAB_KIND_OOM: { |
| 111 static int crashed_due_to_oom = 0; |
| 112 crashed_due_to_oom++; |
| 113 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.OomCreated", crashed_due_to_oom); |
| 114 break; |
| 115 } |
| 115 #if defined(OS_CHROMEOS) | 116 #if defined(OS_CHROMEOS) |
| 116 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: { | 117 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: { |
| 117 RecordKillCreated(); | 118 RecordKillCreated(); |
| 118 RecordKillCreatedOOM(); | 119 RecordKillCreatedOOM(); |
| 119 const std::string spec = web_contents->GetURL().GetOrigin().spec(); | 120 const std::string spec = web_contents->GetURL().GetOrigin().spec(); |
| 120 memory::OomMemoryDetails::Log( | 121 memory::OomMemoryDetails::Log( |
| 121 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure()); | 122 "Tab OOM-Killed Memory details: " + spec + ", ", base::Closure()); |
| 122 break; | 123 break; |
| 123 } | 124 } |
| 124 #endif | 125 #endif |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 layout->AddView(title_, 2, 1); | 160 layout->AddView(title_, 2, 1); |
| 160 | 161 |
| 161 const SkColor text_color = GetNativeTheme()->GetSystemColor( | 162 const SkColor text_color = GetNativeTheme()->GetSystemColor( |
| 162 ui::NativeTheme::kColorId_LabelDisabledColor); | 163 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 163 | 164 |
| 164 int message_id = IDS_SAD_TAB_MESSAGE; | 165 int message_id = IDS_SAD_TAB_MESSAGE; |
| 165 #if defined(OS_CHROMEOS) | 166 #if defined(OS_CHROMEOS) |
| 166 if (kind_ == chrome::SAD_TAB_KIND_KILLED_BY_OOM) | 167 if (kind_ == chrome::SAD_TAB_KIND_KILLED_BY_OOM) |
| 167 message_id = IDS_KILLED_TAB_BY_OOM_MESSAGE; | 168 message_id = IDS_KILLED_TAB_BY_OOM_MESSAGE; |
| 168 #endif | 169 #endif |
| 170 if (kind_ == chrome::SAD_TAB_KIND_OOM) |
| 171 message_id = IDS_SAD_TAB_OOM_MESSAGE; |
| 169 | 172 |
| 170 message_ = CreateLabel(l10n_util::GetStringUTF16(message_id)); | 173 message_ = CreateLabel(l10n_util::GetStringUTF16(message_id)); |
| 171 | 174 |
| 172 message_->SetMultiLine(true); | 175 message_->SetMultiLine(true); |
| 173 message_->SetEnabledColor(text_color); | 176 message_->SetEnabledColor(text_color); |
| 174 message_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 177 message_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 175 message_->SetLineHeight(views::kPanelSubVerticalSpacing); | 178 message_->SetLineHeight(views::kPanelSubVerticalSpacing); |
| 176 | 179 |
| 177 layout->StartRowWithPadding(0, column_set_id, 0, views::kPanelVertMargin); | 180 layout->StartRowWithPadding(0, column_set_id, 0, views::kPanelVertMargin); |
| 178 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, | 181 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 } | 244 } |
| 242 | 245 |
| 243 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 246 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
| 244 if (!painted_) { | 247 if (!painted_) { |
| 245 // These stats should use the same counting approach and bucket size used | 248 // These stats should use the same counting approach and bucket size used |
| 246 // for tab discard events in memory::OomPriorityManager so they can be | 249 // for tab discard events in memory::OomPriorityManager so they can be |
| 247 // directly compared. | 250 // directly compared. |
| 248 switch (kind_) { | 251 switch (kind_) { |
| 249 case chrome::SAD_TAB_KIND_CRASHED: { | 252 case chrome::SAD_TAB_KIND_CRASHED: { |
| 250 static int crashed = 0; | 253 static int crashed = 0; |
| 251 UMA_HISTOGRAM_CUSTOM_COUNTS( | 254 crashed++; |
| 252 "Tabs.SadTab.CrashDisplayed", ++crashed, 1, 1000, 50); | 255 UMA_HISTOGRAM_COUNTS_1000("Tabs.SadTab.CrashDisplayed", crashed); |
| 256 break; |
| 257 } |
| 258 case chrome::SAD_TAB_KIND_OOM: { |
| 259 static int crashed_due_to_oom = 0; |
| 260 crashed_due_to_oom++; |
| 261 UMA_HISTOGRAM_COUNTS_1000( |
| 262 "Tabs.SadTab.OomDisplayed", crashed_due_to_oom); |
| 253 break; | 263 break; |
| 254 } | 264 } |
| 255 case chrome::SAD_TAB_KIND_KILLED: | 265 case chrome::SAD_TAB_KIND_KILLED: |
| 256 RecordKillDisplayed(); | 266 RecordKillDisplayed(); |
| 257 break; | 267 break; |
| 258 #if defined(OS_CHROMEOS) | 268 #if defined(OS_CHROMEOS) |
| 259 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: | 269 case chrome::SAD_TAB_KIND_KILLED_BY_OOM: |
| 260 RecordKillDisplayed(); | 270 RecordKillDisplayed(); |
| 261 RecordKillDisplayedOOM(); | 271 RecordKillDisplayedOOM(); |
| 262 break; | 272 break; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 319 } |
| 310 | 320 |
| 311 namespace chrome { | 321 namespace chrome { |
| 312 | 322 |
| 313 SadTab* SadTab::Create(content::WebContents* web_contents, | 323 SadTab* SadTab::Create(content::WebContents* web_contents, |
| 314 SadTabKind kind) { | 324 SadTabKind kind) { |
| 315 return new SadTabView(web_contents, kind); | 325 return new SadTabView(web_contents, kind); |
| 316 } | 326 } |
| 317 | 327 |
| 318 } // namespace chrome | 328 } // namespace chrome |
| OLD | NEW |