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