Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(788)

Side by Side Diff: ash/system/locale/locale_notification_controller.cc

Issue 2082193002: mash: Migrate locale observer and notification to common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Format Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "ash/system/locale/locale_notification_controller.h"
6
7 #include <utility>
8
9 #include "ash/common/system/system_notifier.h"
10 #include "ash/shell.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "base/strings/string16.h"
13 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/message_center/message_center.h"
18 #include "ui/message_center/notification.h"
19 #include "ui/message_center/notification_delegate.h"
20 #include "ui/message_center/notification_types.h"
21
22 using message_center::Notification;
23
24 namespace ash {
25 namespace {
26
27 const char kLocaleChangeNotificationId[] = "chrome://settings/locale";
28
29 class LocaleNotificationDelegate : public message_center::NotificationDelegate {
30 public:
31 explicit LocaleNotificationDelegate(LocaleObserver::Delegate* delegate);
32
33 protected:
34 ~LocaleNotificationDelegate() override;
35
36 // message_center::NotificationDelegate overrides:
37 void Close(bool by_user) override;
38 bool HasClickedListener() override;
39 void Click() override;
40 void ButtonClick(int button_index) override;
41
42 private:
43 LocaleObserver::Delegate* delegate_;
44
45 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate);
46 };
47
48 LocaleNotificationDelegate::LocaleNotificationDelegate(
49 LocaleObserver::Delegate* delegate)
50 : delegate_(delegate) {
51 DCHECK(delegate_);
52 }
53
54 LocaleNotificationDelegate::~LocaleNotificationDelegate() {
55 }
56
57 void LocaleNotificationDelegate::Close(bool by_user) {
58 delegate_->AcceptLocaleChange();
59 }
60
61 bool LocaleNotificationDelegate::HasClickedListener() {
62 return true;
63 }
64
65 void LocaleNotificationDelegate::Click() {
66 delegate_->AcceptLocaleChange();
67 }
68
69 void LocaleNotificationDelegate::ButtonClick(int button_index) {
70 DCHECK_EQ(0, button_index);
71 delegate_->RevertLocaleChange();
72 }
73
74 } // namespace
75
76 LocaleNotificationController::LocaleNotificationController() {
77 Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this);
78 }
79
80 LocaleNotificationController::~LocaleNotificationController() {
81 Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this);
82 }
83
84 void LocaleNotificationController::OnLocaleChanged(
85 LocaleObserver::Delegate* delegate,
86 const std::string& cur_locale,
87 const std::string& from_locale,
88 const std::string& to_locale) {
89 if (!delegate)
90 return;
91
92 base::string16 from = l10n_util::GetDisplayNameForLocale(
93 from_locale, cur_locale, true);
94 base::string16 to = l10n_util::GetDisplayNameForLocale(
95 to_locale, cur_locale, true);
96
97 message_center::RichNotificationData optional;
98 optional.buttons.push_back(message_center::ButtonInfo(
99 l10n_util::GetStringFUTF16(
100 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from)));
101 optional.never_timeout = true;
102
103 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
104 std::unique_ptr<Notification> notification(new Notification(
105 message_center::NOTIFICATION_TYPE_SIMPLE, kLocaleChangeNotificationId,
106 base::string16() /* title */,
107 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE,
108 from, to),
109 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE),
110 base::string16() /* display_source */, GURL(),
111 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
112 system_notifier::kNotifierLocale),
113 optional, new LocaleNotificationDelegate(delegate)));
114 message_center::MessageCenter::Get()->AddNotification(
115 std::move(notification));
116 }
117
118 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698