summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-05 19:10:19 +0000
committerdewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-05 19:10:19 +0000
commit35653072a19559aa077fe241c36cd509152f7535 (patch)
tree8dc2bef7514ad077c5a11dfd9c35f2859b681f3a
parent6737c579fd8e5b2aa81971e5b7b8ceb7e3eb5c13 (diff)
downloadchromium_src-35653072a19559aa077fe241c36cd509152f7535.zip
chromium_src-35653072a19559aa077fe241c36cd509152f7535.tar.gz
chromium_src-35653072a19559aa077fe241c36cd509152f7535.tar.bz2
Re-home the global MessageCenter to support Ash+Win environments.
In the case where Ash is displayed on Windows, we want a single message center data structure with multiple UI surfaces for notifications. g_browser_process now manages the lifetime of the global Message Center object, since its lifetime is always longer than Ash::Shell. This allows us to re-enable the browser tests for message center on Ash+Win, and stops a crash bug. BUG=178429 Review URL: https://chromiumcodereview.appspot.com/12375004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186220 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/shell.cc6
-rw-r--r--ash/shell.h9
-rw-r--r--ash/system/web_notification/web_notification_tray.cc2
-rw-r--r--ash/test/ash_test_base.cc16
-rw-r--r--chrome/browser/browser_process_impl.cc31
-rw-r--r--chrome/browser/browser_process_impl.h9
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc14
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/base/testing_browser_process.cc12
-rw-r--r--chrome/test/base/testing_browser_process.h3
-rw-r--r--chrome/test/base/view_event_test_base.cc14
-rw-r--r--ui/message_center/message_center.cc23
-rw-r--r--ui/message_center/message_center.h16
-rw-r--r--ui/message_center/message_center_tray_unittest.cc10
-rw-r--r--ui/message_center/message_center_util.cc4
15 files changed, 98 insertions, 73 deletions
diff --git a/ash/shell.cc b/ash/shell.cc
index c6965b2..77b60f9 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -858,12 +858,6 @@ void Shell::DoInitialWorkspaceAnimation() {
DoInitialAnimation();
}
-message_center::MessageCenter* Shell::message_center() {
- if (!message_center_.get())
- message_center_.reset(new message_center::MessageCenter());
- return message_center_.get();
-}
-
void Shell::InitRootWindowController(
internal::RootWindowController* controller) {
aura::RootWindow* root_window = controller->root_window();
diff --git a/ash/shell.h b/ash/shell.h
index 5ed4cd7..c2cdda6 100644
--- a/ash/shell.h
+++ b/ash/shell.h
@@ -64,10 +64,6 @@ class WindowModalityController;
}
}
-namespace message_center {
-class MessageCenter;
-}
-
namespace ash {
class AcceleratorController;
@@ -444,9 +440,6 @@ class ASH_EXPORT Shell
return root_window_host_factory_.get();
}
- // MessageCenter is a global list of currently displayed notifications.
- message_center::MessageCenter* message_center();
-
private:
FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
@@ -589,8 +582,6 @@ class ASH_EXPORT Shell
scoped_ptr<internal::DisplayChangeObserverX11> display_change_observer_;
#endif // defined(OS_CHROMEOS)
- scoped_ptr<message_center::MessageCenter> message_center_;
-
// |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
// pointer to vend to test code.
AshNativeCursorManager* native_cursor_manager_;
diff --git a/ash/system/web_notification/web_notification_tray.cc b/ash/system/web_notification/web_notification_tray.cc
index 998123f..cfc1e1c 100644
--- a/ash/system/web_notification/web_notification_tray.cc
+++ b/ash/system/web_notification/web_notification_tray.cc
@@ -98,7 +98,7 @@ WebNotificationTray::WebNotificationTray(
SetVisible(false);
message_center_tray_.reset(new message_center::MessageCenterTray(
this,
- Shell::GetInstance()->message_center()));
+ message_center::MessageCenter::Get()));
OnMessageCenterTrayChanged();
}
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 853cdff..a1cf637 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -30,6 +30,10 @@
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center.h"
+#endif
+
#if defined(OS_WIN)
#include "ash/test/test_metro_viewer_process_host.h"
#include "base/test/test_process_killer_win.h"
@@ -96,6 +100,12 @@ void AshTestBase::SetUp() {
// Creates Shell and hook with Desktop.
test_shell_delegate_ = new TestShellDelegate;
+
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Creates MessageCenter since g_browser_process is not created in AshTestBase
+ // tests.
+ message_center::MessageCenter::Initialize();
+#endif
ash::Shell::CreateInstance(test_shell_delegate_);
Shell::GetPrimaryRootWindow()->Show();
Shell::GetPrimaryRootWindow()->ShowRootWindow();
@@ -130,6 +140,12 @@ void AshTestBase::TearDown() {
// Tear down the shell.
Shell::DeleteInstance();
+
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Remove global message center state.
+ message_center::MessageCenter::Shutdown();
+#endif
+
aura::Env::DeleteInstance();
ui::TextInputTestSupport::Shutdown();
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 8f6a95d..3eba46e 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -93,10 +93,6 @@
#include "chrome/browser/policy/policy_service_stub.h"
#endif // defined(ENABLE_CONFIGURATION_POLICY)
-#if defined(ENABLE_MESSAGE_CENTER) && defined(USE_ASH)
-#include "ash/shell.h"
-#endif
-
#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center.h"
#endif
@@ -159,9 +155,6 @@ BrowserProcessImpl::BrowserProcessImpl(
created_local_state_(false),
created_icon_manager_(false),
created_notification_ui_manager_(false),
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(USE_ASH)
- created_message_center_(false),
-#endif
created_safe_browsing_service_(false),
module_ref_count_(0),
did_start_(false),
@@ -191,6 +184,10 @@ BrowserProcessImpl::BrowserProcessImpl(
extension_event_router_forwarder_ = new extensions::EventRouterForwarder;
ExtensionRendererState::GetInstance()->Init();
+
+#if defined(ENABLE_MESSAGE_CENTER)
+ message_center::MessageCenter::Initialize();
+#endif
}
BrowserProcessImpl::~BrowserProcessImpl() {
@@ -247,6 +244,10 @@ void BrowserProcessImpl::StartTearDown() {
ExtensionRendererState::GetInstance()->Shutdown();
+#if defined(ENABLE_MESSAGE_CENTER)
+ message_center::MessageCenter::Shutdown();
+#endif
+
#if defined(ENABLE_CONFIGURATION_POLICY)
// The policy providers managed by |browser_policy_connector_| need to shut
// down while the IO and FILE threads are still alive.
@@ -461,13 +462,7 @@ NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter* BrowserProcessImpl::message_center() {
DCHECK(CalledOnValidThread());
-#if defined(USE_ASH)
- return ash::Shell::GetInstance()->message_center();
-#else
- if (!created_message_center_)
- CreateMessageCenter();
- return message_center_.get();
-#endif
+ return message_center::MessageCenter::Get();
}
#endif
@@ -914,14 +909,6 @@ void BrowserProcessImpl::CreateNotificationUIManager() {
#endif
}
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(USE_ASH)
-void BrowserProcessImpl::CreateMessageCenter() {
- DCHECK(message_center_.get() == NULL);
- message_center_.reset(new message_center::MessageCenter());
- created_message_center_ = true;
-}
-#endif
-
void BrowserProcessImpl::CreateBackgroundModeManager() {
DCHECK(background_mode_manager_.get() == NULL);
background_mode_manager_.reset(
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index 3b28dc4..8487798 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -147,9 +147,6 @@ class BrowserProcessImpl : public BrowserProcess,
void CreateIconManager();
void CreateIntranetRedirectDetector();
void CreateNotificationUIManager();
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(USE_ASH)
- void CreateMessageCenter();
-#endif
void CreateStatusTrayManager();
void CreatePrintPreviewDialogController();
void CreateBackgroundPrintingManager();
@@ -215,12 +212,6 @@ class BrowserProcessImpl : public BrowserProcess,
bool created_notification_ui_manager_;
scoped_ptr<NotificationUIManager> notification_ui_manager_;
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(USE_ASH)
- // MessageCenter keeps currently displayed UI notifications.
- scoped_ptr<message_center::MessageCenter> message_center_;
- bool created_message_center_;
-#endif
-
#if defined(ENABLE_AUTOMATION)
scoped_ptr<AutomationProviderList> automation_provider_list_;
#endif
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index 85ce0e23..aca84f1 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -13,6 +13,10 @@
#include "chrome/common/pref_names.h"
#include "content/public/common/show_desktop_notification_params.h"
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center.h"
+#endif
+
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/test/test_shell_delegate.h"
@@ -97,6 +101,11 @@ DesktopNotificationsTest::~DesktopNotificationsTest() {
void DesktopNotificationsTest::SetUp() {
#if defined(USE_ASH)
WebKit::initialize(webkit_platform_support_.Get());
+#if defined(ENABLE_MESSAGE_CENTER)
+ // The message center is notmally initialized on |g_browser_process| which
+ // is not created for these tests.
+ message_center::MessageCenter::Initialize();
+#endif
// MockBalloonCollection retrieves information about the screen on creation.
// So it is necessary to make sure the desktop gets created first.
ash::Shell::CreateInstance(new ash::test::TestShellDelegate);
@@ -119,6 +128,11 @@ void DesktopNotificationsTest::TearDown() {
#if defined(USE_ASH)
active_desktop_monitor_.reset();
ash::Shell::DeleteInstance();
+#if defined(ENABLE_MESSAGE_CENTER)
+ // The message center is notmally shutdown on |g_browser_process| which
+ // is not created for these tests.
+ message_center::MessageCenter::Shutdown();
+#endif
aura::Env::DeleteInstance();
WebKit::shutdown();
#endif
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index fcb6ae3..520f557 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1857,7 +1857,7 @@
['exclude', '^browser/ui/app_list/'],
],
}],
- ['enable_message_center==0 or use_ash==1', {
+ ['enable_message_center==0', {
'sources!': [
'browser/notifications/message_center_notifications_browsertest.cc',
'browser/ui/views/message_center/web_notification_tray_win_browsertest.cc',
diff --git a/chrome/test/base/testing_browser_process.cc b/chrome/test/base/testing_browser_process.cc
index bbaab14..e74d080 100644
--- a/chrome/test/base/testing_browser_process.cc
+++ b/chrome/test/base/testing_browser_process.cc
@@ -34,10 +34,6 @@
#include "chrome/browser/policy/policy_service_stub.h"
#endif // defined(ENABLE_CONFIGURATION_POLICY)
-#if defined(ENABLE_MESSAGE_CENTER) && defined(USE_ASH)
-#include "ash/shell.h"
-#endif
-
#if defined(ENABLE_MESSAGE_CENTER)
#include "ui/message_center/message_center.h"
#endif
@@ -201,13 +197,7 @@ NotificationUIManager* TestingBrowserProcess::notification_ui_manager() {
#if defined(ENABLE_MESSAGE_CENTER)
message_center::MessageCenter* TestingBrowserProcess::message_center() {
-#if defined(USE_ASH)
- return ash::Shell::GetInstance()->message_center();
-#else
- if (!message_center_.get())
- message_center_.reset(new message_center::MessageCenter());
- return message_center_.get();
-#endif
+ return message_center::MessageCenter::Get();
}
#endif
diff --git a/chrome/test/base/testing_browser_process.h b/chrome/test/base/testing_browser_process.h
index 00ba5d1..99e763e 100644
--- a/chrome/test/base/testing_browser_process.h
+++ b/chrome/test/base/testing_browser_process.h
@@ -135,9 +135,6 @@ class TestingBrowserProcess : public BrowserProcess {
#endif
scoped_ptr<ProfileManager> profile_manager_;
scoped_ptr<NotificationUIManager> notification_ui_manager_;
-#if defined(ENABLE_MESSAGE_CENTER) && !defined(USE_ASH)
- scoped_ptr<message_center::MessageCenter> message_center_;
-#endif
scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
scoped_refptr<printing::PrintPreviewDialogController>
print_preview_dialog_controller_;
diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc
index cbf1f5e..91b1855 100644
--- a/chrome/test/base/view_event_test_base.cc
+++ b/chrome/test/base/view_event_test_base.cc
@@ -18,6 +18,10 @@
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#include "ui/views/widget/widget.h"
+#if defined(ENABLE_MESSAGE_CENTER)
+#include "ui/message_center/message_center.h"
+#endif
+
#if defined(USE_ASH)
#include "ash/shell.h"
#include "ash/test/test_shell_delegate.h"
@@ -98,6 +102,11 @@ void ViewEventTestBase::SetUp() {
gfx::Screen::SetScreenInstance(
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen());
#else
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Ash Shell can't just live on its own without a browser process, we need to
+ // also create the message center.
+ message_center::MessageCenter::Initialize();
+#endif
ash::Shell::CreateInstance(new ash::test::TestShellDelegate());
context = ash::Shell::GetPrimaryRootWindow();
#endif
@@ -126,6 +135,11 @@ void ViewEventTestBase::TearDown() {
#if defined(OS_WIN)
#else
ash::Shell::DeleteInstance();
+#if defined(ENABLE_MESSAGE_CENTER)
+ // Ash Shell can't just live on its own without a browser process, we need to
+ // also shut down the message center.
+ message_center::MessageCenter::Shutdown();
+#endif
aura::Env::DeleteInstance();
#endif
#elif defined(USE_AURA)
diff --git a/ui/message_center/message_center.cc b/ui/message_center/message_center.cc
index 8aeb89b0..97f05ce 100644
--- a/ui/message_center/message_center.cc
+++ b/ui/message_center/message_center.cc
@@ -12,6 +12,29 @@
namespace message_center {
+namespace {
+static MessageCenter* g_message_center;
+}
+
+// static
+void MessageCenter::Initialize() {
+ DCHECK(g_message_center == NULL);
+ g_message_center = new MessageCenter();
+}
+
+// static
+MessageCenter* MessageCenter::Get() {
+ DCHECK(g_message_center);
+ return g_message_center;
+}
+
+// static
+void MessageCenter::Shutdown() {
+ DCHECK(g_message_center);
+ delete g_message_center;
+ g_message_center = NULL;
+}
+
//------------------------------------------------------------------------------
MessageCenter::MessageCenter()
: delegate_(NULL) {
diff --git a/ui/message_center/message_center.h b/ui/message_center/message_center.h
index 7cc49da..a78c151 100644
--- a/ui/message_center/message_center.h
+++ b/ui/message_center/message_center.h
@@ -30,6 +30,15 @@ namespace message_center {
class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
public:
+ // Creates the global message center object.
+ static void Initialize();
+
+ // Returns the global message center object. Initialize must be called first.
+ static MessageCenter* Get();
+
+ // Destroys the global message_center object.
+ static void Shutdown();
+
// Class that hosts the message center.
class MESSAGE_CENTER_EXPORT Observer {
public:
@@ -78,9 +87,6 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
virtual ~Delegate() {}
};
- MessageCenter();
- virtual ~MessageCenter();
-
// Called to set the delegate. Generally called only once, except in tests.
// Changing the delegate does not affect notifications in its
// NotificationList.
@@ -153,6 +159,10 @@ class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate {
OVERRIDE;
virtual NotificationList* GetNotificationList() OVERRIDE;
+ protected:
+ MessageCenter();
+ virtual ~MessageCenter();
+
private:
// Calls OnMessageCenterChanged on each observer.
void NotifyMessageCenterChanged(bool new_notification);
diff --git a/ui/message_center/message_center_tray_unittest.cc b/ui/message_center/message_center_tray_unittest.cc
index 406e360..bd9271f 100644
--- a/ui/message_center/message_center_tray_unittest.cc
+++ b/ui/message_center/message_center_tray_unittest.cc
@@ -43,22 +43,24 @@ class MessageCenterTrayTest : public testing::Test {
virtual ~MessageCenterTrayTest() {}
virtual void SetUp() {
+ MessageCenter::Initialize();
delegate_.reset(new MockDelegate);
- message_center_.reset(new MessageCenter());
+ message_center_ = MessageCenter::Get();
message_center_tray_.reset(
- new MessageCenterTray(delegate_.get(), message_center_.get()));
+ new MessageCenterTray(delegate_.get(), message_center_));
}
virtual void TearDown() {
message_center_tray_.reset();
- message_center_.reset();
delegate_.reset();
+ message_center_ = NULL;
+ MessageCenter::Shutdown();
}
protected:
scoped_ptr<MockDelegate> delegate_;
scoped_ptr<MessageCenterTray> message_center_tray_;
- scoped_ptr<MessageCenter> message_center_;
+ MessageCenter* message_center_;
private:
DISALLOW_COPY_AND_ASSIGN(MessageCenterTrayTest);
diff --git a/ui/message_center/message_center_util.cc b/ui/message_center/message_center_util.cc
index 8380279..90f7f47 100644
--- a/ui/message_center/message_center_util.cc
+++ b/ui/message_center/message_center_util.cc
@@ -10,12 +10,8 @@
namespace message_center {
bool IsRichNotificationEnabled() {
-#if defined(OS_WIN) && defined(USE_AURA)
- return false;
-#else
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableRichNotifications);
-#endif
}
} // namespace message_center