Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / hung_renderer_infobar_delegate.cc
blobf469c675c6d8992518dc66f925302a0b178ea060
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.
5 #include "chrome/browser/android/hung_renderer_infobar_delegate.h"
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/common/result_codes.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
17 // static
18 void HungRendererInfoBarDelegate::Create(
19 InfoBarService* infobar_service,
20 content::RenderProcessHost* render_process_host) {
21 DCHECK(render_process_host);
22 infobar_service->AddInfoBar(
23 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
24 new HungRendererInfoBarDelegate(render_process_host))));
27 void HungRendererInfoBarDelegate::OnRendererResponsive() {
28 LogEvent(RENDERER_BECAME_RESPONSIVE);
31 HungRendererInfoBarDelegate::HungRendererInfoBarDelegate(
32 content::RenderProcessHost* render_process_host)
33 : render_process_host_(render_process_host),
34 terminal_event_logged_for_uma_(false) {}
36 HungRendererInfoBarDelegate::~HungRendererInfoBarDelegate() {
37 if (!terminal_event_logged_for_uma_)
38 LogEvent(TAB_CLOSED);
41 void HungRendererInfoBarDelegate::InfoBarDismissed() {
42 LogEvent(CLOSE_CLICKED);
45 HungRendererInfoBarDelegate*
46 HungRendererInfoBarDelegate::AsHungRendererInfoBarDelegate() {
47 return this;
50 int HungRendererInfoBarDelegate::GetIconId() const {
51 return IDR_INFOBAR_FROZEN_TAB;
54 base::string16 HungRendererInfoBarDelegate::GetMessageText() const {
55 return l10n_util::GetPluralStringFUTF16(IDS_BROWSER_HANGMONITOR_RENDERER, 1);
58 base::string16 HungRendererInfoBarDelegate::GetButtonLabel(
59 InfoBarButton button) const {
60 return l10n_util::GetStringUTF16((button == BUTTON_OK)
61 ? IDS_BROWSER_HANGMONITOR_RENDERER_END
62 : IDS_BROWSER_HANGMONITOR_RENDERER_WAIT);
65 bool HungRendererInfoBarDelegate::Accept() {
66 LogEvent(KILL_CLICKED);
67 render_process_host_->Shutdown(content::RESULT_CODE_HUNG, false);
68 return true;
71 bool HungRendererInfoBarDelegate::Cancel() {
72 LogEvent(WAIT_CLICKED);
73 return true;
76 void HungRendererInfoBarDelegate::LogEvent(Event event) {
77 DCHECK(!terminal_event_logged_for_uma_);
78 terminal_event_logged_for_uma_ = true;
79 UMA_HISTOGRAM_ENUMERATION("Renderer.Hung.MobileInfoBar.UserEvent", event,
80 EVENT_COUNT);