| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/hung_renderer_infobar_delegate.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/metrics/histogram.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "components/infobars/core/infobar.h" |
| 12 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/result_codes.h" |
| 15 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" |
| 17 |
| 18 // static |
| 19 void HungRendererInfoBarDelegate::Create(content::WebContents* web_contents) { |
| 20 DCHECK(web_contents); |
| 21 InfoBarService* infobar_service = |
| 22 InfoBarService::FromWebContents(web_contents); |
| 23 if (!infobar_service) |
| 24 return; |
| 25 scoped_ptr<ConfirmInfoBarDelegate> delegate( |
| 26 new HungRendererInfoBarDelegate(web_contents)); |
| 27 infobar_service->AddInfoBar( |
| 28 infobar_service->CreateConfirmInfoBar(delegate.Pass())); |
| 29 } |
| 30 |
| 31 void HungRendererInfoBarDelegate::OnRendererResponsive() { |
| 32 LogEvent(RENDERER_BECAME_RESPONSIVE); |
| 33 } |
| 34 |
| 35 HungRendererInfoBarDelegate::HungRendererInfoBarDelegate( |
| 36 content::WebContents* web_contents) |
| 37 : web_contents_(web_contents), terminal_event_logged_for_uma_(false) { |
| 38 DCHECK(web_contents); |
| 39 } |
| 40 |
| 41 HungRendererInfoBarDelegate::~HungRendererInfoBarDelegate() { |
| 42 if (!terminal_event_logged_for_uma_) |
| 43 LogEvent(INFOBAR_SHUTDOWN); |
| 44 } |
| 45 |
| 46 void HungRendererInfoBarDelegate::InfoBarDismissed() { |
| 47 LogEvent(CLOSE_CLICKED); |
| 48 } |
| 49 |
| 50 HungRendererInfoBarDelegate* |
| 51 HungRendererInfoBarDelegate::AsHungRendererInfoBarDelegate() { |
| 52 return this; |
| 53 } |
| 54 |
| 55 int HungRendererInfoBarDelegate::GetIconID() const { |
| 56 return IDR_INFOBAR_FROZEN_TAB; |
| 57 } |
| 58 |
| 59 base::string16 HungRendererInfoBarDelegate::GetMessageText() const { |
| 60 return l10n_util::GetPluralStringFUTF16(IDS_BROWSER_HANGMONITOR_RENDERER, 1); |
| 61 } |
| 62 |
| 63 base::string16 HungRendererInfoBarDelegate::GetButtonLabel( |
| 64 InfoBarButton button) const { |
| 65 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
| 66 ? IDS_BROWSER_HANGMONITOR_RENDERER_END |
| 67 : IDS_BROWSER_HANGMONITOR_RENDERER_WAIT); |
| 68 } |
| 69 |
| 70 bool HungRendererInfoBarDelegate::Accept() { |
| 71 LogEvent(KILL_CLICKED); |
| 72 content::RenderProcessHost* process = web_contents_->GetRenderProcessHost(); |
| 73 process->Shutdown(content::RESULT_CODE_HUNG, false); |
| 74 return true; |
| 75 } |
| 76 |
| 77 bool HungRendererInfoBarDelegate::Cancel() { |
| 78 LogEvent(WAIT_CLICKED); |
| 79 return true; |
| 80 } |
| 81 |
| 82 void HungRendererInfoBarDelegate::LogEvent(Event event) { |
| 83 DCHECK(!terminal_event_logged_for_uma_); |
| 84 terminal_event_logged_for_uma_ = true; |
| 85 UMA_HISTOGRAM_ENUMERATION("HungRenderer.MobileInfoBar.Event", event, |
| 86 EVENT_COUNT); |
| 87 } |
| OLD | NEW |