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

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

Issue 2867673004: Use OnceCallback on Mojo interfaces in //ash (Closed)
Patch Set: count -> container_count Created 3 years, 7 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/locale/locale_notification_controller.h" 5 #include "ash/system/locale/locale_notification_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/resources/grit/ash_resources.h" 10 #include "ash/resources/grit/ash_resources.h"
(...skipping 11 matching lines...) Expand all
22 using message_center::Notification; 22 using message_center::Notification;
23 23
24 namespace ash { 24 namespace ash {
25 namespace { 25 namespace {
26 26
27 const char kLocaleChangeNotificationId[] = "chrome://settings/locale"; 27 const char kLocaleChangeNotificationId[] = "chrome://settings/locale";
28 28
29 class LocaleNotificationDelegate : public message_center::NotificationDelegate { 29 class LocaleNotificationDelegate : public message_center::NotificationDelegate {
30 public: 30 public:
31 explicit LocaleNotificationDelegate( 31 explicit LocaleNotificationDelegate(
32 const base::Callback<void(ash::mojom::LocaleNotificationResult)>& 32 base::OnceCallback<void(ash::mojom::LocaleNotificationResult)> callback);
33 callback);
34 33
35 protected: 34 protected:
36 ~LocaleNotificationDelegate() override; 35 ~LocaleNotificationDelegate() override;
37 36
38 // message_center::NotificationDelegate overrides: 37 // message_center::NotificationDelegate overrides:
39 void Close(bool by_user) override; 38 void Close(bool by_user) override;
40 bool HasClickedListener() override; 39 bool HasClickedListener() override;
41 void Click() override; 40 void Click() override;
42 void ButtonClick(int button_index) override; 41 void ButtonClick(int button_index) override;
43 42
44 private: 43 private:
45 base::Callback<void(ash::mojom::LocaleNotificationResult)> callback_; 44 base::OnceCallback<void(ash::mojom::LocaleNotificationResult)> callback_;
46 45
47 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate); 46 DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate);
48 }; 47 };
49 48
50 LocaleNotificationDelegate::LocaleNotificationDelegate( 49 LocaleNotificationDelegate::LocaleNotificationDelegate(
51 const base::Callback<void(ash::mojom::LocaleNotificationResult)>& callback) 50 base::OnceCallback<void(ash::mojom::LocaleNotificationResult)> callback)
52 : callback_(callback) {} 51 : callback_(std::move(callback)) {}
53 52
54 LocaleNotificationDelegate::~LocaleNotificationDelegate() { 53 LocaleNotificationDelegate::~LocaleNotificationDelegate() {
55 if (callback_) { 54 if (callback_) {
56 // We're being destroyed but the user didn't click on anything. Run the 55 // We're being destroyed but the user didn't click on anything. Run the
57 // callback so that we don't crash. 56 // callback so that we don't crash.
58 callback_.Run(ash::mojom::LocaleNotificationResult::ACCEPT); 57 std::move(callback_).Run(ash::mojom::LocaleNotificationResult::ACCEPT);
59 } 58 }
60 } 59 }
61 60
62 void LocaleNotificationDelegate::Close(bool by_user) { 61 void LocaleNotificationDelegate::Close(bool by_user) {
63 if (callback_) { 62 if (callback_) {
64 callback_.Run(ash::mojom::LocaleNotificationResult::ACCEPT); 63 std::move(callback_).Run(ash::mojom::LocaleNotificationResult::ACCEPT);
65 callback_.Reset();
66 } 64 }
67 } 65 }
68 66
69 bool LocaleNotificationDelegate::HasClickedListener() { 67 bool LocaleNotificationDelegate::HasClickedListener() {
70 return true; 68 return true;
71 } 69 }
72 70
73 void LocaleNotificationDelegate::Click() { 71 void LocaleNotificationDelegate::Click() {
74 if (callback_) { 72 if (callback_) {
75 callback_.Run(ash::mojom::LocaleNotificationResult::ACCEPT); 73 std::move(callback_).Run(ash::mojom::LocaleNotificationResult::ACCEPT);
76 callback_.Reset();
77 } 74 }
78 } 75 }
79 76
80 void LocaleNotificationDelegate::ButtonClick(int button_index) { 77 void LocaleNotificationDelegate::ButtonClick(int button_index) {
81 DCHECK_EQ(0, button_index); 78 DCHECK_EQ(0, button_index);
82 79
83 if (callback_) { 80 if (callback_) {
84 callback_.Run(ash::mojom::LocaleNotificationResult::REVERT); 81 std::move(callback_).Run(ash::mojom::LocaleNotificationResult::REVERT);
85 callback_.Reset();
86 } 82 }
87 } 83 }
88 84
89 } // namespace 85 } // namespace
90 86
91 LocaleNotificationController::LocaleNotificationController() {} 87 LocaleNotificationController::LocaleNotificationController() {}
92 88
93 LocaleNotificationController::~LocaleNotificationController() {} 89 LocaleNotificationController::~LocaleNotificationController() {}
94 90
95 void LocaleNotificationController::BindRequest( 91 void LocaleNotificationController::BindRequest(
96 mojom::LocaleNotificationControllerRequest request) { 92 mojom::LocaleNotificationControllerRequest request) {
97 bindings_.AddBinding(this, std::move(request)); 93 bindings_.AddBinding(this, std::move(request));
98 } 94 }
99 95
100 void LocaleNotificationController::OnLocaleChanged( 96 void LocaleNotificationController::OnLocaleChanged(
101 const std::string& cur_locale, 97 const std::string& cur_locale,
102 const std::string& from_locale, 98 const std::string& from_locale,
103 const std::string& to_locale, 99 const std::string& to_locale,
104 const OnLocaleChangedCallback& callback) { 100 OnLocaleChangedCallback callback) {
105 base::string16 from = 101 base::string16 from =
106 l10n_util::GetDisplayNameForLocale(from_locale, cur_locale, true); 102 l10n_util::GetDisplayNameForLocale(from_locale, cur_locale, true);
107 base::string16 to = 103 base::string16 to =
108 l10n_util::GetDisplayNameForLocale(to_locale, cur_locale, true); 104 l10n_util::GetDisplayNameForLocale(to_locale, cur_locale, true);
109 105
110 message_center::RichNotificationData optional; 106 message_center::RichNotificationData optional;
111 optional.buttons.push_back( 107 optional.buttons.push_back(
112 message_center::ButtonInfo(l10n_util::GetStringFUTF16( 108 message_center::ButtonInfo(l10n_util::GetStringFUTF16(
113 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from))); 109 IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from)));
114 optional.never_timeout = true; 110 optional.never_timeout = true;
115 111
116 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 112 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
117 std::unique_ptr<Notification> notification(new Notification( 113 std::unique_ptr<Notification> notification(new Notification(
118 message_center::NOTIFICATION_TYPE_SIMPLE, kLocaleChangeNotificationId, 114 message_center::NOTIFICATION_TYPE_SIMPLE, kLocaleChangeNotificationId,
119 base::string16() /* title */, 115 base::string16() /* title */,
120 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, 116 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE,
121 from, to), 117 from, to),
122 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE), 118 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE),
123 base::string16() /* display_source */, GURL(), 119 base::string16() /* display_source */, GURL(),
124 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 120 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
125 system_notifier::kNotifierLocale), 121 system_notifier::kNotifierLocale),
126 optional, new LocaleNotificationDelegate(callback))); 122 optional, new LocaleNotificationDelegate(std::move(callback))));
127 message_center::MessageCenter::Get()->AddNotification( 123 message_center::MessageCenter::Get()->AddNotification(
128 std::move(notification)); 124 std::move(notification));
129 } 125 }
130 126
131 } // namespace ash 127 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/locale/locale_notification_controller.h ('k') | ash/test/test_session_state_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698