Delete use of AsyncInvoker in FakeMdnsResponder

Bug: webrtc:12339
Change-Id: Icf27a95eeb1433cd1c0166f8a0f6afa16aabd383
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/211353
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33562}
This commit is contained in:
Niels Möller
2021-03-25 09:31:26 +01:00
committed by Commit Bot
parent acf8ccb3c9
commit c964d80e3d
2 changed files with 9 additions and 7 deletions

View File

@ -1211,6 +1211,7 @@ rtc_library("rtc_base_tests_utils") {
"../api/units:timestamp",
"memory:fifo_buffer",
"synchronization:mutex",
"task_utils:to_queued_task",
"third_party/sigslot",
]
absl_deps = [

View File

@ -19,10 +19,14 @@
#include "rtc_base/ip_address.h"
#include "rtc_base/location.h"
#include "rtc_base/mdns_responder_interface.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "rtc_base/thread.h"
namespace webrtc {
// This class posts tasks on the given `thread` to invoke callbacks. It's the
// callback's responsibility to be aware of potential destruction of state it
// depends on, e.g., using WeakPtrFactory or PendingTaskSafetyFlag.
class FakeMdnsResponder : public MdnsResponderInterface {
public:
explicit FakeMdnsResponder(rtc::Thread* thread) : thread_(thread) {}
@ -37,9 +41,8 @@ class FakeMdnsResponder : public MdnsResponderInterface {
name = std::to_string(next_available_id_++) + ".local";
addr_name_map_[addr] = name;
}
invoker_.AsyncInvoke<void>(
RTC_FROM_HERE, thread_,
[callback, addr, name]() { callback(addr, name); });
thread_->PostTask(
ToQueuedTask([callback, addr, name]() { callback(addr, name); }));
}
void RemoveNameForAddress(const rtc::IPAddress& addr,
NameRemovedCallback callback) override {
@ -48,8 +51,7 @@ class FakeMdnsResponder : public MdnsResponderInterface {
addr_name_map_.erase(it);
}
bool result = it != addr_name_map_.end();
invoker_.AsyncInvoke<void>(RTC_FROM_HERE, thread_,
[callback, result]() { callback(result); });
thread_->PostTask(ToQueuedTask([callback, result]() { callback(result); }));
}
rtc::IPAddress GetMappedAddressForName(const std::string& name) const {
@ -64,8 +66,7 @@ class FakeMdnsResponder : public MdnsResponderInterface {
private:
uint32_t next_available_id_ = 0;
std::map<rtc::IPAddress, std::string> addr_name_map_;
rtc::Thread* thread_;
rtc::AsyncInvoker invoker_;
rtc::Thread* const thread_;
};
} // namespace webrtc