Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <utility> | |
| 6 | |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/metrics/user_metrics_action.h" | |
| 9 #include "ash/common/system/chromeos/network/sms_observer.h" | |
| 10 #include "ash/common/system/system_notifier.h" | |
| 11 #include "ash/common/system/tray/tray_constants.h" | |
| 12 #include "ash/common/wm_shell.h" | |
| 13 #include "ash/resources/vector_icons/vector_icons.h" | |
| 14 #include "base/memory/ptr_util.h" | |
| 15 #include "base/strings/string_number_conversions.h" | |
| 16 #include "base/strings/utf_string_conversions.h" | |
| 17 #include "chromeos/network/network_event_log.h" | |
| 18 #include "chromeos/network/network_handler.h" | |
| 19 #include "grit/ash_resources.h" | |
| 20 #include "grit/ash_strings.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | |
| 22 #include "ui/base/resource/resource_bundle.h" | |
| 23 #include "ui/gfx/paint_vector_icon.h" | |
| 24 #include "ui/message_center/message_center.h" | |
| 25 #include "ui/views/view.h" | |
| 26 | |
| 27 namespace ash { | |
| 28 | |
| 29 const char SmsObserver::kNotificationId[] = "chrome://network/sms"; | |
| 30 | |
| 31 SmsObserver::SmsObserver() : message_id_(0) { | |
| 32 // TODO(armansito): SMS could be a special case for cellular that requires a | |
| 33 // user (perhaps the owner) to be logged in. If that is the case, then an | |
| 34 // additional check should be done before subscribing for SMS notifications. | |
| 35 if (chromeos::NetworkHandler::IsInitialized()) | |
| 36 chromeos::NetworkHandler::Get()->network_sms_handler()->AddObserver(this); | |
| 37 } | |
| 38 | |
| 39 SmsObserver::~SmsObserver() { | |
| 40 if (chromeos::NetworkHandler::IsInitialized()) { | |
| 41 chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver( | |
| 42 this); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void SmsObserver::MessageReceived(const base::DictionaryValue& message) { | |
| 47 std::string message_text; | |
| 48 if (!message.GetStringWithoutPathExpansion( | |
| 49 chromeos::NetworkSmsHandler::kTextKey, &message_text)) { | |
| 50 NET_LOG_ERROR("SMS message contains no content.", ""); | |
| 51 return; | |
| 52 } | |
| 53 // TODO(armansito): A message might be due to a special "Message Waiting" | |
| 54 // state that the message is in. Once SMS handling moves to shill, such | |
| 55 // messages should be filtered there so that this check becomes unnecessary. | |
| 56 if (message_text.empty()) { | |
| 57 NET_LOG_DEBUG("SMS has empty content text. Ignoring.", ""); | |
| 58 return; | |
| 59 } | |
| 60 std::string message_number; | |
| 61 if (!message.GetStringWithoutPathExpansion( | |
| 62 chromeos::NetworkSmsHandler::kNumberKey, &message_number)) { | |
| 63 NET_LOG_DEBUG("SMS contains no number. Ignoring.", ""); | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 NET_LOG_DEBUG( | |
| 68 "Received SMS from: " + message_number + " with text: " + message_text, | |
| 69 ""); | |
| 70 message_id_++; | |
| 71 Update(&message, message_text, message_number); | |
| 72 } | |
| 73 | |
| 74 void SmsObserver::Update(const base::DictionaryValue* message, | |
| 75 std::string message_text, | |
| 76 std::string message_number) { | |
| 77 gfx::Image image(gfx::Image( | |
|
tdanderson
2017/02/07 00:15:45
You don't need the inner gfx::Image here, just gfx
yiyix
2017/02/07 22:03:22
I will address it as we have discussed offline.
| |
| 78 CreateVectorIcon(kSystemMenuSmsIcon, kMenuIconSize, kMenuIconColor))); | |
| 79 | |
| 80 std::string notification_id = kNotificationId + std::to_string(message_id_); | |
| 81 std::unique_ptr<message_center::Notification> notification; | |
| 82 notification.reset(new message_center::Notification( | |
| 83 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, | |
| 84 base::ASCIIToUTF16(message_number), base::ASCIIToUTF16(message_text), | |
| 85 image, base::string16(), GURL(), | |
| 86 message_center::NotifierId(message_center::NotifierId::APPLICATION, | |
| 87 system_notifier::kNotifierSms), | |
| 88 message_center::RichNotificationData(), nullptr)); | |
| 89 message_center::MessageCenter::Get()->AddNotification( | |
| 90 std::move(notification)); | |
| 91 } | |
| 92 | |
| 93 } // namespace ash | |
| OLD | NEW |