Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / sad_tab_helper.cc
blobd3554c576026f750ba87bed6ea7536237839959c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/sad_tab_helper.h"
7 #include "base/logging.h"
8 #include "chrome/browser/browser_shutdown.h"
9 #include "chrome/browser/ui/sad_tab.h"
10 #include "content/public/browser/web_contents.h"
12 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SadTabHelper);
14 namespace {
16 chrome::SadTabKind SadTabKindFromTerminationStatus(
17 base::TerminationStatus status) {
18 switch (status) {
19 #if defined(OS_CHROMEOS)
20 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM:
21 return chrome::SAD_TAB_KIND_KILLED_BY_OOM;
22 #endif
23 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
24 case base::TERMINATION_STATUS_LAUNCH_FAILED:
25 return chrome::SAD_TAB_KIND_KILLED;
26 default:
27 return chrome::SAD_TAB_KIND_CRASHED;
31 } // namespace
33 SadTabHelper::~SadTabHelper() {
36 SadTabHelper::SadTabHelper(content::WebContents* web_contents)
37 : content::WebContentsObserver(web_contents) {
40 void SadTabHelper::RenderViewReady() {
41 if (sad_tab_) {
42 sad_tab_->Close();
43 sad_tab_.reset();
47 void SadTabHelper::RenderProcessGone(base::TerminationStatus status) {
48 // Only show the sad tab if we're not in browser shutdown, so that WebContents
49 // objects that are not in a browser (e.g., HTML dialogs) and thus are
50 // visible do not flash a sad tab page.
51 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
52 return;
54 if (sad_tab_)
55 return;
57 if (chrome::SadTab::ShouldShow(status))
58 InstallSadTab(status);
61 void SadTabHelper::InstallSadTab(base::TerminationStatus status) {
62 sad_tab_.reset(chrome::SadTab::Create(
63 web_contents(), SadTabKindFromTerminationStatus(status)));
64 sad_tab_->Show();