Index: ash/common/system/chromeos/network/sms_observer.cc |
diff --git a/ash/common/system/chromeos/network/sms_observer.cc b/ash/common/system/chromeos/network/sms_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a2885180d6ef70348eb2e127b9747197d5bf87e7 |
--- /dev/null |
+++ b/ash/common/system/chromeos/network/sms_observer.cc |
@@ -0,0 +1,103 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
tdanderson
2017/01/26 22:19:06
nit: update header - no (c) and update year.
yiyix
2017/02/02 20:43:56
Done.
|
+// found in the LICENSE file. |
+ |
+#include <utility> |
+ |
+#include "ash/common/material_design/material_design_controller.h" |
+#include "ash/common/metrics/user_metrics_action.h" |
+#include "ash/common/system/chromeos/network/sms_observer.h" |
+#include "ash/common/system/system_notifier.h" |
+#include "ash/common/system/tray/tray_constants.h" |
+#include "ash/common/wm_shell.h" |
+#include "ash/resources/vector_icons/vector_icons.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chromeos/network/network_event_log.h" |
+#include "chromeos/network/network_handler.h" |
+#include "grit/ash_resources.h" |
+#include "grit/ash_strings.h" |
+#include "ui/base/l10n/l10n_util.h" |
+#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/paint_vector_icon.h" |
+#include "ui/message_center/message_center.h" |
+#include "ui/views/view.h" |
+ |
+namespace ash { |
+ |
+const char SmsObserver::kNotificationId[] = "chrome://network/sms"; |
+ |
+SmsObserver::SmsObserver() : message_id_(0) { |
+ // TODO(armansito): SMS could be a special case for cellular that requires a |
+ // user (perhaps the owner) to be logged in. If that is the case, then an |
+ // additional check should be done before subscribing for SMS notifications. |
+ if (chromeos::NetworkHandler::IsInitialized()) |
+ chromeos::NetworkHandler::Get()->network_sms_handler()->AddObserver(this); |
+} |
+ |
+SmsObserver::~SmsObserver() {} |
+ |
+void SmsObserver::Shutdown() { |
+ if (chromeos::NetworkHandler::IsInitialized()) { |
+ chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver( |
+ this); |
+ } |
+} |
+ |
+void SmsObserver::MessageReceived(const base::DictionaryValue& message) { |
+ std::string message_text; |
+ if (!message.GetStringWithoutPathExpansion( |
+ chromeos::NetworkSmsHandler::kTextKey, &message_text)) { |
+ NET_LOG_ERROR("SMS message contains no content.", ""); |
+ return; |
+ } |
+ // TODO(armansito): A message might be due to a special "Message Waiting" |
+ // state that the message is in. Once SMS handling moves to shill, such |
+ // messages should be filtered there so that this check becomes unnecessary. |
+ if (message_text.empty()) { |
+ NET_LOG_DEBUG("SMS has empty content text. Ignoring.", ""); |
+ return; |
+ } |
+ std::string message_number; |
+ if (!message.GetStringWithoutPathExpansion( |
+ chromeos::NetworkSmsHandler::kNumberKey, &message_number)) { |
+ NET_LOG_DEBUG("SMS contains no number. Ignoring.", ""); |
+ return; |
+ } |
+ |
+ NET_LOG_DEBUG( |
+ "Received SMS from: " + message_number + " with text: " + message_text, |
+ ""); |
+ message_id_++; |
tdanderson
2017/01/26 22:19:06
This member is initialized to 0 when SmsObserver i
yiyix
2017/02/02 20:43:56
It is how download notification is generated. http
tdanderson
2017/02/07 00:15:45
Can you double check that you linked to the right
yiyix
2017/02/07 22:03:21
As we have discussed offline, The logic where it i
|
+ Update(&message, message_text, message_number); |
+} |
+ |
+void SmsObserver::Update(const base::DictionaryValue* message, |
+ std::string message_text, |
+ std::string message_number) { |
+ std::unique_ptr<message_center::Notification> notification; |
tdanderson
2017/01/26 22:19:06
I don't think you need to declare this so early, I
yiyix
2017/02/02 20:43:56
Sure. Declare the variable before using it. I was
tdanderson
2017/02/07 00:15:45
Thanks.
|
+ gfx::Image* image; |
+ if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
+ image = new gfx::Image( |
+ CreateVectorIcon(kSystemMenuSmsIcon, kMenuIconSize, kMenuIconColor)); |
+ } else { |
tdanderson
2017/01/26 23:12:50
Also, you can land this with just lines 82-83. We
yiyix
2017/02/02 20:43:56
Yeah~ Finally, we can land code with md path only!
tdanderson
2017/02/07 00:15:45
:)
|
+ image = new gfx::Image( |
+ *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
+ IDR_AURA_UBER_TRAY_SMS)); |
+ } |
+ |
+ std::string notification_id = kNotificationId + std::to_string(message_id_); |
tdanderson
2017/01/26 22:19:06
Looks like you don't need this as a named local va
yiyix
2017/02/02 20:43:56
I want to keep it as a class variable so other res
tdanderson
2017/02/07 00:15:45
I meant that you don't need |notification_id| as a
yiyix
2017/02/07 22:03:21
Done.
|
+ LOG(ERROR) << notification_id; |
tdanderson
2017/01/26 22:19:06
Left over from debugging?
yiyix
2017/02/02 20:43:56
sorry, i missed this line.
tdanderson
2017/02/07 00:15:45
Acknowledged.
|
+ notification.reset(new message_center::Notification( |
+ message_center::NOTIFICATION_TYPE_SIMPLE, notification_id, |
+ base::ASCIIToUTF16(message_number), base::ASCIIToUTF16(message_text), |
+ *image, base::string16(), GURL(), |
+ message_center::NotifierId(message_center::NotifierId::APPLICATION, |
+ system_notifier::kNotifierSms), |
+ message_center::RichNotificationData(), nullptr)); |
tdanderson
2017/01/26 22:19:06
Has this CL received approval from UX in terms of
yiyix
2017/02/02 20:43:56
Nope, i only talked with sebastien on hangout. how
tdanderson
2017/02/07 00:15:45
Approval from Sebastien is enough in this case, th
yiyix
2017/02/07 22:03:21
I will ask him to approve it.
|
+ message_center::MessageCenter::Get()->AddNotification( |
+ std::move(notification)); |
+} |
+ |
+} // namespace ash |