Commit bfab7262 authored by David Bokan's avatar David Bokan Committed by Chromium LUCI CQ

Convert DisplaySource to [Once|Repeating]Callback

Bug: 1152268
Change-Id: Ief9b1e5d106c72b44442a4199c83a7f76e8e8813
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593838
Commit-Queue: Eero Häkkinen <eero.hakkinen@intel.com>
Reviewed-by: default avatarEero Häkkinen <eero.hakkinen@intel.com>
Cr-Commit-Position: refs/heads/master@{#838535}
parent 452ff469
......@@ -34,11 +34,12 @@ DisplaySourceGetAvailableSinksFunction::Run() {
return RespondNow(Error(kErrorNotSupported));
}
auto success_callback = base::Bind(
auto success_callback = base::BindOnce(
&DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted, this);
auto failure_callback = base::Bind(
auto failure_callback = base::BindOnce(
&DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed, this);
delegate->GetAvailableSinks(success_callback, failure_callback);
delegate->GetAvailableSinks(std::move(success_callback),
std::move(failure_callback));
return RespondLater();
}
......@@ -76,13 +77,13 @@ DisplaySourceRequestAuthenticationFunction::Run() {
return RespondNow(Error(kErrorNotSupported));
}
auto success_callback = base::Bind(
auto success_callback = base::BindOnce(
&DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted,
this);
auto failure_callback = base::Bind(
auto failure_callback = base::BindOnce(
&DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed, this);
delegate->RequestAuthentication(params->sink_id, success_callback,
failure_callback);
delegate->RequestAuthentication(params->sink_id, std::move(success_callback),
std::move(failure_callback));
return RespondLater();
}
......
......@@ -45,18 +45,18 @@ class MockDisplaySourceConnectionDelegate
: nullptr;
}
void GetAvailableSinks(const SinkInfoListCallback& sinks_callback,
const StringCallback& failure_callback) override;
void GetAvailableSinks(SinkInfoListCallback sinks_callback,
FailureCallback failure_callback) override;
void RequestAuthentication(int sink_id,
const AuthInfoCallback& auth_info_callback,
const StringCallback& failure_callback) override;
AuthInfoCallback auth_info_callback,
FailureCallback failure_callback) override;
void Connect(int sink_id,
const DisplaySourceAuthInfo& auth_info,
const StringCallback& failure_callback) override;
FailureCallback failure_callback) override;
void Disconnect(const StringCallback& failure_callback) override;
void Disconnect(FailureCallback failure_callback) override;
void StartWatchingAvailableSinks() override;
......@@ -71,8 +71,7 @@ class MockDisplaySourceConnectionDelegate
void SendMessage(const std::string& message) override;
void SetMessageReceivedCallback(
const StringCallback& callback) override;
void SetMessageReceivedCallback(RepeatingMessageCallback callback) override;
private:
void AddSink(DisplaySourceSinkInfo sink,
......@@ -97,7 +96,7 @@ class MockDisplaySourceConnectionDelegate
DisplaySourceSinkInfoList sinks_;
DisplaySourceSinkInfo* active_sink_;
std::map<int, std::pair<AuthenticationMethod, std::string>> auth_infos_;
StringCallback message_received_cb_;
RepeatingMessageCallback message_received_cb_;
struct Message {
enum Direction {
......@@ -298,27 +297,27 @@ MockDisplaySourceConnectionDelegate::last_found_sinks() const {
}
void MockDisplaySourceConnectionDelegate::GetAvailableSinks(
const SinkInfoListCallback& sinks_callback,
const StringCallback& failure_callback) {
sinks_callback.Run(sinks_);
SinkInfoListCallback sinks_callback,
FailureCallback failure_callback) {
std::move(sinks_callback).Run(sinks_);
}
void MockDisplaySourceConnectionDelegate::RequestAuthentication(
int sink_id,
const AuthInfoCallback& auth_info_callback,
const StringCallback& failure_callback) {
AuthInfoCallback auth_info_callback,
FailureCallback failure_callback) {
DisplaySourceAuthInfo info;
auto it = auth_infos_.find(sink_id);
ASSERT_NE(it, auth_infos_.end());
info.method = it->second.first;
auth_info_callback.Run(info);
std::move(auth_info_callback).Run(info);
}
void MockDisplaySourceConnectionDelegate::Connect(
int sink_id,
const DisplaySourceAuthInfo& auth_info,
const StringCallback& failure_callback) {
FailureCallback failure_callback) {
auto it = auth_infos_.find(sink_id);
ASSERT_NE(it, auth_infos_.end());
ASSERT_EQ(it->second.first, auth_info.method);
......@@ -345,7 +344,7 @@ void MockDisplaySourceConnectionDelegate::Connect(
}
void MockDisplaySourceConnectionDelegate::Disconnect(
const StringCallback& failure_callback) {
FailureCallback failure_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CHECK(active_sink_);
ASSERT_EQ(active_sink_->state, SINK_STATE_CONNECTED);
......@@ -389,8 +388,8 @@ void MockDisplaySourceConnectionDelegate::SendMessage(
}
void MockDisplaySourceConnectionDelegate::SetMessageReceivedCallback(
const StringCallback& callback) {
message_received_cb_ = callback;
RepeatingMessageCallback callback) {
message_received_cb_ = std::move(callback);
}
void MockDisplaySourceConnectionDelegate::AddSink(
......@@ -528,7 +527,7 @@ void MockDisplaySourceConnectionDelegate::OnMediaPacketReceived(
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&MockDisplaySourceConnectionDelegate::Disconnect,
base::Unretained(this), StringCallback()));
base::Unretained(this), FailureCallback()));
return;
}
......
......@@ -22,10 +22,13 @@ using DisplaySourceErrorType = api::display_source::ErrorType;
// 'chrome.displaySource' API.
class DisplaySourceConnectionDelegate : public KeyedService {
public:
using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>;
using StringCallback = base::Callback<void(const std::string&)>;
using AuthInfoCallback =
base::OnceCallback<void(const DisplaySourceAuthInfo&)>;
using RepeatingMessageCallback =
base::RepeatingCallback<void(const std::string&)>;
using FailureCallback = base::OnceCallback<void(const std::string&)>;
using SinkInfoListCallback =
base::Callback<void(const DisplaySourceSinkInfoList&)>;
base::OnceCallback<void(const DisplaySourceSinkInfoList&)>;
const static int kInvalidSinkId = -1;
......@@ -49,7 +52,7 @@ class DisplaySourceConnectionDelegate : public KeyedService {
// Connection object.
// If an error occurs 'Observer::OnConnectionError' is invoked.
virtual void SetMessageReceivedCallback(
const StringCallback& callback) = 0;
RepeatingMessageCallback callback) = 0;
protected:
Connection();
......@@ -94,27 +97,26 @@ class DisplaySourceConnectionDelegate : public KeyedService {
virtual Connection* connection() = 0;
// Queries the list of currently available sinks.
virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback,
const StringCallback& failure_callback) = 0;
virtual void GetAvailableSinks(SinkInfoListCallback sinks_callback,
FailureCallback failure_callback) = 0;
// Queries the authentication method required by the sink for connection.
// If the used authentication method requires authentication data to be
// visible on the sink's display (e.g. PIN) the implementation should
// request the sink to show it.
virtual void RequestAuthentication(
int sink_id,
const AuthInfoCallback& auth_info_callback,
const StringCallback& failure_callback) = 0;
virtual void RequestAuthentication(int sink_id,
AuthInfoCallback auth_info_callback,
FailureCallback failure_callback) = 0;
// Connects to a sink by given id and auth info.
virtual void Connect(int sink_id,
const DisplaySourceAuthInfo& auth_info,
const StringCallback& failure_callback) = 0;
FailureCallback failure_callback) = 0;
// Disconnects the current connection to sink, the 'failure_callback'
// is called if an error has occurred or if there is no established
// connection.
virtual void Disconnect(const StringCallback& failure_callback) = 0;
virtual void Disconnect(FailureCallback failure_callback) = 0;
// Implementation should start watching the available sinks updates.
virtual void StartWatchingAvailableSinks() = 0;
......
......@@ -115,8 +115,8 @@ void WiFiDisplayMediaServiceImpl::Send() {
DCHECK(!write_buffers_.empty());
last_send_code_ = rtp_socket_->Write(
write_buffers_.front().get(), write_buffers_.front()->size(),
base::Bind(&WiFiDisplayMediaServiceImpl::OnSent,
weak_factory_.GetWeakPtr()));
base::BindOnce(&WiFiDisplayMediaServiceImpl::OnSent,
weak_factory_.GetWeakPtr()));
if (last_send_code_ != net::ERR_IO_PENDING)
OnSent(last_send_code_);
}
......
......@@ -51,8 +51,8 @@ void WiFiDisplaySessionServiceImpl::SetClient(
DCHECK(!client_);
client_.Bind(std::move(client));
client_.set_disconnect_handler(
base::Bind(&WiFiDisplaySessionServiceImpl::OnClientConnectionError,
weak_factory_.GetWeakPtr()));
base::BindOnce(&WiFiDisplaySessionServiceImpl::OnClientConnectionError,
weak_factory_.GetWeakPtr()));
}
void WiFiDisplaySessionServiceImpl::Connect(int32_t sink_id,
......@@ -80,9 +80,10 @@ void WiFiDisplaySessionServiceImpl::Connect(int32_t sink_id,
auth_info.method = static_cast<AuthenticationMethod>(auth_method);
auth_info.data = std::unique_ptr<std::string>(new std::string(auth_data));
}
auto on_error = base::Bind(&WiFiDisplaySessionServiceImpl::OnConnectFailed,
weak_factory_.GetWeakPtr(), sink_id);
delegate_->Connect(sink_id, auth_info, on_error);
auto on_error =
base::BindOnce(&WiFiDisplaySessionServiceImpl::OnConnectFailed,
weak_factory_.GetWeakPtr(), sink_id);
delegate_->Connect(sink_id, auth_info, std::move(on_error));
sink_id_ = sink_id;
sink_state_ = found->state;
DCHECK(sink_state_ == SINK_STATE_CONNECTING);
......@@ -105,9 +106,10 @@ void WiFiDisplaySessionServiceImpl::Disconnect() {
DCHECK(found->state == SINK_STATE_CONNECTED ||
found->state == SINK_STATE_CONNECTING);
auto on_error = base::Bind(&WiFiDisplaySessionServiceImpl::OnDisconnectFailed,
weak_factory_.GetWeakPtr(), sink_id_);
delegate_->Disconnect(on_error);
auto on_error =
base::BindOnce(&WiFiDisplaySessionServiceImpl::OnDisconnectFailed,
weak_factory_.GetWeakPtr(), sink_id_);
delegate_->Disconnect(std::move(on_error));
}
void WiFiDisplaySessionServiceImpl::SendMessage(const std::string& message) {
......@@ -153,8 +155,9 @@ void WiFiDisplaySessionServiceImpl::OnSinksUpdated(
if (actual_state == SINK_STATE_CONNECTED) {
auto connection = delegate_->connection();
DCHECK(connection);
auto on_message = base::Bind(&WiFiDisplaySessionServiceImpl::OnSinkMessage,
weak_factory_.GetWeakPtr());
auto on_message =
base::BindRepeating(&WiFiDisplaySessionServiceImpl::OnSinkMessage,
weak_factory_.GetWeakPtr());
connection->SetMessageReceivedCallback(on_message);
client_->OnConnected(connection->GetLocalAddress(),
connection->GetSinkAddress());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment