| 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" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 message, | 54 message, |
| 55 // TODO(khorimoto): Add tether icon. | 55 // TODO(khorimoto): Add tether icon. |
| 56 gfx::Image() /* icon */, base::string16() /* display_source */, | 56 gfx::Image() /* icon */, base::string16() /* display_source */, |
| 57 GURL() /* origin_url */, | 57 GURL() /* origin_url */, |
| 58 message_center::NotifierId( | 58 message_center::NotifierId( |
| 59 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, | 59 message_center::NotifierId::NotifierType::SYSTEM_COMPONENT, |
| 60 kTetherNotifierId), | 60 kTetherNotifierId), |
| 61 rich_notification_data, nullptr); | 61 rich_notification_data, nullptr); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TetherNotificationPresenter::TetherNotificationPresenter() | |
| 65 : TetherNotificationPresenter(message_center::MessageCenter::Get()) {} | |
| 66 | |
| 67 TetherNotificationPresenter::TetherNotificationPresenter( | 64 TetherNotificationPresenter::TetherNotificationPresenter( |
| 68 message_center::MessageCenter* message_center) | 65 message_center::MessageCenter* message_center, |
| 69 : message_center_(message_center), weak_ptr_factory_(this) { | 66 NetworkConnect* network_connect) |
| 67 : message_center_(message_center), |
| 68 network_connect_(network_connect), |
| 69 weak_ptr_factory_(this) { |
| 70 message_center_->AddObserver(this); | 70 message_center_->AddObserver(this); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TetherNotificationPresenter::~TetherNotificationPresenter() { | 73 TetherNotificationPresenter::~TetherNotificationPresenter() { |
| 74 message_center_->RemoveObserver(this); | 74 message_center_->RemoveObserver(this); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void TetherNotificationPresenter::NotifyPotentialHotspotNearby( | 77 void TetherNotificationPresenter::NotifyPotentialHotspotNearby( |
| 78 const cryptauth::RemoteDevice& remote_device) { | 78 const cryptauth::RemoteDevice& remote_device) { |
| 79 PA_LOG(INFO) << "Displaying \"potential hotspot nearby\" notification for " | 79 PA_LOG(INFO) << "Displaying \"potential hotspot nearby\" notification for " |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // TODO(khorimoto): Open the settings page. | 145 // TODO(khorimoto): Open the settings page. |
| 146 } | 146 } |
| 147 | 147 |
| 148 void TetherNotificationPresenter::OnNotificationButtonClicked( | 148 void TetherNotificationPresenter::OnNotificationButtonClicked( |
| 149 const std::string& notification_id, | 149 const std::string& notification_id, |
| 150 int button_index) { | 150 int button_index) { |
| 151 PA_LOG(INFO) << "Button at index " << button_index | 151 PA_LOG(INFO) << "Button at index " << button_index |
| 152 << " of notification with ID " << notification_id | 152 << " of notification with ID " << notification_id |
| 153 << " was clicked."; | 153 << " was clicked."; |
| 154 | 154 |
| 155 // Only the "potential hotspot nearby" notification has a button, and it only | 155 if (notification_id == kPotentialHotspotNotificationId && button_index == 0) { |
| 156 // has one button (index 0). | 156 // TODO (hansberry): Only directly start a connection if this is not the |
| 157 DCHECK(std::string(kPotentialHotspotNotificationId) == notification_id); | 157 // first time the user has connected to a host. |
| 158 DCHECK(0 == button_index); | 158 network_connect_->ConnectToNetworkId(hotspot_nearby_device_.GetDeviceId()); |
| 159 | 159 } |
| 160 // TODO(khorimoto): Start a connection. | |
| 161 } | 160 } |
| 162 | 161 |
| 163 void TetherNotificationPresenter::ShowNotification( | 162 void TetherNotificationPresenter::ShowNotification( |
| 164 std::unique_ptr<message_center::Notification> notification) { | 163 std::unique_ptr<message_center::Notification> notification) { |
| 165 std::string notification_id = notification->id(); | 164 std::string notification_id = notification->id(); |
| 166 if (message_center_->FindVisibleNotificationById(notification_id)) { | 165 if (message_center_->FindVisibleNotificationById(notification_id)) { |
| 167 message_center_->UpdateNotification(notification_id, | 166 message_center_->UpdateNotification(notification_id, |
| 168 std::move(notification)); | 167 std::move(notification)); |
| 169 } else { | 168 } else { |
| 170 message_center_->AddNotification(std::move(notification)); | 169 message_center_->AddNotification(std::move(notification)); |
| 171 } | 170 } |
| 172 } | 171 } |
| 173 | 172 |
| 174 } // namespace tether | 173 } // namespace tether |
| 175 | 174 |
| 176 } // namespace chromeos | 175 } // namespace chromeos |
| OLD | NEW |