OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chromeos/network/network_sms_handler.h" | 5 #include "chromeos/network/network_sms_handler.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <algorithm> | 10 #include <algorithm> |
8 #include <deque> | 11 #include <deque> |
9 #include <vector> | 12 #include <vector> |
10 | 13 |
11 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/macros.h" |
12 #include "base/values.h" | 16 #include "base/values.h" |
13 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
| 18 #include "chromeos/dbus/gsm_sms_client.h" |
| 19 #include "chromeos/dbus/modem_messaging_client.h" |
14 #include "chromeos/dbus/shill_device_client.h" | 20 #include "chromeos/dbus/shill_device_client.h" |
15 #include "chromeos/dbus/shill_manager_client.h" | 21 #include "chromeos/dbus/shill_manager_client.h" |
16 #include "chromeos/dbus/gsm_sms_client.h" | |
17 #include "chromeos/dbus/modem_messaging_client.h" | |
18 #include "chromeos/dbus/sms_client.h" | 22 #include "chromeos/dbus/sms_client.h" |
19 #include "dbus/object_path.h" | 23 #include "dbus/object_path.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 24 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 | 25 |
22 namespace { | 26 namespace { |
23 | 27 |
24 // Not exposed/exported: | 28 // Not exposed/exported: |
25 const char kIndexKey[] = "index"; | 29 const char kIndexKey[] = "index"; |
26 | 30 |
27 // Keys from ModemManager1 | 31 // Keys from ModemManager1 |
(...skipping 25 matching lines...) Expand all Loading... |
53 : public NetworkSmsHandler::NetworkSmsDeviceHandler { | 57 : public NetworkSmsHandler::NetworkSmsDeviceHandler { |
54 public: | 58 public: |
55 ModemManagerNetworkSmsDeviceHandler(NetworkSmsHandler* host, | 59 ModemManagerNetworkSmsDeviceHandler(NetworkSmsHandler* host, |
56 const std::string& service_name, | 60 const std::string& service_name, |
57 const dbus::ObjectPath& object_path); | 61 const dbus::ObjectPath& object_path); |
58 | 62 |
59 void RequestUpdate() override; | 63 void RequestUpdate() override; |
60 | 64 |
61 private: | 65 private: |
62 void ListCallback(const base::ListValue& message_list); | 66 void ListCallback(const base::ListValue& message_list); |
63 void SmsReceivedCallback(uint32 index, bool complete); | 67 void SmsReceivedCallback(uint32_t index, bool complete); |
64 void GetCallback(uint32 index, const base::DictionaryValue& dictionary); | 68 void GetCallback(uint32_t index, const base::DictionaryValue& dictionary); |
65 void DeleteMessages(); | 69 void DeleteMessages(); |
66 void MessageReceived(const base::DictionaryValue& dictionary); | 70 void MessageReceived(const base::DictionaryValue& dictionary); |
67 | 71 |
68 NetworkSmsHandler* host_; | 72 NetworkSmsHandler* host_; |
69 std::string service_name_; | 73 std::string service_name_; |
70 dbus::ObjectPath object_path_; | 74 dbus::ObjectPath object_path_; |
71 bool deleting_messages_; | 75 bool deleting_messages_; |
72 std::vector<uint32> delete_queue_; | 76 std::vector<uint32_t> delete_queue_; |
73 base::WeakPtrFactory<ModemManagerNetworkSmsDeviceHandler> weak_ptr_factory_; | 77 base::WeakPtrFactory<ModemManagerNetworkSmsDeviceHandler> weak_ptr_factory_; |
74 | 78 |
75 DISALLOW_COPY_AND_ASSIGN(ModemManagerNetworkSmsDeviceHandler); | 79 DISALLOW_COPY_AND_ASSIGN(ModemManagerNetworkSmsDeviceHandler); |
76 }; | 80 }; |
77 | 81 |
78 NetworkSmsHandler:: | 82 NetworkSmsHandler:: |
79 ModemManagerNetworkSmsDeviceHandler::ModemManagerNetworkSmsDeviceHandler( | 83 ModemManagerNetworkSmsDeviceHandler::ModemManagerNetworkSmsDeviceHandler( |
80 NetworkSmsHandler* host, | 84 NetworkSmsHandler* host, |
81 const std::string& service_name, | 85 const std::string& service_name, |
82 const dbus::ObjectPath& object_path) | 86 const dbus::ObjectPath& object_path) |
(...skipping 26 matching lines...) Expand all Loading... |
109 // This receives all messages, so clear any pending deletes. | 113 // This receives all messages, so clear any pending deletes. |
110 delete_queue_.clear(); | 114 delete_queue_.clear(); |
111 for (base::ListValue::const_iterator iter = message_list.begin(); | 115 for (base::ListValue::const_iterator iter = message_list.begin(); |
112 iter != message_list.end(); ++iter) { | 116 iter != message_list.end(); ++iter) { |
113 base::DictionaryValue* message = NULL; | 117 base::DictionaryValue* message = NULL; |
114 if (!(*iter)->GetAsDictionary(&message)) | 118 if (!(*iter)->GetAsDictionary(&message)) |
115 continue; | 119 continue; |
116 MessageReceived(*message); | 120 MessageReceived(*message); |
117 double index = 0; | 121 double index = 0; |
118 if (message->GetDoubleWithoutPathExpansion(kIndexKey, &index)) | 122 if (message->GetDoubleWithoutPathExpansion(kIndexKey, &index)) |
119 delete_queue_.push_back(static_cast<uint32>(index)); | 123 delete_queue_.push_back(static_cast<uint32_t>(index)); |
120 } | 124 } |
121 DeleteMessages(); | 125 DeleteMessages(); |
122 } | 126 } |
123 | 127 |
124 // Messages must be deleted one at a time, since we can not guarantee | 128 // Messages must be deleted one at a time, since we can not guarantee |
125 // the order the deletion will be executed in. Delete messages from | 129 // the order the deletion will be executed in. Delete messages from |
126 // the back of the list so that the indices are valid. | 130 // the back of the list so that the indices are valid. |
127 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::DeleteMessages() { | 131 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::DeleteMessages() { |
128 if (delete_queue_.empty()) { | 132 if (delete_queue_.empty()) { |
129 deleting_messages_ = false; | 133 deleting_messages_ = false; |
130 return; | 134 return; |
131 } | 135 } |
132 deleting_messages_ = true; | 136 deleting_messages_ = true; |
133 uint32 index = delete_queue_.back(); | 137 uint32_t index = delete_queue_.back(); |
134 delete_queue_.pop_back(); | 138 delete_queue_.pop_back(); |
135 DBusThreadManager::Get()->GetGsmSMSClient()->Delete( | 139 DBusThreadManager::Get()->GetGsmSMSClient()->Delete( |
136 service_name_, object_path_, index, | 140 service_name_, object_path_, index, |
137 base::Bind(&NetworkSmsHandler:: | 141 base::Bind(&NetworkSmsHandler:: |
138 ModemManagerNetworkSmsDeviceHandler::DeleteMessages, | 142 ModemManagerNetworkSmsDeviceHandler::DeleteMessages, |
139 weak_ptr_factory_.GetWeakPtr())); | 143 weak_ptr_factory_.GetWeakPtr())); |
140 } | 144 } |
141 | 145 |
142 void NetworkSmsHandler:: | 146 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler:: |
143 ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback( | 147 SmsReceivedCallback(uint32_t index, bool complete) { |
144 uint32 index, | |
145 bool complete) { | |
146 // Only handle complete messages. | 148 // Only handle complete messages. |
147 if (!complete) | 149 if (!complete) |
148 return; | 150 return; |
149 DBusThreadManager::Get()->GetGsmSMSClient()->Get( | 151 DBusThreadManager::Get()->GetGsmSMSClient()->Get( |
150 service_name_, object_path_, index, | 152 service_name_, object_path_, index, |
151 base::Bind(&NetworkSmsHandler:: | 153 base::Bind(&NetworkSmsHandler:: |
152 ModemManagerNetworkSmsDeviceHandler::GetCallback, | 154 ModemManagerNetworkSmsDeviceHandler::GetCallback, |
153 weak_ptr_factory_.GetWeakPtr(), index)); | 155 weak_ptr_factory_.GetWeakPtr(), index)); |
154 } | 156 } |
155 | 157 |
156 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::GetCallback( | 158 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::GetCallback( |
157 uint32 index, | 159 uint32_t index, |
158 const base::DictionaryValue& dictionary) { | 160 const base::DictionaryValue& dictionary) { |
159 MessageReceived(dictionary); | 161 MessageReceived(dictionary); |
160 delete_queue_.push_back(index); | 162 delete_queue_.push_back(index); |
161 if (!deleting_messages_) | 163 if (!deleting_messages_) |
162 DeleteMessages(); | 164 DeleteMessages(); |
163 } | 165 } |
164 | 166 |
165 void NetworkSmsHandler:: | 167 void NetworkSmsHandler:: |
166 ModemManagerNetworkSmsDeviceHandler::MessageReceived( | 168 ModemManagerNetworkSmsDeviceHandler::MessageReceived( |
167 const base::DictionaryValue& dictionary) { | 169 const base::DictionaryValue& dictionary) { |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 new ModemManager1NetworkSmsDeviceHandler( | 477 new ModemManager1NetworkSmsDeviceHandler( |
476 this, service_name, object_path)); | 478 this, service_name, object_path)); |
477 } else { | 479 } else { |
478 device_handlers_.push_back( | 480 device_handlers_.push_back( |
479 new ModemManagerNetworkSmsDeviceHandler( | 481 new ModemManagerNetworkSmsDeviceHandler( |
480 this, service_name, object_path)); | 482 this, service_name, object_path)); |
481 } | 483 } |
482 } | 484 } |
483 | 485 |
484 } // namespace chromeos | 486 } // namespace chromeos |
OLD | NEW |