OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/dbus/fake_modem_messaging_client.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/logging.h" |
| 12 #include "dbus/object_path.h" |
| 13 |
| 14 namespace chromeos { |
| 15 |
| 16 FakeModemMessagingClient::FakeModemMessagingClient() {} |
| 17 FakeModemMessagingClient::~FakeModemMessagingClient() {} |
| 18 |
| 19 void FakeModemMessagingClient::Init(dbus::Bus* bus) {} |
| 20 |
| 21 void FakeModemMessagingClient::SetSmsReceivedHandler( |
| 22 const std::string& service_name, |
| 23 const dbus::ObjectPath& object_path, |
| 24 const SmsReceivedHandler& handler) { |
| 25 DCHECK(sms_received_handler_.is_null()); |
| 26 sms_received_handler_ = handler; |
| 27 } |
| 28 |
| 29 void FakeModemMessagingClient::ResetSmsReceivedHandler( |
| 30 const std::string& service_name, |
| 31 const dbus::ObjectPath& object_path) { |
| 32 sms_received_handler_.Reset(); |
| 33 } |
| 34 |
| 35 void FakeModemMessagingClient::Delete(const std::string& service_name, |
| 36 const dbus::ObjectPath& object_path, |
| 37 const dbus::ObjectPath& sms_path, |
| 38 const DeleteCallback& callback) { |
| 39 std::vector<dbus::ObjectPath>::iterator it( |
| 40 find(message_paths_.begin(), message_paths_.end(), sms_path)); |
| 41 if (it != message_paths_.end()) |
| 42 message_paths_.erase(it); |
| 43 callback.Run(); |
| 44 } |
| 45 |
| 46 void FakeModemMessagingClient::List(const std::string& service_name, |
| 47 const dbus::ObjectPath& object_path, |
| 48 const ListCallback& callback) { |
| 49 // This entire FakeModemMessagingClient is for testing. |
| 50 // Calling List with |service_name| equal to "AddSMS" allows unit |
| 51 // tests to confirm that the sms_received_handler is functioning. |
| 52 if (service_name == "AddSMS") { |
| 53 std::vector<dbus::ObjectPath> no_paths; |
| 54 const dbus::ObjectPath kSmsPath("/SMS/0"); |
| 55 message_paths_.push_back(kSmsPath); |
| 56 if (!sms_received_handler_.is_null()) |
| 57 sms_received_handler_.Run(kSmsPath, true); |
| 58 callback.Run(no_paths); |
| 59 } else { |
| 60 callback.Run(message_paths_); |
| 61 } |
| 62 } |
| 63 |
| 64 } // namespace chromeos |
OLD | NEW |