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

Side by Side Diff: ash/common/system/chromeos/network/sms_observer.cc

Issue 2583393002: Send notification to users upon receiving sms messages (Closed)
Patch Set: Created 3 years, 11 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // 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.
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
41 void SmsObserver::Shutdown() {
42 if (chromeos::NetworkHandler::IsInitialized()) {
43 chromeos::NetworkHandler::Get()->network_sms_handler()->RemoveObserver(
44 this);
45 }
46 }
47
48 void SmsObserver::MessageReceived(const base::DictionaryValue& message) {
49 std::string message_text;
50 if (!message.GetStringWithoutPathExpansion(
51 chromeos::NetworkSmsHandler::kTextKey, &message_text)) {
52 NET_LOG_ERROR("SMS message contains no content.", "");
53 return;
54 }
55 // TODO(armansito): A message might be due to a special "Message Waiting"
56 // state that the message is in. Once SMS handling moves to shill, such
57 // messages should be filtered there so that this check becomes unnecessary.
58 if (message_text.empty()) {
59 NET_LOG_DEBUG("SMS has empty content text. Ignoring.", "");
60 return;
61 }
62 std::string message_number;
63 if (!message.GetStringWithoutPathExpansion(
64 chromeos::NetworkSmsHandler::kNumberKey, &message_number)) {
65 NET_LOG_DEBUG("SMS contains no number. Ignoring.", "");
66 return;
67 }
68
69 NET_LOG_DEBUG(
70 "Received SMS from: " + message_number + " with text: " + message_text,
71 "");
72 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
73 Update(&message, message_text, message_number);
74 }
75
76 void SmsObserver::Update(const base::DictionaryValue* message,
77 std::string message_text,
78 std::string message_number) {
79 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.
80 gfx::Image* image;
81 if (MaterialDesignController::UseMaterialDesignSystemIcons()) {
82 image = new gfx::Image(
83 CreateVectorIcon(kSystemMenuSmsIcon, kMenuIconSize, kMenuIconColor));
84 } 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 :)
85 image = new gfx::Image(
86 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
87 IDR_AURA_UBER_TRAY_SMS));
88 }
89
90 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.
91 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.
92 notification.reset(new message_center::Notification(
93 message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
94 base::ASCIIToUTF16(message_number), base::ASCIIToUTF16(message_text),
95 *image, base::string16(), GURL(),
96 message_center::NotifierId(message_center::NotifierId::APPLICATION,
97 system_notifier::kNotifierSms),
98 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.
99 message_center::MessageCenter::Get()->AddNotification(
100 std::move(notification));
101 }
102
103 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698