| 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 #include "chromeos/dbus/modem_messaging_client.h" | 4 #include "chromeos/dbus/modem_messaging_client.h" |
| 5 | 5 |
| 6 #include <map> | 6 #include <map> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return proxy; | 190 return proxy; |
| 191 } | 191 } |
| 192 | 192 |
| 193 dbus::Bus* bus_; | 193 dbus::Bus* bus_; |
| 194 ProxyMap proxies_; | 194 ProxyMap proxies_; |
| 195 STLValueDeleter<ProxyMap> proxies_deleter_; | 195 STLValueDeleter<ProxyMap> proxies_deleter_; |
| 196 | 196 |
| 197 DISALLOW_COPY_AND_ASSIGN(ModemMessagingClientImpl); | 197 DISALLOW_COPY_AND_ASSIGN(ModemMessagingClientImpl); |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 class CHROMEOS_EXPORT ModemMessagingClientStubImpl | |
| 201 : public ModemMessagingClient { | |
| 202 public: | |
| 203 ModemMessagingClientStubImpl() {} | |
| 204 virtual ~ModemMessagingClientStubImpl() {} | |
| 205 | |
| 206 // ModemMessagingClient override. | |
| 207 virtual void Init(dbus::Bus* bus) OVERRIDE {} | |
| 208 virtual void SetSmsReceivedHandler( | |
| 209 const std::string& service_name, | |
| 210 const dbus::ObjectPath& object_path, | |
| 211 const SmsReceivedHandler& handler) OVERRIDE { | |
| 212 DCHECK(sms_received_handler_.is_null()); | |
| 213 sms_received_handler_ = handler; | |
| 214 } | |
| 215 | |
| 216 // ModemMessagingClient override. | |
| 217 virtual void ResetSmsReceivedHandler( | |
| 218 const std::string& service_name, | |
| 219 const dbus::ObjectPath& object_path) OVERRIDE { | |
| 220 sms_received_handler_.Reset(); | |
| 221 } | |
| 222 | |
| 223 // ModemMessagingClient override. | |
| 224 virtual void Delete(const std::string& service_name, | |
| 225 const dbus::ObjectPath& object_path, | |
| 226 const dbus::ObjectPath& sms_path, | |
| 227 const DeleteCallback& callback) OVERRIDE { | |
| 228 std::vector<dbus::ObjectPath>::iterator it( | |
| 229 find(message_paths_.begin(), message_paths_.end(), sms_path)); | |
| 230 if (it != message_paths_.end()) | |
| 231 message_paths_.erase(it); | |
| 232 callback.Run(); | |
| 233 } | |
| 234 | |
| 235 // ModemMessagingClient override. | |
| 236 virtual void List(const std::string& service_name, | |
| 237 const dbus::ObjectPath& object_path, | |
| 238 const ListCallback& callback) OVERRIDE { | |
| 239 // This entire ModemMessagingClientStubImpl is for testing. | |
| 240 // Calling List with |service_name| equal to "AddSMS" allows unit | |
| 241 // tests to confirm that the sms_received_handler is functioning. | |
| 242 if (service_name == "AddSMS") { | |
| 243 std::vector<dbus::ObjectPath> no_paths; | |
| 244 const dbus::ObjectPath kSmsPath("/SMS/0"); | |
| 245 message_paths_.push_back(kSmsPath); | |
| 246 if (!sms_received_handler_.is_null()) | |
| 247 sms_received_handler_.Run(kSmsPath, true); | |
| 248 callback.Run(no_paths); | |
| 249 } else { | |
| 250 callback.Run(message_paths_); | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 private: | |
| 255 SmsReceivedHandler sms_received_handler_; | |
| 256 std::vector<dbus::ObjectPath> message_paths_; | |
| 257 | |
| 258 DISALLOW_COPY_AND_ASSIGN(ModemMessagingClientStubImpl); | |
| 259 }; | |
| 260 | |
| 261 } // namespace | 200 } // namespace |
| 262 | 201 |
| 263 //////////////////////////////////////////////////////////////////////////////// | 202 //////////////////////////////////////////////////////////////////////////////// |
| 264 // ModemMessagingClient | 203 // ModemMessagingClient |
| 265 | 204 |
| 266 ModemMessagingClient::ModemMessagingClient() {} | 205 ModemMessagingClient::ModemMessagingClient() {} |
| 267 | 206 |
| 268 ModemMessagingClient::~ModemMessagingClient() {} | 207 ModemMessagingClient::~ModemMessagingClient() {} |
| 269 | 208 |
| 270 | 209 |
| 271 // static | 210 // static |
| 272 ModemMessagingClient* ModemMessagingClient::Create( | 211 ModemMessagingClient* ModemMessagingClient::Create() { |
| 273 DBusClientImplementationType type) { | 212 return new ModemMessagingClientImpl(); |
| 274 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { | |
| 275 return new ModemMessagingClientImpl(); | |
| 276 } | |
| 277 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | |
| 278 return new ModemMessagingClientStubImpl(); | |
| 279 } | 213 } |
| 280 | 214 |
| 281 | 215 |
| 282 } // namespace chromeos | 216 } // namespace chromeos |
| OLD | NEW |