Commit 09f0bb32 authored by yoshiki iguchi's avatar yoshiki iguchi Committed by Commit Bot

Extract the popup-only UI code from ui/message_center

message_center::UiController and UiDelegate were used by both the platform
with only popup and with the message center and popup. This CL is the first
CL of refactoring to split them into two for simplification.
The current dependency:
 CrOS: UiController --UiDelegate--> NotificationTray/UnifiedSystemTray
 Old Win/Linux: UiController --UiDelegate--> PopupsOnlyUiDelegate
 Old Mac: UiController --UiDelegate--> MessageCenterBridge

The new dependency:
 CrOS: UiController --UiDelegate--> NotificationTray/UnifiedSystemTray
 Old Win/Linux: PopupsOnlyUiController(new) --::Delegate(new)--> PopupsOnlyUiDelegate
 Old MacMac: PopupsOnlyUiController(new) --::Delegate(new)--> MessageCenterBridge

I will move the existing UiController and UiDelegate to ash/ and refactor
them in following CLs.

Bug: 869278
Test: Notification works on Linux

Change-Id: I8ab077f0339cb55cf25633aa481509f1775d43dd
Reviewed-on: https://chromium-review.googlesource.com/1154617
Commit-Queue: Yoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579715}
parent c4138a47
...@@ -894,6 +894,8 @@ jumbo_split_static_library("browser") { ...@@ -894,6 +894,8 @@ jumbo_split_static_library("browser") {
"notifications/persistent_notification_handler.h", "notifications/persistent_notification_handler.h",
"notifications/platform_notification_service_impl.cc", "notifications/platform_notification_service_impl.cc",
"notifications/platform_notification_service_impl.h", "notifications/platform_notification_service_impl.h",
"notifications/popups_only_ui_controller.cc",
"notifications/popups_only_ui_controller.h",
"notifications/system_notification_helper.cc", "notifications/system_notification_helper.cc",
"notifications/system_notification_helper.h", "notifications/system_notification_helper.h",
"ntp_snippets/bookmark_last_visit_updater.cc", "ntp_snippets/bookmark_last_visit_updater.cc",
......
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/notifications/fullscreen_notification_blocker.h"
#include "chrome/browser/notifications/popups_only_ui_controller.h"
#include "chrome/browser/notifications/profile_notification.h" #include "chrome/browser/notifications/profile_notification.h"
#include "chrome/browser/notifications/screen_lock_notification_blocker.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -23,34 +26,21 @@ ...@@ -23,34 +26,21 @@
#include "ui/message_center/public/cpp/message_center_constants.h" #include "ui/message_center/public/cpp/message_center_constants.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/message_center/ui_controller.h"
#if !defined(OS_CHROMEOS)
#include "chrome/browser/notifications/fullscreen_notification_blocker.h"
#include "chrome/browser/notifications/screen_lock_notification_blocker.h"
#endif
using message_center::MessageCenter; using message_center::MessageCenter;
using message_center::NotifierId; using message_center::NotifierId;
MessageCenterNotificationManager::MessageCenterNotificationManager() MessageCenterNotificationManager::MessageCenterNotificationManager()
: system_observer_(this) { : system_observer_(this),
popups_only_ui_controller_(std::make_unique<PopupsOnlyUiController>(
PopupsOnlyUiController::CreateDelegate())) {
auto* message_center = MessageCenter::Get(); auto* message_center = MessageCenter::Get();
message_center->AddObserver(this); message_center->AddObserver(this);
#if !defined(OS_CHROMEOS)
blockers_.push_back( blockers_.push_back(
std::make_unique<ScreenLockNotificationBlocker>(message_center)); std::make_unique<ScreenLockNotificationBlocker>(message_center));
blockers_.push_back( blockers_.push_back(
std::make_unique<FullscreenNotificationBlocker>(message_center)); std::make_unique<FullscreenNotificationBlocker>(message_center));
#endif
#if defined(OS_WIN) || defined(OS_MACOSX) \
|| (defined(OS_LINUX) && !defined(OS_CHROMEOS))
// On Windows, Linux and Mac, the notification manager owns the tray icon and
// views.Other platforms have global ownership and Create will return NULL.
tray_.reset(CreateUiDelegate());
#endif
} }
MessageCenterNotificationManager::~MessageCenterNotificationManager() { MessageCenterNotificationManager::~MessageCenterNotificationManager() {
...@@ -223,15 +213,15 @@ void MessageCenterNotificationManager::StartShutdown() { ...@@ -223,15 +213,15 @@ void MessageCenterNotificationManager::StartShutdown() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// MessageCenter::Observer // MessageCenter::Observer
void MessageCenterNotificationManager::OnNotificationRemoved( void MessageCenterNotificationManager::OnNotificationRemoved(
const std::string& id, const std::string& id,
bool by_user) { bool by_user) {
RemoveProfileNotification(id); RemoveProfileNotification(id);
} }
void MessageCenterNotificationManager::SetUiDelegateForTest( void MessageCenterNotificationManager::ResetUiControllerForTest() {
message_center::UiDelegate* delegate) { popups_only_ui_controller_.reset();
tray_.reset(delegate);
} }
std::string std::string
...@@ -266,8 +256,8 @@ void MessageCenterNotificationManager::RemoveProfileNotification( ...@@ -266,8 +256,8 @@ void MessageCenterNotificationManager::RemoveProfileNotification(
// the one ScopedKeepAlive object that was keeping the browser alive, and // the one ScopedKeepAlive object that was keeping the browser alive, and
// destroying it would result in: // destroying it would result in:
// a) A reentrant call to this class. Because every method in this class // a) A reentrant call to this class. Because every method in this class
// touches |profile_notifications_|, |profile_notifications_| must always // touches |profile_notifications_|, |profile_notifications_| must always
// be in a self-consistent state in moments where re-entrance might happen. // be in a self-consistent state in moments where re-entrance might happen.
// b) A crash like https://crbug.com/649971 because it can trigger // b) A crash like https://crbug.com/649971 because it can trigger
// shutdown process while we're still inside the call stack from UI // shutdown process while we're still inside the call stack from UI
// framework. // framework.
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "ui/message_center/message_center_observer.h" #include "ui/message_center/message_center_observer.h"
#include "ui/message_center/message_center_types.h" #include "ui/message_center/message_center_types.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/ui_delegate.h"
class PopupsOnlyUiController;
class Profile; class Profile;
class ProfileNotification; class ProfileNotification;
...@@ -31,9 +31,6 @@ class NotificationBlocker; ...@@ -31,9 +31,6 @@ class NotificationBlocker;
FORWARD_DECLARE_TEST(NotificationTrayTest, ManuallyCloseMessageCenter); FORWARD_DECLARE_TEST(NotificationTrayTest, ManuallyCloseMessageCenter);
} }
// Implementations are platform specific.
message_center::UiDelegate* CreateUiDelegate();
// This class extends NotificationUIManagerImpl and delegates actual display // This class extends NotificationUIManagerImpl and delegates actual display
// of notifications to MessageCenter, doing necessary conversions. This is only // of notifications to MessageCenter, doing necessary conversions. This is only
// used on platforms that support non-native notifications. // used on platforms that support non-native notifications.
...@@ -60,24 +57,25 @@ class MessageCenterNotificationManager ...@@ -60,24 +57,25 @@ class MessageCenterNotificationManager
void CancelAll() override; void CancelAll() override;
void StartShutdown() override; void StartShutdown() override;
// MessageCenterObserver // MessageCenterObserver:
void OnNotificationRemoved(const std::string& notification_id, void OnNotificationRemoved(const std::string& notification_id,
bool by_user) override; bool by_user) override;
// Takes ownership of |delegate|. // Resets the ui controller.
void SetUiDelegateForTest(message_center::UiDelegate* delegate); void ResetUiControllerForTest();
// Returns the notification id which this manager will use to add to message // Returns the notification id which this manager will use to add to message
// center, for this combination of delegate id and profile. // center, for this combination of delegate id and profile.
std::string GetMessageCenterNotificationIdForTest( std::string GetMessageCenterNotificationIdForTest(
const std::string& delegate_id, Profile* profile); const std::string& delegate_id, Profile* profile);
// Returns true if the popup bubbles are currently visible.
bool popups_visible() const { return popups_visible_; }
private: private:
FRIEND_TEST_ALL_PREFIXES(message_center::NotificationTrayTest, FRIEND_TEST_ALL_PREFIXES(message_center::NotificationTrayTest,
ManuallyCloseMessageCenter); ManuallyCloseMessageCenter);
std::unique_ptr<message_center::UiDelegate> tray_;
// Use a map by notification_id since this mapping is the most often used. // Use a map by notification_id since this mapping is the most often used.
std::map<std::string, std::unique_ptr<ProfileNotification>> std::map<std::string, std::unique_ptr<ProfileNotification>>
profile_notifications_; profile_notifications_;
...@@ -97,9 +95,15 @@ class MessageCenterNotificationManager ...@@ -97,9 +95,15 @@ class MessageCenterNotificationManager
NotificationSystemObserver system_observer_; NotificationSystemObserver system_observer_;
// Delegate of this class.
std::unique_ptr<PopupsOnlyUiController> popups_only_ui_controller_;
// Tracks if shutdown has started. // Tracks if shutdown has started.
bool is_shutdown_started_ = false; bool is_shutdown_started_ = false;
// Tracks the current visibility status of the popup bubbles.
bool popups_visible_ = false;
DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager); DISALLOW_COPY_AND_ASSIGN(MessageCenterNotificationManager);
}; };
......
...@@ -17,13 +17,11 @@ ...@@ -17,13 +17,11 @@
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/message_center/fake_ui_delegate.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_types.h" #include "ui/message_center/message_center_types.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h" #include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h" #include "ui/message_center/public/cpp/notifier_id.h"
#include "ui/message_center/ui_controller.h"
namespace message_center { namespace message_center {
...@@ -37,8 +35,7 @@ class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest { ...@@ -37,8 +35,7 @@ class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest {
BrowserWithTestWindowTest::SetUp(); BrowserWithTestWindowTest::SetUp();
message_center_ = MessageCenter::Get(); message_center_ = MessageCenter::Get();
delegate_ = new FakeUiDelegate(); notification_manager()->ResetUiControllerForTest();
notification_manager()->SetUiDelegateForTest(delegate_);
} }
void TearDown() override { void TearDown() override {
...@@ -65,7 +62,6 @@ class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest { ...@@ -65,7 +62,6 @@ class MessageCenterNotificationManagerTest : public BrowserWithTestWindowTest {
private: private:
MessageCenter* message_center_; MessageCenter* message_center_;
FakeUiDelegate* delegate_;
}; };
TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) { TEST_F(MessageCenterNotificationManagerTest, SetupNotificationManager) {
......
// Copyright 2018 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/notifications/popups_only_ui_controller.h"
#include "ui/display/screen.h"
#include "ui/message_center/message_center.h"
PopupsOnlyUiController::PopupsOnlyUiController(
std::unique_ptr<Delegate> delegate)
: message_center_(message_center::MessageCenter::Get()),
delegate_(std::move(delegate)) {
message_center_->AddObserver(this);
message_center_->SetHasMessageCenterView(false);
}
PopupsOnlyUiController::~PopupsOnlyUiController() {
message_center_->RemoveObserver(this);
}
void PopupsOnlyUiController::OnNotificationAdded(
const std::string& notification_id) {
ShowOrHidePopupBubbles();
}
void PopupsOnlyUiController::OnNotificationRemoved(
const std::string& notification_id,
bool by_user) {
ShowOrHidePopupBubbles();
}
void PopupsOnlyUiController::OnNotificationUpdated(
const std::string& notification_id) {
ShowOrHidePopupBubbles();
}
void PopupsOnlyUiController::OnNotificationClicked(
const std::string& notification_id,
const base::Optional<int>& button_index,
const base::Optional<base::string16>& reply) {
if (popups_visible_)
ShowOrHidePopupBubbles();
}
void PopupsOnlyUiController::ShowOrHidePopupBubbles() {
if (popups_visible_ && !message_center_->HasPopupNotifications()) {
if (delegate_)
delegate_->HidePopups();
popups_visible_ = false;
} else if (!popups_visible_ && message_center_->HasPopupNotifications()) {
if (delegate_)
delegate_->ShowPopups();
popups_visible_ = true;
}
}
// Copyright 2018 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_NOTIFICATIONS_POPUPS_ONLY_UI_CONTROLLER_H_
#define CHROME_BROWSER_NOTIFICATIONS_POPUPS_ONLY_UI_CONTROLLER_H_
#include <memory>
#include "base/macros.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
// A message center view implementation that shows notification popups (toasts)
// in the corner of the screen, but has no dedicated message center (widget with
// multiple notifications inside). This is used on Windows and Linux for
// non-native notifications.
class PopupsOnlyUiController : public message_center::MessageCenterObserver {
public:
class Delegate {
public:
virtual ~Delegate() {}
virtual void ShowPopups() = 0;
virtual void HidePopups() = 0;
};
// Implementations are platform specific.
static std::unique_ptr<Delegate> CreateDelegate();
explicit PopupsOnlyUiController(std::unique_ptr<Delegate> delegate);
~PopupsOnlyUiController() override;
// UiDelegate implementation.
void OnNotificationAdded(const std::string& notification_id) override;
void OnNotificationRemoved(const std::string& notification_id,
bool b_user) override;
void OnNotificationUpdated(const std::string& notification_id) override;
void OnNotificationClicked(
const std::string& notification_id,
const base::Optional<int>& button_index,
const base::Optional<base::string16>& reply) override;
Delegate* delegate() { return delegate_.get(); }
bool popups_visible() const { return popups_visible_; }
private:
message_center::MessageCenter* const message_center_;
const std::unique_ptr<Delegate> delegate_;
// Update the visibility of the popup bubbles. Shows or hides them if
// necessary.
void ShowOrHidePopupBubbles();
bool popups_visible_ = false;
DISALLOW_COPY_AND_ASSIGN(PopupsOnlyUiController);
};
#endif // CHROME_BROWSER_NOTIFICATIONS_POPUPS_ONLY_UI_CONTROLLER_H_
...@@ -12,41 +12,33 @@ ...@@ -12,41 +12,33 @@
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/notifications/popups_only_ui_controller.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/ui_delegate.h"
@class MCPopupCollection; @class MCPopupCollection;
namespace message_center { namespace message_center {
class MessageCenter; class MessageCenter;
class UiController;
} // namespace message_center } // namespace message_center
// MessageCenterBridge is the owner of all the Cocoa UI objects for the // MessageCenterBridge is the owner of all the Cocoa UI objects for the
// message_center. It bridges C++ notifications from the UiController to // message_center. It bridges C++ notifications from the PoupsOnlyUiController
// the various UI objects. // to the various UI objects.
class MessageCenterBridge : public message_center::UiDelegate { class MessageCenterBridge : public PopupsOnlyUiController::Delegate {
public: public:
explicit MessageCenterBridge(message_center::MessageCenter* message_center); explicit MessageCenterBridge(message_center::MessageCenter* message_center);
~MessageCenterBridge() override; ~MessageCenterBridge() override;
// message_center::UiDelegate: // PopupsUiController::Delegate:
void OnMessageCenterContentsChanged() override; void ShowPopups() override;
bool ShowPopups() override;
void HidePopups() override; void HidePopups() override;
bool ShowMessageCenter(bool show_by_click) override;
void HideMessageCenter() override;
bool ShowNotifierSettings() override;
private: private:
friend class MessageCenterBridgeTest; friend class MessageCenterBridgeTest;
// The global, singleton message center model object. Weak. // The global, singleton message center model object. Weak.
message_center::MessageCenter* message_center_; message_center::MessageCenter* const message_center_;
// C++ controller for the UI (which informs |this| of changes).
std::unique_ptr<message_center::UiController> controller_;
// Obj-C controller for the on-screen popup notifications. // Obj-C controller for the on-screen popup notifications.
base::scoped_nsobject<MCPopupCollection> popup_collection_; base::scoped_nsobject<MCPopupCollection> popup_collection_;
......
...@@ -10,37 +10,25 @@ ...@@ -10,37 +10,25 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#import "ui/message_center/cocoa/popup_collection.h" #import "ui/message_center/cocoa/popup_collection.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/ui_controller.h"
message_center::UiDelegate* CreateUiDelegate() { // static
return new MessageCenterBridge(message_center::MessageCenter::Get()); std::unique_ptr<PopupsOnlyUiController::Delegate>
PopupsOnlyUiController::CreateDelegate() {
return std::make_unique<MessageCenterBridge>(
message_center::MessageCenter::Get());
} }
MessageCenterBridge::MessageCenterBridge( MessageCenterBridge::MessageCenterBridge(
message_center::MessageCenter* message_center) message_center::MessageCenter* message_center)
: message_center_(message_center), : message_center_(message_center) {}
controller_(new message_center::UiController(this)) {}
MessageCenterBridge::~MessageCenterBridge() {} MessageCenterBridge::~MessageCenterBridge() {}
void MessageCenterBridge::OnMessageCenterContentsChanged() {} void MessageCenterBridge::ShowPopups() {
bool MessageCenterBridge::ShowPopups() {
popup_collection_.reset( popup_collection_.reset(
[[MCPopupCollection alloc] initWithMessageCenter:message_center_]); [[MCPopupCollection alloc] initWithMessageCenter:message_center_]);
return true;
} }
void MessageCenterBridge::HidePopups() { void MessageCenterBridge::HidePopups() {
popup_collection_.reset(); popup_collection_.reset();
} }
bool MessageCenterBridge::ShowMessageCenter(bool show_by_click) {
return false;
}
void MessageCenterBridge::HideMessageCenter() {}
bool MessageCenterBridge::ShowNotifierSettings() {
return false;
}
...@@ -6,59 +6,33 @@ ...@@ -6,59 +6,33 @@
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/ui_controller.h"
#include "ui/message_center/views/desktop_popup_alignment_delegate.h" #include "ui/message_center/views/desktop_popup_alignment_delegate.h"
#include "ui/message_center/views/message_popup_collection.h" #include "ui/message_center/views/message_popup_collection.h"
message_center::UiDelegate* CreateUiDelegate() { // static
return new PopupsOnlyUiDelegate(); std::unique_ptr<PopupsOnlyUiController::Delegate>
PopupsOnlyUiController::CreateDelegate() {
return std::make_unique<PopupsOnlyUiDelegate>();
} }
PopupsOnlyUiDelegate::PopupsOnlyUiDelegate() { PopupsOnlyUiDelegate::PopupsOnlyUiDelegate() {
ui_controller_.reset(new message_center::UiController(this));
alignment_delegate_.reset(new message_center::DesktopPopupAlignmentDelegate); alignment_delegate_.reset(new message_center::DesktopPopupAlignmentDelegate);
popup_collection_.reset( popup_collection_.reset(
new message_center::MessagePopupCollection(alignment_delegate_.get())); new message_center::MessagePopupCollection(alignment_delegate_.get()));
message_center()->SetHasMessageCenterView(false);
} }
PopupsOnlyUiDelegate::~PopupsOnlyUiDelegate() { PopupsOnlyUiDelegate::~PopupsOnlyUiDelegate() {
// Reset this early so that delegated events during destruction don't cause // Reset this early so that delegated events during destruction don't cause
// problems. // problems.
popup_collection_.reset(); popup_collection_.reset();
ui_controller_.reset();
} }
message_center::MessageCenter* PopupsOnlyUiDelegate::message_center() { void PopupsOnlyUiDelegate::ShowPopups() {
return ui_controller_->message_center();
}
bool PopupsOnlyUiDelegate::ShowPopups() {
alignment_delegate_->StartObserving(display::Screen::GetScreen()); alignment_delegate_->StartObserving(display::Screen::GetScreen());
popup_collection_->Update(); popup_collection_->Update();
return true;
} }
void PopupsOnlyUiDelegate::HidePopups() { void PopupsOnlyUiDelegate::HidePopups() {
DCHECK(popup_collection_.get()); DCHECK(popup_collection_.get());
popup_collection_->MarkAllPopupsShown(); popup_collection_->MarkAllPopupsShown();
} }
bool PopupsOnlyUiDelegate::ShowMessageCenter(bool show_by_click) {
// Message center not available on Windows/Linux.
return false;
}
void PopupsOnlyUiDelegate::HideMessageCenter() {}
bool PopupsOnlyUiDelegate::ShowNotifierSettings() {
// Message center settings not available on Windows/Linux.
return false;
}
void PopupsOnlyUiDelegate::OnMessageCenterContentsChanged() {}
message_center::UiController*
PopupsOnlyUiDelegate::GetUiControllerForTesting() {
return ui_controller_.get();
}
...@@ -8,12 +8,10 @@ ...@@ -8,12 +8,10 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "ui/message_center/ui_delegate.h" #include "chrome/browser/notifications/popups_only_ui_controller.h"
namespace message_center { namespace message_center {
class DesktopPopupAlignmentDelegate; class DesktopPopupAlignmentDelegate;
class MessageCenter;
class UiController;
class MessagePopupCollection; class MessagePopupCollection;
} // namespace message_center } // namespace message_center
...@@ -21,28 +19,19 @@ class MessagePopupCollection; ...@@ -21,28 +19,19 @@ class MessagePopupCollection;
// in the corner of the screen, but has no dedicated message center (widget with // in the corner of the screen, but has no dedicated message center (widget with
// multiple notifications inside). This is used on Windows and Linux for // multiple notifications inside). This is used on Windows and Linux for
// non-native notifications. // non-native notifications.
class PopupsOnlyUiDelegate : public message_center::UiDelegate { class PopupsOnlyUiDelegate : public PopupsOnlyUiController::Delegate {
public: public:
PopupsOnlyUiDelegate(); PopupsOnlyUiDelegate();
~PopupsOnlyUiDelegate() override; ~PopupsOnlyUiDelegate() override;
message_center::MessageCenter* message_center();
// UiDelegate implementation. // UiDelegate implementation.
bool ShowPopups() override; void ShowPopups() override;
void HidePopups() override; void HidePopups() override;
bool ShowMessageCenter(bool show_by_click) override;
void HideMessageCenter() override;
void OnMessageCenterContentsChanged() override;
bool ShowNotifierSettings() override;
message_center::UiController* GetUiControllerForTesting();
private: private:
std::unique_ptr<message_center::MessagePopupCollection> popup_collection_; std::unique_ptr<message_center::MessagePopupCollection> popup_collection_;
std::unique_ptr<message_center::DesktopPopupAlignmentDelegate> std::unique_ptr<message_center::DesktopPopupAlignmentDelegate>
alignment_delegate_; alignment_delegate_;
std::unique_ptr<message_center::UiController> ui_controller_;
DISALLOW_COPY_AND_ASSIGN(PopupsOnlyUiDelegate); DISALLOW_COPY_AND_ASSIGN(PopupsOnlyUiDelegate);
}; };
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/notifications/popups_only_ui_controller.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/notification_list.h" #include "ui/message_center/notification_list.h"
...@@ -17,7 +18,6 @@ ...@@ -17,7 +18,6 @@
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h" #include "ui/message_center/public/cpp/notification_delegate.h"
#include "ui/message_center/public/cpp/notification_types.h" #include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/ui_controller.h"
#include "ui/message_center/views/message_popup_collection.h" #include "ui/message_center/views/message_popup_collection.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -92,30 +92,32 @@ class PopupsOnlyUiDelegateTest : public views::test::WidgetTest { ...@@ -92,30 +92,32 @@ class PopupsOnlyUiDelegateTest : public views::test::WidgetTest {
}; };
TEST_F(PopupsOnlyUiDelegateTest, WebNotificationPopupBubble) { TEST_F(PopupsOnlyUiDelegateTest, WebNotificationPopupBubble) {
auto delegate = std::make_unique<PopupsOnlyUiDelegate>(); auto ui_controller = std::make_unique<PopupsOnlyUiController>(
std::make_unique<PopupsOnlyUiDelegate>());
// Adding a notification should show the popup bubble. // Adding a notification should show the popup bubble.
AddNotification("id1"); AddNotification("id1");
EXPECT_TRUE(delegate->GetUiControllerForTesting()->popups_visible()); EXPECT_TRUE(ui_controller->popups_visible());
// Updating a notification should not hide the popup bubble. // Updating a notification should not hide the popup bubble.
AddNotification("id2"); AddNotification("id2");
UpdateNotification("id2"); UpdateNotification("id2");
EXPECT_TRUE(delegate->GetUiControllerForTesting()->popups_visible()); EXPECT_TRUE(ui_controller->popups_visible());
// Removing the first notification should not hide the popup bubble. // Removing the first notification should not hide the popup bubble.
RemoveNotification("id1"); RemoveNotification("id1");
EXPECT_TRUE(delegate->GetUiControllerForTesting()->popups_visible()); EXPECT_TRUE(ui_controller->popups_visible());
// Removing the visible notification should hide the popup bubble. // Removing the visible notification should hide the popup bubble.
RemoveNotification("id2"); RemoveNotification("id2");
EXPECT_FALSE(delegate->GetUiControllerForTesting()->popups_visible()); EXPECT_FALSE(ui_controller->popups_visible());
delegate->HidePopups(); ui_controller->delegate()->HidePopups();
} }
TEST_F(PopupsOnlyUiDelegateTest, ManyPopupNotifications) { TEST_F(PopupsOnlyUiDelegateTest, ManyPopupNotifications) {
auto delegate = std::make_unique<PopupsOnlyUiDelegate>(); auto ui_controller = std::make_unique<PopupsOnlyUiController>(
std::make_unique<PopupsOnlyUiDelegate>());
// Add the max visible popup notifications +1, ensure the correct num visible. // Add the max visible popup notifications +1, ensure the correct num visible.
size_t notifications_to_add = size_t notifications_to_add =
...@@ -124,8 +126,8 @@ TEST_F(PopupsOnlyUiDelegateTest, ManyPopupNotifications) { ...@@ -124,8 +126,8 @@ TEST_F(PopupsOnlyUiDelegateTest, ManyPopupNotifications) {
std::string id = base::StringPrintf("id%d", static_cast<int>(i)); std::string id = base::StringPrintf("id%d", static_cast<int>(i));
AddNotification(id); AddNotification(id);
} }
EXPECT_TRUE(delegate->GetUiControllerForTesting()->popups_visible()); EXPECT_TRUE(ui_controller->popups_visible());
MessageCenter* message_center = delegate->message_center(); MessageCenter* message_center = MessageCenter::Get();
EXPECT_EQ(notifications_to_add, message_center->NotificationCount()); EXPECT_EQ(notifications_to_add, message_center->NotificationCount());
message_center::NotificationList::PopupNotifications popups = message_center::NotificationList::PopupNotifications popups =
message_center->GetPopupNotifications(); message_center->GetPopupNotifications();
......
...@@ -89,9 +89,6 @@ jumbo_component("message_center") { ...@@ -89,9 +89,6 @@ jumbo_component("message_center") {
"popup_timer.h", "popup_timer.h",
"popup_timers_controller.cc", "popup_timers_controller.cc",
"popup_timers_controller.h", "popup_timers_controller.h",
"ui_controller.cc",
"ui_controller.h",
"ui_delegate.h",
] ]
sources += get_target_outputs(":message_center_vector_icons") sources += get_target_outputs(":message_center_vector_icons")
...@@ -110,6 +107,15 @@ jumbo_component("message_center") { ...@@ -110,6 +107,15 @@ jumbo_component("message_center") {
] ]
} }
# TODO(yoshiki): move the following files to ash/message_center.
if (is_chromeos) {
sources += [
"ui_controller.cc",
"ui_controller.h",
"ui_delegate.h",
]
}
# On Mac, toolkit-views builds still use the Cocoa UI. Keep this in sync # On Mac, toolkit-views builds still use the Cocoa UI. Keep this in sync
# with message_center_unittests below. # with message_center_unittests below.
if (toolkit_views && !is_mac) { if (toolkit_views && !is_mac) {
...@@ -176,8 +182,6 @@ if (enable_message_center) { ...@@ -176,8 +182,6 @@ if (enable_message_center) {
sources = [ sources = [
"fake_message_center.cc", "fake_message_center.cc",
"fake_message_center.h", "fake_message_center.h",
"fake_ui_delegate.cc",
"fake_ui_delegate.h",
] ]
deps = [ deps = [
...@@ -203,7 +207,6 @@ if (enable_message_center) { ...@@ -203,7 +207,6 @@ if (enable_message_center) {
"notification_list_unittest.cc", "notification_list_unittest.cc",
"public/cpp/notification_delegate_unittest.cc", "public/cpp/notification_delegate_unittest.cc",
"test/run_all_unittests.cc", "test/run_all_unittests.cc",
"ui_controller_unittest.cc",
] ]
deps = [ deps = [
...@@ -236,7 +239,13 @@ if (enable_message_center) { ...@@ -236,7 +239,13 @@ if (enable_message_center) {
] ]
if (is_chromeos) { if (is_chromeos) {
sources += [ "public/mojo/struct_traits_unittest.cc" ] sources += [
"public/mojo/struct_traits_unittest.cc",
# TODO(yoshiki): move ui_controller_unittest.cc to ash/message_center.
"ui_controller_unittest.cc",
]
deps += [ deps += [
"//mojo/core/embedder", "//mojo/core/embedder",
"//ui/message_center/public/mojo:test_interfaces", "//ui/message_center/public/mojo:test_interfaces",
......
// Copyright 2014 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 "ui/message_center/fake_ui_delegate.h"
#include "ui/message_center/ui_controller.h"
namespace message_center {
FakeUiDelegate::FakeUiDelegate() : tray_(new UiController(this)) {}
FakeUiDelegate::~FakeUiDelegate() {}
void FakeUiDelegate::OnMessageCenterContentsChanged() {}
bool FakeUiDelegate::ShowPopups() {
return false;
}
void FakeUiDelegate::HidePopups() {}
bool FakeUiDelegate::ShowMessageCenter(bool show_by_click) {
return false;
}
void FakeUiDelegate::HideMessageCenter() {}
bool FakeUiDelegate::ShowNotifierSettings() {
return false;
}
} // namespace message_center
// Copyright 2014 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 UI_MESSAGE_CENTER_FAKE_UI_DELEGATE_H_
#define UI_MESSAGE_CENTER_FAKE_UI_DELEGATE_H_
#include <memory>
#include "base/callback.h"
#include "base/macros.h"
#include "ui/message_center/ui_delegate.h"
namespace message_center {
class UiController;
// A message center UI delegate which does nothing.
class FakeUiDelegate : public UiDelegate {
public:
FakeUiDelegate();
~FakeUiDelegate() override;
// Overridden from UiDelegate:
void OnMessageCenterContentsChanged() override;
bool ShowPopups() override;
void HidePopups() override;
bool ShowMessageCenter(bool show_by_click) override;
void HideMessageCenter() override;
bool ShowNotifierSettings() override;
private:
std::unique_ptr<UiController> tray_;
base::Closure quit_closure_;
DISALLOW_COPY_AND_ASSIGN(FakeUiDelegate);
};
} // namespace message_center
#endif // UI_MESSAGE_CENTER_FAKE_UI_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment