Skip to content

Commit

Permalink
[Bubbles] Common base class for SessionCrashedBubble.
Browse files Browse the repository at this point in the history
In anticipation of the coming Cocoa version of the SessionCrashedBubble,
this adds a shared base class for that bubble.

BUG=none

Review URL: https://codereview.chromium.org/1374683005

Cr-Commit-Position: refs/heads/master@{#351630}
  • Loading branch information
chroby authored and Commit bot committed Sep 30, 2015
1 parent 2630b3b commit 3f38c02
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 34 deletions.
5 changes: 0 additions & 5 deletions chrome/browser/ui/browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ class BrowserWindow : public ui::BaseWindow {
translate::TranslateErrors::Type error_type,
bool is_user_gesture) = 0;

// Create a session recovery bubble if the last session crashed. It also
// offers the option to enable metrics reporting if it's not already enabled.
// Returns true if a bubble is created, returns false if nothing is created.
virtual bool ShowSessionCrashedBubble() = 0;

// Shows the profile reset bubble on the platforms that support it.
virtual bool IsProfileResetBubbleSupported() const = 0;
virtual GlobalErrorBubbleViewBase* ShowProfileResetBubble(
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/ui/cocoa/browser_window_cocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class BrowserWindowCocoa
translate::TranslateStep step,
translate::TranslateErrors::Type error_type,
bool is_user_gesture) override;
bool ShowSessionCrashedBubble() override;
bool IsProfileResetBubbleSupported() const override;
GlobalErrorBubbleViewBase* ShowProfileResetBubble(
const base::WeakPtr<ProfileResetGlobalError>& global_error) override;
Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/ui/cocoa/browser_window_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,6 @@ - (void)validateText:(NSString*)text {
errorType:error_type];
}

bool BrowserWindowCocoa::ShowSessionCrashedBubble() {
return false;
}

bool BrowserWindowCocoa::IsProfileResetBubbleSupported() const {
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions chrome/browser/ui/cocoa/session_crashed_bubble.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/session_crashed_bubble.h"

bool SessionCrashedBubble::Show(Browser* /* browser */) {
return false;
}
31 changes: 31 additions & 0 deletions chrome/browser/ui/session_crashed_bubble.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_SESSION_CRASHED_BUBBLE_H_
#define CHROME_BROWSER_UI_SESSION_CRASHED_BUBBLE_H_

#include "base/macros.h"

class Browser;

// Base class for a session restore request bubble, to be displayed when the
// previous session has crashed. It also presents an option to enable metrics
// reporting, if it not enabled already.
class SessionCrashedBubble {
public:
// Create a session recovery bubble if the last session crashed. It also
// offers the option to enable metrics reporting if it's not already enabled.
// Returns true if a bubble is created, returns false if nothing is created.
static bool Show(Browser* browser);

virtual ~SessionCrashedBubble() {}

protected:
SessionCrashedBubble() {}

private:
DISALLOW_COPY_AND_ASSIGN(SessionCrashedBubble);
};

#endif // CHROME_BROWSER_UI_SESSION_CRASHED_BUBBLE_H_
3 changes: 2 additions & 1 deletion chrome/browser/ui/startup/startup_browser_creator_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "chrome/browser/ui/extensions/app_launch_params.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/session_crashed_bubble.h"
#include "chrome/browser/ui/startup/autolaunch_prompt.h"
#include "chrome/browser/ui/startup/bad_flags_prompt.h"
#include "chrome/browser/ui/startup/default_browser_prompt.h"
Expand Down Expand Up @@ -803,7 +804,7 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary(
return;

if (HasPendingUncleanExit(browser->profile()) &&
!browser->window()->ShowSessionCrashedBubble()) {
!SessionCrashedBubble::Show(browser)) {
SessionCrashedInfoBarDelegate::Create(browser);
}

Expand Down
4 changes: 0 additions & 4 deletions chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1306,10 +1306,6 @@ void BrowserView::ShowTranslateBubble(
error_type, is_user_gesture);
}

bool BrowserView::ShowSessionCrashedBubble() {
return SessionCrashedBubbleView::Show(browser_.get());
}

bool BrowserView::IsProfileResetBubbleSupported() const {
return true;
}
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/ui/views/frame/browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ class BrowserView : public BrowserWindow,
translate::TranslateStep step,
translate::TranslateErrors::Type error_type,
bool is_user_gesture) override;
bool ShowSessionCrashedBubble() override;
bool IsProfileResetBubbleSupported() const override;
GlobalErrorBubbleViewBase* ShowProfileResetBubble(
const base::WeakPtr<ProfileResetGlobalError>& global_error) override;
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/ui/views/session_crashed_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SessionCrashedBubbleView::BrowserRemovalObserver
};

// static
bool SessionCrashedBubbleView::Show(Browser* browser) {
bool SessionCrashedBubble::Show(Browser* browser) {
if (!IsBubbleUIEnabled())
return false;

Expand All @@ -147,8 +147,8 @@ bool SessionCrashedBubbleView::Show(Browser* browser) {
return true;

// Observes browser removal event and will be deallocated in ShowForReal.
scoped_ptr<BrowserRemovalObserver> browser_observer(
new BrowserRemovalObserver(browser));
scoped_ptr<SessionCrashedBubbleView::BrowserRemovalObserver> browser_observer(
new SessionCrashedBubbleView::BrowserRemovalObserver(browser));

// Stats collection only applies to Google Chrome builds.
#if defined(GOOGLE_CHROME_BUILD)
Expand Down
20 changes: 10 additions & 10 deletions chrome/browser/ui/views/session_crashed_bubble_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_SESSION_CRASHED_BUBBLE_VIEW_H_

#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/session_crashed_bubble.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
Expand All @@ -32,31 +33,30 @@ class Browser;
// crashed. It also presents an option to enable metrics reporting, if it not
// enabled already.
class SessionCrashedBubbleView
: public views::BubbleDelegateView,
: public SessionCrashedBubble,
public views::BubbleDelegateView,
public views::ButtonListener,
public views::StyledLabelListener,
public content::WebContentsObserver,
public content::NotificationObserver,
public TabStripModelObserver {
public:
static bool Show(Browser* browser);

private:
// A helper class that listens to browser removal event.
class BrowserRemovalObserver;

SessionCrashedBubbleView(views::View* anchor_view,
Browser* browser,
content::WebContents* web_contents,
bool offer_uma_optin);
~SessionCrashedBubbleView() override;

// Creates and shows the session crashed bubble, with |uma_opted_in_already|
// indicating whether the user has already opted-in to UMA. It will be called
// by Show. It takes ownership of |browser_observer|.
static void ShowForReal(scoped_ptr<BrowserRemovalObserver> browser_observer,
bool uma_opted_in_already);

private:
SessionCrashedBubbleView(views::View* anchor_view,
Browser* browser,
content::WebContents* web_contents,
bool offer_uma_optin);
~SessionCrashedBubbleView() override;

// WidgetDelegateView methods.
views::View* GetInitiallyFocusedView() override;
base::string16 GetWindowTitle() const override;
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_browser_ui.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
'browser/ui/search_engines/search_engine_tab_helper.h',
'browser/ui/search_engines/template_url_table_model.cc',
'browser/ui/search_engines/template_url_table_model.h',
'browser/ui/session_crashed_bubble.h',
'browser/ui/simple_message_box.h',
'browser/ui/simple_message_box_internal.cc',
'browser/ui/simple_message_box_internal.h',
Expand Down Expand Up @@ -1165,6 +1166,7 @@
'browser/ui/cocoa/rect_path_utils.mm',
'browser/ui/cocoa/restart_browser.h',
'browser/ui/cocoa/restart_browser.mm',
'browser/ui/cocoa/session_crashed_bubble.mm',
'browser/ui/cocoa/screen_capture_notification_ui_cocoa.h',
'browser/ui/cocoa/screen_capture_notification_ui_cocoa.mm',
'browser/ui/cocoa/simple_message_box_mac.mm',
Expand Down
4 changes: 0 additions & 4 deletions chrome/test/base/test_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ gfx::Rect TestBrowserWindow::GetRootWindowResizerRect() const {
return gfx::Rect();
}

bool TestBrowserWindow::ShowSessionCrashedBubble() {
return false;
}

bool TestBrowserWindow::IsProfileResetBubbleSupported() const {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion chrome/test/base/test_browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ class TestBrowserWindow : public BrowserWindow {
translate::TranslateStep step,
translate::TranslateErrors::Type error_type,
bool is_user_gesture) override {}
bool ShowSessionCrashedBubble() override;
bool IsProfileResetBubbleSupported() const override;
GlobalErrorBubbleViewBase* ShowProfileResetBubble(
const base::WeakPtr<ProfileResetGlobalError>& global_error) override;
Expand Down

0 comments on commit 3f38c02

Please sign in to comment.