Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(794)

Side by Side Diff: chrome/browser/android/hung_renderer_infobar_delegate.cc

Issue 1299513002: [Android] Add support for a hung renderer dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename histogram Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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;
Peter Kasting 2015/09/02 21:52:45 The only caller of this method has already assumed
jdduke (slow) 2015/09/02 23:00:35 Done.
25 scoped_ptr<ConfirmInfoBarDelegate> delegate(
26 new HungRendererInfoBarDelegate(web_contents));
Peter Kasting 2015/09/02 21:52:45 Nit: You can avoid the Pass() call and the temp he
jdduke (slow) 2015/09/02 23:00:35 Done.
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) {
Peter Kasting 2015/09/02 21:52:45 Nit: It seems like the only thing we save |web_con
jdduke (slow) 2015/09/02 23:00:35 Done.
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("Renderer.Hung.MobileInfoBar.UserEvent", event,
86 EVENT_COUNT);
87 }
OLDNEW
« no previous file with comments | « chrome/browser/android/hung_renderer_infobar_delegate.h ('k') | chrome/browser/android/resource_id.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698