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 <algorithm> |
| 8 #include <deque> |
7 #include <string> | 9 #include <string> |
| 10 #include <vector> |
8 | 11 |
9 #include "base/bind.h" | 12 #include "base/bind.h" |
10 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
11 #include "chromeos/dbus/flimflam_device_client.h" | 14 #include "chromeos/dbus/flimflam_device_client.h" |
12 #include "chromeos/dbus/flimflam_manager_client.h" | 15 #include "chromeos/dbus/flimflam_manager_client.h" |
13 #include "chromeos/dbus/gsm_sms_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" |
14 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
15 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
16 | 21 |
17 // Not exposed/exported. | 22 // Not exposed/exported. |
18 namespace { | 23 namespace { |
19 const char kSmscKey[] = "smsc"; | 24 const char kSmscKey[] = "smsc"; |
20 const char kValidityKey[] = "validity"; | 25 const char kValidityKey[] = "validity"; |
21 const char kClassKey[] = "class"; | 26 const char kClassKey[] = "class"; |
22 const char kIndexKey[] = "index"; | 27 const char kIndexKey[] = "index"; |
| 28 |
| 29 // Keys from ModemManager1 |
| 30 const char kModemManager1NumberKey[] = "Number"; |
| 31 const char kModemManager1TextKey[] = "Text"; |
| 32 const char kModemManager1TimestampKey[] = "Timestamp"; |
23 } // namespace | 33 } // namespace |
24 | 34 |
25 namespace chromeos { | 35 namespace chromeos { |
26 | 36 |
27 // static | 37 // static |
28 const char NetworkSmsHandler::kNumberKey[] = "number"; | 38 const char NetworkSmsHandler::kNumberKey[] = "number"; |
29 const char NetworkSmsHandler::kTextKey[] = "text"; | 39 const char NetworkSmsHandler::kTextKey[] = "text"; |
30 const char NetworkSmsHandler::kTimestampKey[] = "timestamp"; | 40 const char NetworkSmsHandler::kTimestampKey[] = "timestamp"; |
31 | 41 |
32 class NetworkSmsHandler::NetworkSmsDeviceHandler { | 42 class NetworkSmsHandler::NetworkSmsDeviceHandler { |
33 public: | 43 public: |
34 NetworkSmsDeviceHandler(NetworkSmsHandler* host, | 44 NetworkSmsDeviceHandler() {} |
35 std::string dbus_connection, | 45 virtual ~NetworkSmsDeviceHandler() {} |
36 dbus::ObjectPath object_path); | 46 |
| 47 virtual void RequestUpdate() = 0; |
| 48 }; |
| 49 |
| 50 class NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler |
| 51 : public NetworkSmsHandler::NetworkSmsDeviceHandler { |
| 52 public: |
| 53 ModemManagerNetworkSmsDeviceHandler(NetworkSmsHandler* host, |
| 54 std::string dbus_connection, |
| 55 dbus::ObjectPath object_path); |
37 | 56 |
38 void RequestUpdate(); | 57 void RequestUpdate(); |
39 | 58 |
40 private: | 59 private: |
41 void ListCallback(const base::ListValue& message_list); | 60 void ListCallback(const base::ListValue& message_list); |
42 void SmsReceivedCallback(uint32 index, bool complete); | 61 void SmsReceivedCallback(uint32 index, bool complete); |
43 void GetCallback(uint32 index, const base::DictionaryValue& dictionary); | 62 void GetCallback(uint32 index, const base::DictionaryValue& dictionary); |
44 void DeleteMessages(); | 63 void DeleteMessages(); |
45 void NotifyMessageReceived(const base::DictionaryValue& dictionary); | 64 void NotifyMessageReceived(const base::DictionaryValue& dictionary); |
46 | 65 |
47 NetworkSmsHandler* host_; | 66 NetworkSmsHandler* host_; |
48 std::string dbus_connection_; | 67 std::string dbus_connection_; |
49 dbus::ObjectPath object_path_; | 68 dbus::ObjectPath object_path_; |
50 bool deleting_messages_; | 69 bool deleting_messages_; |
51 base::WeakPtrFactory<NetworkSmsDeviceHandler> weak_ptr_factory_; | 70 base::WeakPtrFactory<ModemManagerNetworkSmsDeviceHandler> weak_ptr_factory_; |
52 std::vector<uint32> delete_queue_; | 71 std::vector<uint32> delete_queue_; |
53 | 72 |
54 DISALLOW_COPY_AND_ASSIGN(NetworkSmsDeviceHandler); | 73 DISALLOW_COPY_AND_ASSIGN(ModemManagerNetworkSmsDeviceHandler); |
55 }; | 74 }; |
56 | 75 |
57 NetworkSmsHandler::NetworkSmsDeviceHandler::NetworkSmsDeviceHandler( | 76 NetworkSmsHandler:: |
| 77 ModemManagerNetworkSmsDeviceHandler::ModemManagerNetworkSmsDeviceHandler( |
58 NetworkSmsHandler* host, | 78 NetworkSmsHandler* host, |
59 std::string dbus_connection, | 79 std::string dbus_connection, |
60 dbus::ObjectPath object_path) | 80 dbus::ObjectPath object_path) |
61 : host_(host), | 81 : host_(host), |
62 dbus_connection_(dbus_connection), | 82 dbus_connection_(dbus_connection), |
63 object_path_(object_path), | 83 object_path_(object_path), |
64 deleting_messages_(false), | 84 deleting_messages_(false), |
65 weak_ptr_factory_(this) { | 85 weak_ptr_factory_(this) { |
66 // Set the handler for received Sms messaages. | 86 // Set the handler for received Sms messaages. |
67 DBusThreadManager::Get()->GetGsmSMSClient()->SetSmsReceivedHandler( | 87 DBusThreadManager::Get()->GetGsmSMSClient()->SetSmsReceivedHandler( |
68 dbus_connection_, object_path_, | 88 dbus_connection_, object_path_, |
69 base::Bind(&NetworkSmsDeviceHandler::SmsReceivedCallback, | 89 base::Bind(&ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback, |
70 weak_ptr_factory_.GetWeakPtr())); | 90 weak_ptr_factory_.GetWeakPtr())); |
71 | 91 |
72 // List the existing messages. | 92 // List the existing messages. |
73 DBusThreadManager::Get()->GetGsmSMSClient()->List( | 93 DBusThreadManager::Get()->GetGsmSMSClient()->List( |
74 dbus_connection_, object_path_, | 94 dbus_connection_, object_path_, |
75 base::Bind(&NetworkSmsDeviceHandler::ListCallback, | 95 base::Bind(&NetworkSmsHandler:: |
| 96 ModemManagerNetworkSmsDeviceHandler::ListCallback, |
76 weak_ptr_factory_.GetWeakPtr())); | 97 weak_ptr_factory_.GetWeakPtr())); |
77 } | 98 } |
78 | 99 |
79 void NetworkSmsHandler::NetworkSmsDeviceHandler::RequestUpdate() { | 100 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::RequestUpdate() { |
80 DBusThreadManager::Get()->GetGsmSMSClient()->RequestUpdate( | 101 DBusThreadManager::Get()->GetGsmSMSClient()->RequestUpdate( |
81 dbus_connection_, object_path_); | 102 dbus_connection_, object_path_); |
82 } | 103 } |
83 | 104 |
84 void NetworkSmsHandler::NetworkSmsDeviceHandler::ListCallback( | 105 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::ListCallback( |
85 const base::ListValue& message_list) { | 106 const base::ListValue& message_list) { |
86 // This receives all messages, so clear any pending deletes. | 107 // This receives all messages, so clear any pending deletes. |
87 delete_queue_.clear(); | 108 delete_queue_.clear(); |
88 for (base::ListValue::const_iterator iter = message_list.begin(); | 109 for (base::ListValue::const_iterator iter = message_list.begin(); |
89 iter != message_list.end(); ++iter) { | 110 iter != message_list.end(); ++iter) { |
90 base::DictionaryValue* message = NULL; | 111 base::DictionaryValue* message = NULL; |
91 if (!(*iter)->GetAsDictionary(&message)) | 112 if (!(*iter)->GetAsDictionary(&message)) |
92 continue; | 113 continue; |
93 NotifyMessageReceived(*message); | 114 NotifyMessageReceived(*message); |
94 double index = 0; | 115 double index = 0; |
95 if (message->GetDoubleWithoutPathExpansion(kIndexKey, &index)) | 116 if (message->GetDoubleWithoutPathExpansion(kIndexKey, &index)) |
96 delete_queue_.push_back(static_cast<uint32>(index)); | 117 delete_queue_.push_back(static_cast<uint32>(index)); |
97 } | 118 } |
98 DeleteMessages(); | 119 DeleteMessages(); |
99 } | 120 } |
100 | 121 |
101 // Messages must be deleted one at a time, since we can not gaurantee the order | 122 // Messages must be deleted one at a time, since we can not guarantee |
102 // the deletion will be executed in. Delete messages from the back of the list | 123 // the order the deletion will be executed in. Delete messages from |
103 // so that the indices are valid. | 124 // the back of the list so that the indices are valid. |
104 void NetworkSmsHandler::NetworkSmsDeviceHandler::DeleteMessages() { | 125 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::DeleteMessages() { |
105 if (delete_queue_.empty()) { | 126 if (delete_queue_.empty()) { |
106 deleting_messages_ = false; | 127 deleting_messages_ = false; |
107 return; | 128 return; |
108 } | 129 } |
109 deleting_messages_ = true; | 130 deleting_messages_ = true; |
110 uint32 index = delete_queue_.back(); | 131 uint32 index = delete_queue_.back(); |
111 delete_queue_.pop_back(); | 132 delete_queue_.pop_back(); |
112 DBusThreadManager::Get()->GetGsmSMSClient()->Delete( | 133 DBusThreadManager::Get()->GetGsmSMSClient()->Delete( |
113 dbus_connection_, object_path_, index, | 134 dbus_connection_, object_path_, index, |
114 base::Bind(&NetworkSmsDeviceHandler::DeleteMessages, | 135 base::Bind(&NetworkSmsHandler:: |
| 136 ModemManagerNetworkSmsDeviceHandler::DeleteMessages, |
115 weak_ptr_factory_.GetWeakPtr())); | 137 weak_ptr_factory_.GetWeakPtr())); |
116 } | 138 } |
117 | 139 |
118 void NetworkSmsHandler::NetworkSmsDeviceHandler::SmsReceivedCallback( | 140 void NetworkSmsHandler:: |
| 141 ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback( |
119 uint32 index, | 142 uint32 index, |
120 bool complete) { | 143 bool complete) { |
121 // Only handle complete messages. | 144 // Only handle complete messages. |
122 if (!complete) | 145 if (!complete) |
123 return; | 146 return; |
124 DBusThreadManager::Get()->GetGsmSMSClient()->Get( | 147 DBusThreadManager::Get()->GetGsmSMSClient()->Get( |
125 dbus_connection_, object_path_, index, | 148 dbus_connection_, object_path_, index, |
126 base::Bind(&NetworkSmsDeviceHandler::GetCallback, | 149 base::Bind(&NetworkSmsHandler:: |
| 150 ModemManagerNetworkSmsDeviceHandler::GetCallback, |
127 weak_ptr_factory_.GetWeakPtr(), index)); | 151 weak_ptr_factory_.GetWeakPtr(), index)); |
128 } | 152 } |
129 | 153 |
130 void NetworkSmsHandler::NetworkSmsDeviceHandler::GetCallback( | 154 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::GetCallback( |
131 uint32 index, | 155 uint32 index, |
132 const base::DictionaryValue& dictionary) { | 156 const base::DictionaryValue& dictionary) { |
133 NotifyMessageReceived(dictionary); | 157 NotifyMessageReceived(dictionary); |
134 delete_queue_.push_back(index); | 158 delete_queue_.push_back(index); |
135 if (!deleting_messages_) | 159 if (!deleting_messages_) |
136 DeleteMessages(); | 160 DeleteMessages(); |
137 } | 161 } |
138 | 162 |
139 void NetworkSmsHandler::NetworkSmsDeviceHandler::NotifyMessageReceived( | 163 void NetworkSmsHandler:: |
| 164 ModemManagerNetworkSmsDeviceHandler::NotifyMessageReceived( |
140 const base::DictionaryValue& dictionary) { | 165 const base::DictionaryValue& dictionary) { |
| 166 // The keys of the ModemManager.Modem.Gsm.SMS interface match the |
| 167 // exported keys, so the dictionary used as a notification argument |
| 168 // unchanged. |
141 host_->NotifyMessageReceived(dictionary); | 169 host_->NotifyMessageReceived(dictionary); |
142 } | 170 } |
143 | 171 |
| 172 class NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler |
| 173 : public NetworkSmsHandler::NetworkSmsDeviceHandler { |
| 174 public: |
| 175 ModemManager1NetworkSmsDeviceHandler(NetworkSmsHandler* host, |
| 176 std::string dbus_connection, |
| 177 dbus::ObjectPath object_path); |
| 178 |
| 179 void RequestUpdate(); |
| 180 |
| 181 private: |
| 182 void ListCallback(const std::vector<dbus::ObjectPath>& paths); |
| 183 void SmsReceivedCallback(const dbus::ObjectPath& path, bool complete); |
| 184 void GetCallback(const base::DictionaryValue& dictionary); |
| 185 void DeleteMessages(); |
| 186 void GetMessages(); |
| 187 void NotifyMessageReceived(const base::DictionaryValue& dictionary); |
| 188 |
| 189 NetworkSmsHandler* host_; |
| 190 std::string dbus_connection_; |
| 191 dbus::ObjectPath object_path_; |
| 192 bool deleting_messages_; |
| 193 bool retrieving_messages_; |
| 194 base::WeakPtrFactory<ModemManager1NetworkSmsDeviceHandler> weak_ptr_factory_; |
| 195 std::vector<dbus::ObjectPath> delete_queue_; |
| 196 std::deque<dbus::ObjectPath> retrieval_queue_; |
| 197 |
| 198 DISALLOW_COPY_AND_ASSIGN(ModemManager1NetworkSmsDeviceHandler); |
| 199 }; |
| 200 |
| 201 NetworkSmsHandler:: |
| 202 ModemManager1NetworkSmsDeviceHandler::ModemManager1NetworkSmsDeviceHandler( |
| 203 NetworkSmsHandler* host, |
| 204 std::string dbus_connection, |
| 205 dbus::ObjectPath object_path) |
| 206 : host_(host), |
| 207 dbus_connection_(dbus_connection), |
| 208 object_path_(object_path), |
| 209 deleting_messages_(false), |
| 210 retrieving_messages_(false), |
| 211 weak_ptr_factory_(this) { |
| 212 // Set the handler for received Sms messaages. |
| 213 DBusThreadManager::Get()->GetModemMessagingClient()->SetSmsReceivedHandler( |
| 214 dbus_connection_, object_path_, |
| 215 base::Bind( |
| 216 &NetworkSmsHandler:: |
| 217 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback, |
| 218 weak_ptr_factory_.GetWeakPtr())); |
| 219 |
| 220 // List the existing messages. |
| 221 DBusThreadManager::Get()->GetModemMessagingClient()->List( |
| 222 dbus_connection_, object_path_, |
| 223 base::Bind(&NetworkSmsHandler:: |
| 224 ModemManager1NetworkSmsDeviceHandler::ListCallback, |
| 225 weak_ptr_factory_.GetWeakPtr())); |
| 226 } |
| 227 |
| 228 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::RequestUpdate() { |
| 229 // Calling List using the service "AddSMS" causes the stub |
| 230 // implementation to deliver new sms messages. |
| 231 DBusThreadManager::Get()->GetModemMessagingClient()->List( |
| 232 std::string("AddSMS"), dbus::ObjectPath("/"), |
| 233 base::Bind(&NetworkSmsHandler:: |
| 234 ModemManager1NetworkSmsDeviceHandler::ListCallback, |
| 235 weak_ptr_factory_.GetWeakPtr())); |
| 236 } |
| 237 |
| 238 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::ListCallback( |
| 239 const std::vector<dbus::ObjectPath>& paths) { |
| 240 // This receives all messages, so clear any pending gets and deletes. |
| 241 retrieval_queue_.clear(); |
| 242 delete_queue_.clear(); |
| 243 |
| 244 retrieval_queue_.resize(paths.size()); |
| 245 std::copy(paths.begin(), paths.end(), retrieval_queue_.begin()); |
| 246 if (!retrieving_messages_) |
| 247 GetMessages(); |
| 248 } |
| 249 |
| 250 // Messages must be deleted one at a time, since we can not guarantee |
| 251 // the order the deletion will be executed in. Delete messages from |
| 252 // the back of the list so that the indices are valid. |
| 253 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::DeleteMessages() { |
| 254 if (delete_queue_.empty()) { |
| 255 deleting_messages_ = false; |
| 256 return; |
| 257 } |
| 258 deleting_messages_ = true; |
| 259 dbus::ObjectPath sms_path = delete_queue_.back(); |
| 260 delete_queue_.pop_back(); |
| 261 DBusThreadManager::Get()->GetModemMessagingClient()->Delete( |
| 262 dbus_connection_, object_path_, sms_path, |
| 263 base::Bind(&NetworkSmsHandler:: |
| 264 ModemManager1NetworkSmsDeviceHandler::DeleteMessages, |
| 265 weak_ptr_factory_.GetWeakPtr())); |
| 266 } |
| 267 |
| 268 // Messages must be fetched one at a time, so that we do not queue too |
| 269 // many requests to a single threaded server. |
| 270 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetMessages() { |
| 271 if (retrieval_queue_.empty()) { |
| 272 retrieving_messages_ = false; |
| 273 if (!deleting_messages_) |
| 274 DeleteMessages(); |
| 275 return; |
| 276 } |
| 277 retrieving_messages_ = true; |
| 278 dbus::ObjectPath sms_path = retrieval_queue_.front(); |
| 279 retrieval_queue_.pop_front(); |
| 280 DBusThreadManager::Get()->GetSMSClient()->GetAll( |
| 281 dbus_connection_, sms_path, |
| 282 base::Bind(&NetworkSmsHandler:: |
| 283 ModemManager1NetworkSmsDeviceHandler::GetCallback, |
| 284 weak_ptr_factory_.GetWeakPtr())); |
| 285 delete_queue_.push_back(sms_path); |
| 286 } |
| 287 |
| 288 void NetworkSmsHandler:: |
| 289 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback( |
| 290 const dbus::ObjectPath& sms_path, |
| 291 bool complete) { |
| 292 // Only handle complete messages. |
| 293 if (!complete) |
| 294 return; |
| 295 retrieval_queue_.push_back(sms_path); |
| 296 if (!retrieving_messages_) |
| 297 GetMessages(); |
| 298 } |
| 299 |
| 300 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetCallback( |
| 301 const base::DictionaryValue& dictionary) { |
| 302 NotifyMessageReceived(dictionary); |
| 303 GetMessages(); |
| 304 } |
| 305 |
| 306 void NetworkSmsHandler:: |
| 307 ModemManager1NetworkSmsDeviceHandler::NotifyMessageReceived( |
| 308 const base::DictionaryValue& dictionary) { |
| 309 // The keys of the ModemManager1.SMS interface do not match the |
| 310 // exported keys, so a new dictionary is created with the expected |
| 311 // key namaes. |
| 312 base::DictionaryValue new_dictionary; |
| 313 std::string text, number, timestamp; |
| 314 if (dictionary.GetStringWithoutPathExpansion(kModemManager1NumberKey, |
| 315 &number)) |
| 316 new_dictionary.SetString(kNumberKey, number); |
| 317 if (dictionary.GetStringWithoutPathExpansion(kModemManager1TextKey, &text)) |
| 318 new_dictionary.SetString(kTextKey, text); |
| 319 // TODO(jglasgow): consider normalizing timestamp. |
| 320 if (dictionary.GetStringWithoutPathExpansion(kModemManager1TimestampKey, |
| 321 ×tamp)) |
| 322 new_dictionary.SetString(kTimestampKey, timestamp); |
| 323 host_->NotifyMessageReceived(new_dictionary); |
| 324 } |
| 325 |
144 /////////////////////////////////////////////////////////////////////////////// | 326 /////////////////////////////////////////////////////////////////////////////// |
145 // NetworkSmsHandler | 327 // NetworkSmsHandler |
146 | 328 |
147 NetworkSmsHandler::NetworkSmsHandler() | 329 NetworkSmsHandler::NetworkSmsHandler() |
148 : weak_ptr_factory_(this) { | 330 : weak_ptr_factory_(this) { |
149 } | 331 } |
150 | 332 |
151 NetworkSmsHandler::~NetworkSmsHandler() { | 333 NetworkSmsHandler::~NetworkSmsHandler() { |
152 } | 334 } |
153 | 335 |
(...skipping 27 matching lines...) Expand all Loading... |
181 void NetworkSmsHandler::ManagerPropertiesCallback( | 363 void NetworkSmsHandler::ManagerPropertiesCallback( |
182 DBusMethodCallStatus call_status, | 364 DBusMethodCallStatus call_status, |
183 const base::DictionaryValue& properties) { | 365 const base::DictionaryValue& properties) { |
184 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 366 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
185 LOG(ERROR) << "NetworkSmsHandler: Failed to get manager properties."; | 367 LOG(ERROR) << "NetworkSmsHandler: Failed to get manager properties."; |
186 return; | 368 return; |
187 } | 369 } |
188 base::Value* value; | 370 base::Value* value; |
189 if (!properties.GetWithoutPathExpansion(flimflam::kDevicesProperty, &value) || | 371 if (!properties.GetWithoutPathExpansion(flimflam::kDevicesProperty, &value) || |
190 value->GetType() != base::Value::TYPE_LIST) { | 372 value->GetType() != base::Value::TYPE_LIST) { |
191 LOG(ERROR) << "NetworkSmsDeviceHandler: No list value for: " | 373 LOG(ERROR) << "NetworkSmsHandler: No list value for: " |
192 << flimflam::kDevicesProperty; | 374 << flimflam::kDevicesProperty; |
193 return; | 375 return; |
194 } | 376 } |
195 const base::ListValue* devices = static_cast<const base::ListValue*>(value); | 377 const base::ListValue* devices = static_cast<const base::ListValue*>(value); |
196 for (base::ListValue::const_iterator iter = devices->begin(); | 378 for (base::ListValue::const_iterator iter = devices->begin(); |
197 iter != devices->end(); ++iter) { | 379 iter != devices->end(); ++iter) { |
198 std::string device_path; | 380 std::string device_path; |
199 (*iter)->GetAsString(&device_path); | 381 (*iter)->GetAsString(&device_path); |
200 if (!device_path.empty()) { | 382 if (!device_path.empty()) { |
201 // Request device properties. | 383 // Request device properties. |
202 DBusThreadManager::Get()->GetFlimflamDeviceClient()->GetProperties( | 384 DBusThreadManager::Get()->GetFlimflamDeviceClient()->GetProperties( |
203 dbus::ObjectPath(device_path), | 385 dbus::ObjectPath(device_path), |
204 base::Bind(&NetworkSmsHandler::DevicePropertiesCallback, | 386 base::Bind(&NetworkSmsHandler::DevicePropertiesCallback, |
205 weak_ptr_factory_.GetWeakPtr(), | 387 weak_ptr_factory_.GetWeakPtr(), |
206 device_path)); | 388 device_path)); |
207 } | 389 } |
208 } | 390 } |
209 } | 391 } |
210 | 392 |
211 void NetworkSmsHandler::DevicePropertiesCallback( | 393 void NetworkSmsHandler::DevicePropertiesCallback( |
212 const std::string& device_path, | 394 const std::string& device_path, |
213 DBusMethodCallStatus call_status, | 395 DBusMethodCallStatus call_status, |
214 const base::DictionaryValue& properties) { | 396 const base::DictionaryValue& properties) { |
215 if (call_status != DBUS_METHOD_CALL_SUCCESS) | 397 if (call_status != DBUS_METHOD_CALL_SUCCESS) |
216 return; | 398 return; |
217 | 399 |
218 std::string device_type; | 400 std::string device_type; |
219 if (!properties.GetStringWithoutPathExpansion( | 401 if (!properties.GetStringWithoutPathExpansion( |
220 flimflam::kTypeProperty, &device_type)) { | 402 flimflam::kTypeProperty, &device_type)) { |
221 LOG(ERROR) << "NetworkSmsDeviceHandler: No type for: " << device_path; | 403 LOG(ERROR) << "NetworkSmsHandler: No type for: " << device_path; |
222 return; | 404 return; |
223 } | 405 } |
224 if (device_type != flimflam::kTypeCellular) | 406 if (device_type != flimflam::kTypeCellular) |
225 return; | 407 return; |
226 | 408 |
227 std::string dbus_connection; | 409 std::string dbus_connection; |
228 if (!properties.GetStringWithoutPathExpansion( | 410 if (!properties.GetStringWithoutPathExpansion( |
229 flimflam::kDBusConnectionProperty, &dbus_connection)) { | 411 flimflam::kDBusConnectionProperty, &dbus_connection)) { |
230 LOG(ERROR) << "Device has no DBusConnection Property: " << device_path; | 412 LOG(ERROR) << "Device has no DBusConnection Property: " << device_path; |
231 return; | 413 return; |
232 } | 414 } |
233 | 415 |
234 std::string object_path_string; | 416 std::string object_path_string; |
235 if (!properties.GetStringWithoutPathExpansion( | 417 if (!properties.GetStringWithoutPathExpansion( |
236 flimflam::kDBusObjectProperty, &object_path_string)) { | 418 flimflam::kDBusObjectProperty, &object_path_string)) { |
237 LOG(ERROR) << "Device has no DBusObject Property: " << device_path; | 419 LOG(ERROR) << "Device has no DBusObject Property: " << device_path; |
238 return; | 420 return; |
239 } | 421 } |
240 dbus::ObjectPath object_path(object_path_string); | 422 dbus::ObjectPath object_path(object_path_string); |
241 device_handlers_.push_back( | 423 if (object_path_string.compare( |
242 new NetworkSmsDeviceHandler(this, dbus_connection, object_path)); | 424 0, sizeof(modemmanager::kModemManager1ServicePath) - 1, |
| 425 modemmanager::kModemManager1ServicePath) == 0) { |
| 426 device_handlers_.push_back( |
| 427 new ModemManager1NetworkSmsDeviceHandler( |
| 428 this, dbus_connection, object_path)); |
| 429 } else { |
| 430 device_handlers_.push_back( |
| 431 new ModemManagerNetworkSmsDeviceHandler( |
| 432 this, dbus_connection, object_path)); |
| 433 } |
243 } | 434 } |
244 | 435 |
245 | 436 |
246 } // namespace chromeos | 437 } // namespace chromeos |
OLD | NEW |