Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / dbus / fake_modem_messaging_client.cc
blobd68cfdecf82f6071e7601c5a5a1aa0520ec9bb55
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.
5 #include "chromeos/dbus/fake_modem_messaging_client.h"
7 #include <string>
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "dbus/object_path.h"
14 namespace chromeos {
16 FakeModemMessagingClient::FakeModemMessagingClient() {}
17 FakeModemMessagingClient::~FakeModemMessagingClient() {}
19 void FakeModemMessagingClient::Init(dbus::Bus* bus) {}
21 void FakeModemMessagingClient::SetSmsReceivedHandler(
22 const std::string& service_name,
23 const dbus::ObjectPath& object_path,
24 const SmsReceivedHandler& handler) {
25 sms_received_handler_ = handler;
28 void FakeModemMessagingClient::ResetSmsReceivedHandler(
29 const std::string& service_name,
30 const dbus::ObjectPath& object_path) {
31 sms_received_handler_.Reset();
34 void FakeModemMessagingClient::Delete(const std::string& service_name,
35 const dbus::ObjectPath& object_path,
36 const dbus::ObjectPath& sms_path,
37 const DeleteCallback& callback) {
38 std::vector<dbus::ObjectPath>::iterator it(
39 find(message_paths_.begin(), message_paths_.end(), sms_path));
40 if (it != message_paths_.end())
41 message_paths_.erase(it);
42 callback.Run();
45 void FakeModemMessagingClient::List(const std::string& service_name,
46 const dbus::ObjectPath& object_path,
47 const ListCallback& callback) {
48 // This entire FakeModemMessagingClient is for testing.
49 // Calling List with |service_name| equal to "AddSMS" allows unit
50 // tests to confirm that the sms_received_handler is functioning.
51 if (service_name == "AddSMS") {
52 std::vector<dbus::ObjectPath> no_paths;
53 const dbus::ObjectPath kSmsPath("/SMS/0");
54 message_paths_.push_back(kSmsPath);
55 if (!sms_received_handler_.is_null())
56 sms_received_handler_.Run(kSmsPath, true);
57 callback.Run(no_paths);
58 } else {
59 callback.Run(message_paths_);
63 } // namespace chromeos