OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/chromeos/net/tether_notification_presenter.h" | 5 #include "chrome/browser/chromeos/net/tether_notification_presenter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/ui/chrome_pages.h" |
11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
12 #include "components/proximity_auth/logging/logging.h" | 13 #include "components/proximity_auth/logging/logging.h" |
13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
15 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
16 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
17 #include "ui/message_center/notifier_settings.h" | 18 #include "ui/message_center/notifier_settings.h" |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 namespace tether { | 22 namespace tether { |
22 | 23 |
| 24 namespace { |
| 25 |
| 26 const char kTetherSettingsSubpage[] = "networks?type=Tether"; |
| 27 |
| 28 class SettingsUiDelegateImpl |
| 29 : public TetherNotificationPresenter::SettingsUiDelegate { |
| 30 public: |
| 31 SettingsUiDelegateImpl() {} |
| 32 ~SettingsUiDelegateImpl() override {} |
| 33 |
| 34 void ShowSettingsSubPageForProfile(Profile* profile, |
| 35 const std::string& sub_page) override { |
| 36 chrome::ShowSettingsSubPageForProfile(profile, sub_page); |
| 37 } |
| 38 }; |
| 39 |
| 40 } // namespace |
| 41 |
23 // static | 42 // static |
24 constexpr const char TetherNotificationPresenter::kTetherNotifierId[] = | 43 constexpr const char TetherNotificationPresenter::kTetherNotifierId[] = |
25 "cros_tether_notification_ids.notifier_id"; | 44 "cros_tether_notification_ids.notifier_id"; |
26 | 45 |
27 // static | 46 // static |
28 constexpr const char TetherNotificationPresenter::kActiveHostNotificationId[] = | 47 constexpr const char TetherNotificationPresenter::kActiveHostNotificationId[] = |
29 "cros_tether_notification_ids.active_host"; | 48 "cros_tether_notification_ids.active_host"; |
30 | 49 |
31 // static | 50 // static |
32 constexpr const char | 51 constexpr const char |
(...skipping 22 matching lines...) Expand all Loading... |
55 // TODO(khorimoto): Add tether icon. | 74 // TODO(khorimoto): Add tether icon. |
56 gfx::Image() /* icon */, base::string16() /* display_source */, | 75 gfx::Image() /* icon */, base::string16() /* display_source */, |
57 GURL() /* origin_url */, | 76 GURL() /* origin_url */, |
58 message_center::NotifierId( | 77 message_center::NotifierId( |
59 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, | 78 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, |
60 kTetherNotifierId), | 79 kTetherNotifierId), |
61 rich_notification_data, nullptr); | 80 rich_notification_data, nullptr); |
62 } | 81 } |
63 | 82 |
64 TetherNotificationPresenter::TetherNotificationPresenter( | 83 TetherNotificationPresenter::TetherNotificationPresenter( |
| 84 Profile* profile, |
65 message_center::MessageCenter* message_center, | 85 message_center::MessageCenter* message_center, |
66 NetworkConnect* network_connect) | 86 NetworkConnect* network_connect) |
67 : message_center_(message_center), | 87 : profile_(profile), |
| 88 message_center_(message_center), |
68 network_connect_(network_connect), | 89 network_connect_(network_connect), |
| 90 settings_ui_delegate_(base::WrapUnique(new SettingsUiDelegateImpl())), |
69 weak_ptr_factory_(this) { | 91 weak_ptr_factory_(this) { |
70 message_center_->AddObserver(this); | 92 message_center_->AddObserver(this); |
71 } | 93 } |
72 | 94 |
73 TetherNotificationPresenter::~TetherNotificationPresenter() { | 95 TetherNotificationPresenter::~TetherNotificationPresenter() { |
74 message_center_->RemoveObserver(this); | 96 message_center_->RemoveObserver(this); |
75 } | 97 } |
76 | 98 |
77 void TetherNotificationPresenter::NotifyPotentialHotspotNearby( | 99 void TetherNotificationPresenter::NotifyPotentialHotspotNearby( |
78 const cryptauth::RemoteDevice& remote_device) { | 100 const cryptauth::RemoteDevice& remote_device) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 PA_LOG(INFO) << "Removing \"connection attempt failed\" dialog. " | 156 PA_LOG(INFO) << "Removing \"connection attempt failed\" dialog. " |
135 << "Notification ID = " << kActiveHostNotificationId; | 157 << "Notification ID = " << kActiveHostNotificationId; |
136 | 158 |
137 message_center_->RemoveNotification(std::string(kActiveHostNotificationId), | 159 message_center_->RemoveNotification(std::string(kActiveHostNotificationId), |
138 false /* by_user */); | 160 false /* by_user */); |
139 } | 161 } |
140 | 162 |
141 void TetherNotificationPresenter::OnNotificationClicked( | 163 void TetherNotificationPresenter::OnNotificationClicked( |
142 const std::string& notification_id) { | 164 const std::string& notification_id) { |
143 PA_LOG(INFO) << "Notification with ID " << notification_id << " was clicked."; | 165 PA_LOG(INFO) << "Notification with ID " << notification_id << " was clicked."; |
144 | 166 settings_ui_delegate_->ShowSettingsSubPageForProfile(profile_, |
145 // TODO(khorimoto): Open the settings page. | 167 kTetherSettingsSubpage); |
146 } | 168 } |
147 | 169 |
148 void TetherNotificationPresenter::OnNotificationButtonClicked( | 170 void TetherNotificationPresenter::OnNotificationButtonClicked( |
149 const std::string& notification_id, | 171 const std::string& notification_id, |
150 int button_index) { | 172 int button_index) { |
151 PA_LOG(INFO) << "Button at index " << button_index | 173 PA_LOG(INFO) << "Button at index " << button_index |
152 << " of notification with ID " << notification_id | 174 << " of notification with ID " << notification_id |
153 << " was clicked."; | 175 << " was clicked."; |
154 | 176 |
155 if (notification_id == kPotentialHotspotNotificationId && button_index == 0) { | 177 if (notification_id == kPotentialHotspotNotificationId && button_index == 0) { |
156 // TODO (hansberry): Only directly start a connection if this is not the | |
157 // first time the user has connected to a host. | |
158 network_connect_->ConnectToNetworkId(hotspot_nearby_device_.GetDeviceId()); | 178 network_connect_->ConnectToNetworkId(hotspot_nearby_device_.GetDeviceId()); |
159 } | 179 } |
160 } | 180 } |
161 | 181 |
| 182 void TetherNotificationPresenter::SetSettingsUiDelegateForTesting( |
| 183 std::unique_ptr<SettingsUiDelegate> settings_ui_delegate) { |
| 184 settings_ui_delegate_ = std::move(settings_ui_delegate); |
| 185 } |
| 186 |
162 void TetherNotificationPresenter::ShowNotification( | 187 void TetherNotificationPresenter::ShowNotification( |
163 std::unique_ptr<message_center::Notification> notification) { | 188 std::unique_ptr<message_center::Notification> notification) { |
164 std::string notification_id = notification->id(); | 189 std::string notification_id = notification->id(); |
165 if (message_center_->FindVisibleNotificationById(notification_id)) { | 190 if (message_center_->FindVisibleNotificationById(notification_id)) { |
166 message_center_->UpdateNotification(notification_id, | 191 message_center_->UpdateNotification(notification_id, |
167 std::move(notification)); | 192 std::move(notification)); |
168 } else { | 193 } else { |
169 message_center_->AddNotification(std::move(notification)); | 194 message_center_->AddNotification(std::move(notification)); |
170 } | 195 } |
171 } | 196 } |
172 | 197 |
173 } // namespace tether | 198 } // namespace tether |
174 | 199 |
175 } // namespace chromeos | 200 } // namespace chromeos |
OLD | NEW |