Chromium Code Reviews| Index: ash/common/system/locale/locale_notification_controller.cc |
| diff --git a/ash/common/system/locale/locale_notification_controller.cc b/ash/common/system/locale/locale_notification_controller.cc |
| index 4a5e4a1af36a541c3bf1eb6453780b8518e54fd0..a460428590d073ead7d1263d128a6c1634e17a2b 100644 |
| --- a/ash/common/system/locale/locale_notification_controller.cc |
| +++ b/ash/common/system/locale/locale_notification_controller.cc |
| @@ -4,6 +4,7 @@ |
| #include "ash/common/system/locale/locale_notification_controller.h" |
| +#include <memory> |
| #include <utility> |
| #include "ash/common/system/system_notifier.h" |
| @@ -28,7 +29,9 @@ const char kLocaleChangeNotificationId[] = "chrome://settings/locale"; |
| class LocaleNotificationDelegate : public message_center::NotificationDelegate { |
| public: |
| - explicit LocaleNotificationDelegate(LocaleObserver::Delegate* delegate); |
| + explicit LocaleNotificationDelegate( |
| + const base::Callback<void(ash::mojom::LocaleNotificationResult)>& |
| + callback); |
| protected: |
| ~LocaleNotificationDelegate() override; |
| @@ -40,21 +43,19 @@ class LocaleNotificationDelegate : public message_center::NotificationDelegate { |
| void ButtonClick(int button_index) override; |
| private: |
| - LocaleObserver::Delegate* delegate_; |
| + base::Callback<void(ash::mojom::LocaleNotificationResult)> callback_; |
| DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate); |
| }; |
| LocaleNotificationDelegate::LocaleNotificationDelegate( |
| - LocaleObserver::Delegate* delegate) |
| - : delegate_(delegate) { |
| - DCHECK(delegate_); |
| -} |
| + const base::Callback<void(ash::mojom::LocaleNotificationResult)>& callback) |
| + : callback_(callback) {} |
| LocaleNotificationDelegate::~LocaleNotificationDelegate() {} |
| void LocaleNotificationDelegate::Close(bool by_user) { |
| - delegate_->AcceptLocaleChange(); |
| + callback_.Run(ash::mojom::LocaleNotificationResult::ACCEPT); |
|
sky
2016/10/18 16:58:03
I'm not familiar with the code in this class. Are
Elliot Glaysher
2016/10/18 19:41:57
Done. (Added check in dtor, too.)
|
| } |
| bool LocaleNotificationDelegate::HasClickedListener() { |
| @@ -62,32 +63,30 @@ bool LocaleNotificationDelegate::HasClickedListener() { |
| } |
| void LocaleNotificationDelegate::Click() { |
| - delegate_->AcceptLocaleChange(); |
| + callback_.Run(ash::mojom::LocaleNotificationResult::ACCEPT); |
| } |
| void LocaleNotificationDelegate::ButtonClick(int button_index) { |
| DCHECK_EQ(0, button_index); |
| - delegate_->RevertLocaleChange(); |
| + callback_.Run(ash::mojom::LocaleNotificationResult::REVERT); |
| } |
| } // namespace |
| -LocaleNotificationController::LocaleNotificationController() { |
| - WmShell::Get()->system_tray_notifier()->AddLocaleObserver(this); |
| -} |
| +LocaleNotificationController::LocaleNotificationController() {} |
| -LocaleNotificationController::~LocaleNotificationController() { |
| - WmShell::Get()->system_tray_notifier()->RemoveLocaleObserver(this); |
| +LocaleNotificationController::~LocaleNotificationController() {} |
| + |
| +void LocaleNotificationController::BindRequest( |
| + mojom::LocaleNotificationControllerRequest request) { |
| + bindings_.AddBinding(this, std::move(request)); |
| } |
| void LocaleNotificationController::OnLocaleChanged( |
| - LocaleObserver::Delegate* delegate, |
| const std::string& cur_locale, |
| const std::string& from_locale, |
| - const std::string& to_locale) { |
| - if (!delegate) |
| - return; |
| - |
| + const std::string& to_locale, |
| + const OnLocaleChangedCallback& callback) { |
| base::string16 from = |
| l10n_util::GetDisplayNameForLocale(from_locale, cur_locale, true); |
| base::string16 to = |
| @@ -109,7 +108,7 @@ void LocaleNotificationController::OnLocaleChanged( |
| base::string16() /* display_source */, GURL(), |
| message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| system_notifier::kNotifierLocale), |
| - optional, new LocaleNotificationDelegate(delegate))); |
| + optional, new LocaleNotificationDelegate(callback))); |
| message_center::MessageCenter::Get()->AddNotification( |
| std::move(notification)); |
| } |