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

Side by Side Diff: chromeos/network/network_sms_handler.cc

Issue 136463004: Fix NetworkSMSHandler to use DBus service name instead of connection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « chromeos/dbus/fake_shill_device_client.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 NetworkSmsDeviceHandler() {} 47 NetworkSmsDeviceHandler() {}
48 virtual ~NetworkSmsDeviceHandler() {} 48 virtual ~NetworkSmsDeviceHandler() {}
49 49
50 virtual void RequestUpdate() = 0; 50 virtual void RequestUpdate() = 0;
51 }; 51 };
52 52
53 class NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler 53 class NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler
54 : public NetworkSmsHandler::NetworkSmsDeviceHandler { 54 : public NetworkSmsHandler::NetworkSmsDeviceHandler {
55 public: 55 public:
56 ModemManagerNetworkSmsDeviceHandler(NetworkSmsHandler* host, 56 ModemManagerNetworkSmsDeviceHandler(NetworkSmsHandler* host,
57 std::string dbus_connection, 57 const std::string& service_name,
58 dbus::ObjectPath object_path); 58 const dbus::ObjectPath& object_path);
59 59
60 virtual void RequestUpdate() OVERRIDE; 60 virtual void RequestUpdate() OVERRIDE;
61 61
62 private: 62 private:
63 void ListCallback(const base::ListValue& message_list); 63 void ListCallback(const base::ListValue& message_list);
64 void SmsReceivedCallback(uint32 index, bool complete); 64 void SmsReceivedCallback(uint32 index, bool complete);
65 void GetCallback(uint32 index, const base::DictionaryValue& dictionary); 65 void GetCallback(uint32 index, const base::DictionaryValue& dictionary);
66 void DeleteMessages(); 66 void DeleteMessages();
67 void MessageReceived(const base::DictionaryValue& dictionary); 67 void MessageReceived(const base::DictionaryValue& dictionary);
68 68
69 NetworkSmsHandler* host_; 69 NetworkSmsHandler* host_;
70 std::string dbus_connection_; 70 std::string service_name_;
71 dbus::ObjectPath object_path_; 71 dbus::ObjectPath object_path_;
72 bool deleting_messages_; 72 bool deleting_messages_;
73 base::WeakPtrFactory<ModemManagerNetworkSmsDeviceHandler> weak_ptr_factory_; 73 base::WeakPtrFactory<ModemManagerNetworkSmsDeviceHandler> weak_ptr_factory_;
74 std::vector<uint32> delete_queue_; 74 std::vector<uint32> delete_queue_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(ModemManagerNetworkSmsDeviceHandler); 76 DISALLOW_COPY_AND_ASSIGN(ModemManagerNetworkSmsDeviceHandler);
77 }; 77 };
78 78
79 NetworkSmsHandler:: 79 NetworkSmsHandler::
80 ModemManagerNetworkSmsDeviceHandler::ModemManagerNetworkSmsDeviceHandler( 80 ModemManagerNetworkSmsDeviceHandler::ModemManagerNetworkSmsDeviceHandler(
81 NetworkSmsHandler* host, 81 NetworkSmsHandler* host,
82 std::string dbus_connection, 82 const std::string& service_name,
83 dbus::ObjectPath object_path) 83 const dbus::ObjectPath& object_path)
84 : host_(host), 84 : host_(host),
85 dbus_connection_(dbus_connection), 85 service_name_(service_name),
86 object_path_(object_path), 86 object_path_(object_path),
87 deleting_messages_(false), 87 deleting_messages_(false),
88 weak_ptr_factory_(this) { 88 weak_ptr_factory_(this) {
89 // Set the handler for received Sms messaages. 89 // Set the handler for received Sms messaages.
90 DBusThreadManager::Get()->GetGsmSMSClient()->SetSmsReceivedHandler( 90 DBusThreadManager::Get()->GetGsmSMSClient()->SetSmsReceivedHandler(
91 dbus_connection_, object_path_, 91 service_name_, object_path_,
92 base::Bind(&ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback, 92 base::Bind(&ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback,
93 weak_ptr_factory_.GetWeakPtr())); 93 weak_ptr_factory_.GetWeakPtr()));
94 94
95 // List the existing messages. 95 // List the existing messages.
96 DBusThreadManager::Get()->GetGsmSMSClient()->List( 96 DBusThreadManager::Get()->GetGsmSMSClient()->List(
97 dbus_connection_, object_path_, 97 service_name_, object_path_,
98 base::Bind(&NetworkSmsHandler:: 98 base::Bind(&NetworkSmsHandler::
99 ModemManagerNetworkSmsDeviceHandler::ListCallback, 99 ModemManagerNetworkSmsDeviceHandler::ListCallback,
100 weak_ptr_factory_.GetWeakPtr())); 100 weak_ptr_factory_.GetWeakPtr()));
101 } 101 }
102 102
103 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::RequestUpdate() { 103 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::RequestUpdate() {
104 DBusThreadManager::Get()->GetGsmSMSClient()->RequestUpdate( 104 DBusThreadManager::Get()->GetGsmSMSClient()->RequestUpdate(
105 dbus_connection_, object_path_); 105 service_name_, object_path_);
106 } 106 }
107 107
108 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::ListCallback( 108 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::ListCallback(
109 const base::ListValue& message_list) { 109 const base::ListValue& message_list) {
110 // This receives all messages, so clear any pending deletes. 110 // This receives all messages, so clear any pending deletes.
111 delete_queue_.clear(); 111 delete_queue_.clear();
112 for (base::ListValue::const_iterator iter = message_list.begin(); 112 for (base::ListValue::const_iterator iter = message_list.begin();
113 iter != message_list.end(); ++iter) { 113 iter != message_list.end(); ++iter) {
114 base::DictionaryValue* message = NULL; 114 base::DictionaryValue* message = NULL;
115 if (!(*iter)->GetAsDictionary(&message)) 115 if (!(*iter)->GetAsDictionary(&message))
(...skipping 11 matching lines...) Expand all
127 // the back of the list so that the indices are valid. 127 // the back of the list so that the indices are valid.
128 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::DeleteMessages() { 128 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::DeleteMessages() {
129 if (delete_queue_.empty()) { 129 if (delete_queue_.empty()) {
130 deleting_messages_ = false; 130 deleting_messages_ = false;
131 return; 131 return;
132 } 132 }
133 deleting_messages_ = true; 133 deleting_messages_ = true;
134 uint32 index = delete_queue_.back(); 134 uint32 index = delete_queue_.back();
135 delete_queue_.pop_back(); 135 delete_queue_.pop_back();
136 DBusThreadManager::Get()->GetGsmSMSClient()->Delete( 136 DBusThreadManager::Get()->GetGsmSMSClient()->Delete(
137 dbus_connection_, object_path_, index, 137 service_name_, object_path_, index,
138 base::Bind(&NetworkSmsHandler:: 138 base::Bind(&NetworkSmsHandler::
139 ModemManagerNetworkSmsDeviceHandler::DeleteMessages, 139 ModemManagerNetworkSmsDeviceHandler::DeleteMessages,
140 weak_ptr_factory_.GetWeakPtr())); 140 weak_ptr_factory_.GetWeakPtr()));
141 } 141 }
142 142
143 void NetworkSmsHandler:: 143 void NetworkSmsHandler::
144 ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback( 144 ModemManagerNetworkSmsDeviceHandler::SmsReceivedCallback(
145 uint32 index, 145 uint32 index,
146 bool complete) { 146 bool complete) {
147 // Only handle complete messages. 147 // Only handle complete messages.
148 if (!complete) 148 if (!complete)
149 return; 149 return;
150 DBusThreadManager::Get()->GetGsmSMSClient()->Get( 150 DBusThreadManager::Get()->GetGsmSMSClient()->Get(
151 dbus_connection_, object_path_, index, 151 service_name_, object_path_, index,
152 base::Bind(&NetworkSmsHandler:: 152 base::Bind(&NetworkSmsHandler::
153 ModemManagerNetworkSmsDeviceHandler::GetCallback, 153 ModemManagerNetworkSmsDeviceHandler::GetCallback,
154 weak_ptr_factory_.GetWeakPtr(), index)); 154 weak_ptr_factory_.GetWeakPtr(), index));
155 } 155 }
156 156
157 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::GetCallback( 157 void NetworkSmsHandler::ModemManagerNetworkSmsDeviceHandler::GetCallback(
158 uint32 index, 158 uint32 index,
159 const base::DictionaryValue& dictionary) { 159 const base::DictionaryValue& dictionary) {
160 MessageReceived(dictionary); 160 MessageReceived(dictionary);
161 delete_queue_.push_back(index); 161 delete_queue_.push_back(index);
162 if (!deleting_messages_) 162 if (!deleting_messages_)
163 DeleteMessages(); 163 DeleteMessages();
164 } 164 }
165 165
166 void NetworkSmsHandler:: 166 void NetworkSmsHandler::
167 ModemManagerNetworkSmsDeviceHandler::MessageReceived( 167 ModemManagerNetworkSmsDeviceHandler::MessageReceived(
168 const base::DictionaryValue& dictionary) { 168 const base::DictionaryValue& dictionary) {
169 // The keys of the ModemManager.Modem.Gsm.SMS interface match the 169 // The keys of the ModemManager.Modem.Gsm.SMS interface match the
170 // exported keys, so the dictionary used as a notification argument 170 // exported keys, so the dictionary used as a notification argument
171 // unchanged. 171 // unchanged.
172 host_->MessageReceived(dictionary); 172 host_->MessageReceived(dictionary);
173 } 173 }
174 174
175 class NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler 175 class NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler
176 : public NetworkSmsHandler::NetworkSmsDeviceHandler { 176 : public NetworkSmsHandler::NetworkSmsDeviceHandler {
177 public: 177 public:
178 ModemManager1NetworkSmsDeviceHandler(NetworkSmsHandler* host, 178 ModemManager1NetworkSmsDeviceHandler(NetworkSmsHandler* host,
179 std::string dbus_connection, 179 const std::string& service_name,
180 dbus::ObjectPath object_path); 180 const dbus::ObjectPath& object_path);
181 181
182 virtual void RequestUpdate() OVERRIDE; 182 virtual void RequestUpdate() OVERRIDE;
183 183
184 private: 184 private:
185 void ListCallback(const std::vector<dbus::ObjectPath>& paths); 185 void ListCallback(const std::vector<dbus::ObjectPath>& paths);
186 void SmsReceivedCallback(const dbus::ObjectPath& path, bool complete); 186 void SmsReceivedCallback(const dbus::ObjectPath& path, bool complete);
187 void GetCallback(const base::DictionaryValue& dictionary); 187 void GetCallback(const base::DictionaryValue& dictionary);
188 void DeleteMessages(); 188 void DeleteMessages();
189 void GetMessages(); 189 void GetMessages();
190 void MessageReceived(const base::DictionaryValue& dictionary); 190 void MessageReceived(const base::DictionaryValue& dictionary);
191 191
192 NetworkSmsHandler* host_; 192 NetworkSmsHandler* host_;
193 std::string dbus_connection_; 193 std::string service_name_;
194 dbus::ObjectPath object_path_; 194 dbus::ObjectPath object_path_;
195 bool deleting_messages_; 195 bool deleting_messages_;
196 bool retrieving_messages_; 196 bool retrieving_messages_;
197 base::WeakPtrFactory<ModemManager1NetworkSmsDeviceHandler> weak_ptr_factory_; 197 base::WeakPtrFactory<ModemManager1NetworkSmsDeviceHandler> weak_ptr_factory_;
198 std::vector<dbus::ObjectPath> delete_queue_; 198 std::vector<dbus::ObjectPath> delete_queue_;
199 std::deque<dbus::ObjectPath> retrieval_queue_; 199 std::deque<dbus::ObjectPath> retrieval_queue_;
200 200
201 DISALLOW_COPY_AND_ASSIGN(ModemManager1NetworkSmsDeviceHandler); 201 DISALLOW_COPY_AND_ASSIGN(ModemManager1NetworkSmsDeviceHandler);
202 }; 202 };
203 203
204 NetworkSmsHandler:: 204 NetworkSmsHandler::
205 ModemManager1NetworkSmsDeviceHandler::ModemManager1NetworkSmsDeviceHandler( 205 ModemManager1NetworkSmsDeviceHandler::ModemManager1NetworkSmsDeviceHandler(
206 NetworkSmsHandler* host, 206 NetworkSmsHandler* host,
207 std::string dbus_connection, 207 const std::string& service_name,
208 dbus::ObjectPath object_path) 208 const dbus::ObjectPath& object_path)
209 : host_(host), 209 : host_(host),
210 dbus_connection_(dbus_connection), 210 service_name_(service_name),
211 object_path_(object_path), 211 object_path_(object_path),
212 deleting_messages_(false), 212 deleting_messages_(false),
213 retrieving_messages_(false), 213 retrieving_messages_(false),
214 weak_ptr_factory_(this) { 214 weak_ptr_factory_(this) {
215 // Set the handler for received Sms messaages. 215 // Set the handler for received Sms messaages.
216 DBusThreadManager::Get()->GetModemMessagingClient()->SetSmsReceivedHandler( 216 DBusThreadManager::Get()->GetModemMessagingClient()->SetSmsReceivedHandler(
217 dbus_connection_, object_path_, 217 service_name_, object_path_,
218 base::Bind( 218 base::Bind(
219 &NetworkSmsHandler:: 219 &NetworkSmsHandler::
220 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback, 220 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback,
221 weak_ptr_factory_.GetWeakPtr())); 221 weak_ptr_factory_.GetWeakPtr()));
222 222
223 // List the existing messages. 223 // List the existing messages.
224 DBusThreadManager::Get()->GetModemMessagingClient()->List( 224 DBusThreadManager::Get()->GetModemMessagingClient()->List(
225 dbus_connection_, object_path_, 225 service_name_, object_path_,
226 base::Bind(&NetworkSmsHandler:: 226 base::Bind(&NetworkSmsHandler::
227 ModemManager1NetworkSmsDeviceHandler::ListCallback, 227 ModemManager1NetworkSmsDeviceHandler::ListCallback,
228 weak_ptr_factory_.GetWeakPtr())); 228 weak_ptr_factory_.GetWeakPtr()));
229 } 229 }
230 230
231 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::RequestUpdate() { 231 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::RequestUpdate() {
232 // Calling List using the service "AddSMS" causes the stub 232 // Calling List using the service "AddSMS" causes the stub
233 // implementation to deliver new sms messages. 233 // implementation to deliver new sms messages.
234 DBusThreadManager::Get()->GetModemMessagingClient()->List( 234 DBusThreadManager::Get()->GetModemMessagingClient()->List(
235 std::string("AddSMS"), dbus::ObjectPath("/"), 235 std::string("AddSMS"), dbus::ObjectPath("/"),
(...skipping 19 matching lines...) Expand all
255 // the back of the list so that the indices are valid. 255 // the back of the list so that the indices are valid.
256 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::DeleteMessages() { 256 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::DeleteMessages() {
257 if (delete_queue_.empty()) { 257 if (delete_queue_.empty()) {
258 deleting_messages_ = false; 258 deleting_messages_ = false;
259 return; 259 return;
260 } 260 }
261 deleting_messages_ = true; 261 deleting_messages_ = true;
262 dbus::ObjectPath sms_path = delete_queue_.back(); 262 dbus::ObjectPath sms_path = delete_queue_.back();
263 delete_queue_.pop_back(); 263 delete_queue_.pop_back();
264 DBusThreadManager::Get()->GetModemMessagingClient()->Delete( 264 DBusThreadManager::Get()->GetModemMessagingClient()->Delete(
265 dbus_connection_, object_path_, sms_path, 265 service_name_, object_path_, sms_path,
266 base::Bind(&NetworkSmsHandler:: 266 base::Bind(&NetworkSmsHandler::
267 ModemManager1NetworkSmsDeviceHandler::DeleteMessages, 267 ModemManager1NetworkSmsDeviceHandler::DeleteMessages,
268 weak_ptr_factory_.GetWeakPtr())); 268 weak_ptr_factory_.GetWeakPtr()));
269 } 269 }
270 270
271 // Messages must be fetched one at a time, so that we do not queue too 271 // Messages must be fetched one at a time, so that we do not queue too
272 // many requests to a single threaded server. 272 // many requests to a single threaded server.
273 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetMessages() { 273 void NetworkSmsHandler::ModemManager1NetworkSmsDeviceHandler::GetMessages() {
274 if (retrieval_queue_.empty()) { 274 if (retrieval_queue_.empty()) {
275 retrieving_messages_ = false; 275 retrieving_messages_ = false;
276 if (!deleting_messages_) 276 if (!deleting_messages_)
277 DeleteMessages(); 277 DeleteMessages();
278 return; 278 return;
279 } 279 }
280 retrieving_messages_ = true; 280 retrieving_messages_ = true;
281 dbus::ObjectPath sms_path = retrieval_queue_.front(); 281 dbus::ObjectPath sms_path = retrieval_queue_.front();
282 retrieval_queue_.pop_front(); 282 retrieval_queue_.pop_front();
283 DBusThreadManager::Get()->GetSMSClient()->GetAll( 283 DBusThreadManager::Get()->GetSMSClient()->GetAll(
284 dbus_connection_, sms_path, 284 service_name_, sms_path,
285 base::Bind(&NetworkSmsHandler:: 285 base::Bind(&NetworkSmsHandler::
286 ModemManager1NetworkSmsDeviceHandler::GetCallback, 286 ModemManager1NetworkSmsDeviceHandler::GetCallback,
287 weak_ptr_factory_.GetWeakPtr())); 287 weak_ptr_factory_.GetWeakPtr()));
288 delete_queue_.push_back(sms_path); 288 delete_queue_.push_back(sms_path);
289 } 289 }
290 290
291 void NetworkSmsHandler:: 291 void NetworkSmsHandler::
292 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback( 292 ModemManager1NetworkSmsDeviceHandler::SmsReceivedCallback(
293 const dbus::ObjectPath& sms_path, 293 const dbus::ObjectPath& sms_path,
294 bool complete) { 294 bool complete) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 450
451 std::string device_type; 451 std::string device_type;
452 if (!properties.GetStringWithoutPathExpansion( 452 if (!properties.GetStringWithoutPathExpansion(
453 shill::kTypeProperty, &device_type)) { 453 shill::kTypeProperty, &device_type)) {
454 LOG(ERROR) << "NetworkSmsHandler: No type for: " << device_path; 454 LOG(ERROR) << "NetworkSmsHandler: No type for: " << device_path;
455 return; 455 return;
456 } 456 }
457 if (device_type != shill::kTypeCellular) 457 if (device_type != shill::kTypeCellular)
458 return; 458 return;
459 459
460 std::string dbus_connection; 460 std::string service_name;
461 if (!properties.GetStringWithoutPathExpansion( 461 if (!properties.GetStringWithoutPathExpansion(
462 shill::kDBusConnectionProperty, &dbus_connection)) { 462 shill::kDBusServiceProperty, &service_name)) {
463 LOG(ERROR) << "Device has no DBusConnection Property: " << device_path; 463 LOG(ERROR) << "Device has no DBusService Property: " << device_path;
464 return; 464 return;
465 } 465 }
466 466
467 std::string object_path_string; 467 std::string object_path_string;
468 if (!properties.GetStringWithoutPathExpansion( 468 if (!properties.GetStringWithoutPathExpansion(
469 shill::kDBusObjectProperty, &object_path_string)) { 469 shill::kDBusObjectProperty, &object_path_string)) {
470 LOG(ERROR) << "Device has no DBusObject Property: " << device_path; 470 LOG(ERROR) << "Device has no DBusObject Property: " << device_path;
471 return; 471 return;
472 } 472 }
473 dbus::ObjectPath object_path(object_path_string); 473 dbus::ObjectPath object_path(object_path_string);
474 if (object_path_string.compare( 474 if (service_name == modemmanager::kModemManager1) {
475 0, sizeof(modemmanager::kModemManager1ServicePath) - 1,
476 modemmanager::kModemManager1ServicePath) == 0) {
477 device_handlers_.push_back( 475 device_handlers_.push_back(
478 new ModemManager1NetworkSmsDeviceHandler( 476 new ModemManager1NetworkSmsDeviceHandler(
479 this, dbus_connection, object_path)); 477 this, service_name, object_path));
480 } else { 478 } else {
481 device_handlers_.push_back( 479 device_handlers_.push_back(
482 new ModemManagerNetworkSmsDeviceHandler( 480 new ModemManagerNetworkSmsDeviceHandler(
483 this, dbus_connection, object_path)); 481 this, service_name, object_path));
484 } 482 }
485 } 483 }
486 484
487
488 } // namespace chromeos 485 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_shill_device_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698