Skip to content

Commit

Permalink
Switch blink::RtcPeerConnectionHandler away from std::string
Browse files Browse the repository at this point in the history
Note that, given that this cl interfaces with libwebrtc,
some std::string usage was deliverately left untouched.

BUG=787254
R=guidou@chromium.org, haraken@chromium.org

Change-Id: Idb7a877c100a05400d0ce8daad0f870945c65ac2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880962
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712029}
  • Loading branch information
tonikitoo authored and Commit Bot committed Nov 3, 2019
1 parent 73a7c6b commit 6774083
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ class RTCPeerConnectionHandler::Observer
: handler_(handler), main_thread_(task_runner) {}

// When an RTC event log is sent back from PeerConnection, it arrives here.
void OnWebRtcEventLogWrite(const std::string& output) override {
void OnWebRtcEventLogWrite(const String& output) override {
if (!main_thread_->BelongsToCurrentThread()) {
main_thread_->PostTask(
FROM_HERE,
Expand Down Expand Up @@ -949,11 +949,11 @@ class RTCPeerConnectionHandler::Observer

main_thread_->PostTask(
FROM_HERE,
base::BindOnce(&RTCPeerConnectionHandler::Observer::OnIceCandidateImpl,
this, sdp, candidate->sdp_mid(),
candidate->sdp_mline_index(),
candidate->candidate().component(),
candidate->candidate().address().family()));
base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnIceCandidateImpl, this,
String::FromUTF8(sdp), String::FromUTF8(candidate->sdp_mid()),
candidate->sdp_mline_index(), candidate->candidate().component(),
candidate->candidate().address().family()));
}

void OnIceCandidateError(const std::string& host_candidate,
Expand All @@ -964,7 +964,8 @@ class RTCPeerConnectionHandler::Observer
FROM_HERE,
base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnIceCandidateErrorImpl, this,
host_candidate, url, error_code, error_text));
String::FromUTF8(host_candidate), String::FromUTF8(url), error_code,
String::FromUTF8(error_text)));
}

void OnDataChannelImpl(scoped_refptr<DataChannelInterface> channel) {
Expand All @@ -973,8 +974,8 @@ class RTCPeerConnectionHandler::Observer
handler_->OnDataChannel(std::move(channel));
}

void OnIceCandidateImpl(const std::string& sdp,
const std::string& sdp_mid,
void OnIceCandidateImpl(const String& sdp,
const String& sdp_mid,
int sdp_mline_index,
int component,
int address_family) {
Expand All @@ -985,10 +986,10 @@ class RTCPeerConnectionHandler::Observer
}
}

void OnIceCandidateErrorImpl(const std::string& host_candidate,
const std::string& url,
void OnIceCandidateErrorImpl(const String& host_candidate,
const String& url,
int error_code,
const std::string& error_text) {
const String& error_text) {
DCHECK(main_thread_->BelongsToCurrentThread());
if (handler_) {
handler_->OnIceCandidateError(host_candidate, url, error_code,
Expand Down Expand Up @@ -1308,22 +1309,23 @@ void RTCPeerConnectionHandler::SetLocalDescription(
webrtc::SessionDescriptionInterface* native_desc =
CreateNativeSessionDescription(sdp, type, &error);
if (!native_desc) {
std::string reason_str = "Failed to parse SessionDescription. ";
reason_str.append(error.line);
reason_str.append(" ");
reason_str.append(error.description);
LOG(ERROR) << reason_str;
StringBuilder reason_str;
reason_str.Append("Failed to parse SessionDescription. ");
reason_str.Append(error.line.c_str());
reason_str.Append(" ");
reason_str.Append(error.description.c_str());
LOG(ERROR) << reason_str.ToString();
if (peer_connection_tracker_) {
peer_connection_tracker_->TrackSessionDescriptionCallback(
this, PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION,
"OnFailure", String::FromUTF8(reason_str));
"OnFailure", reason_str.ToString());
}
// Warning: this line triggers the error callback to be executed, causing
// arbitrary JavaScript to be executed synchronously. As a result, it is
// possible for |this| to be deleted after this line. See
// https://crbug.com/1005251.
request.RequestFailed(webrtc::RTCError(webrtc::RTCErrorType::INTERNAL_ERROR,
std::move(reason_str)));
reason_str.ToString().Utf8()));
return;
}

Expand Down Expand Up @@ -1385,22 +1387,24 @@ void RTCPeerConnectionHandler::SetRemoteDescription(
std::unique_ptr<webrtc::SessionDescriptionInterface> native_desc(
CreateNativeSessionDescription(sdp, type, &error));
if (!native_desc) {
std::string reason_str = "Failed to parse SessionDescription. ";
reason_str.append(error.line);
reason_str.append(" ");
reason_str.append(error.description);
LOG(ERROR) << reason_str;
StringBuilder reason_str;
reason_str.Append("Failed to parse SessionDescription. ");
reason_str.Append(error.line.c_str());
reason_str.Append(" ");
reason_str.Append(error.description.c_str());
LOG(ERROR) << reason_str.ToString();
if (peer_connection_tracker_) {
peer_connection_tracker_->TrackSessionDescriptionCallback(
this, PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION,
"OnFailure", String::FromUTF8(reason_str));
"OnFailure", reason_str.ToString());
}
// Warning: this line triggers the error callback to be executed, causing
// arbitrary JavaScript to be executed synchronously. As a result, it is
// possible for |this| to be deleted after this line. See
// https://crbug.com/1005251.
request.RequestFailed(webrtc::RTCError(
webrtc::RTCErrorType::UNSUPPORTED_OPERATION, std::move(reason_str)));
request.RequestFailed(
webrtc::RTCError(webrtc::RTCErrorType::UNSUPPORTED_OPERATION,
reason_str.ToString().Utf8()));
return;
}

Expand Down Expand Up @@ -2037,12 +2041,10 @@ void RTCPeerConnectionHandler::StopEventLog() {
native_peer_connection_->StopRtcEventLog();
}

void RTCPeerConnectionHandler::OnWebRtcEventLogWrite(
const std::string& output) {
void RTCPeerConnectionHandler::OnWebRtcEventLogWrite(const String& output) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (peer_connection_tracker_) {
peer_connection_tracker_->TrackRtcEventLogWrite(this,
String::FromUTF8(output));
peer_connection_tracker_->TrackRtcEventLogWrite(this, output);
}
}

Expand Down Expand Up @@ -2388,17 +2390,15 @@ void RTCPeerConnectionHandler::OnDataChannel(
client_->DidAddRemoteDataChannel(std::move(channel));
}

void RTCPeerConnectionHandler::OnIceCandidate(const std::string& sdp,
const std::string& sdp_mid,
void RTCPeerConnectionHandler::OnIceCandidate(const String& sdp,
const String& sdp_mid,
int sdp_mline_index,
int component,
int address_family) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnIceCandidateImpl");
scoped_refptr<blink::WebRTCICECandidate> web_candidate =
blink::WebRTCICECandidate::Create(blink::WebString::FromUTF8(sdp),
blink::WebString::FromUTF8(sdp_mid),
sdp_mline_index);
blink::WebRTCICECandidate::Create(sdp, sdp_mid, sdp_mline_index);
if (peer_connection_tracker_) {
peer_connection_tracker_->TrackAddIceCandidate(
this, web_candidate, PeerConnectionTracker::SOURCE_LOCAL, true);
Expand All @@ -2419,18 +2419,15 @@ void RTCPeerConnectionHandler::OnIceCandidate(const std::string& sdp,
client_->DidGenerateICECandidate(std::move(web_candidate));
}

void RTCPeerConnectionHandler::OnIceCandidateError(
const std::string& host_candidate,
const std::string& url,
int error_code,
const std::string& error_text) {
void RTCPeerConnectionHandler::OnIceCandidateError(const String& host_candidate,
const String& url,
int error_code,
const String& error_text) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnIceCandidateError");

if (!is_closed_) {
client_->DidFailICECandidate(blink::WebString::FromUTF8(host_candidate),
blink::WebString::FromUTF8(url), error_code,
blink::WebString::FromUTF8(error_text));
client_->DidFailICECandidate(host_candidate, url, error_code, error_text);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class MODULES_EXPORT RTCPeerConnectionHandler
void StopEventLog();

// WebRTC event log fragments sent back from PeerConnection land here.
void OnWebRtcEventLogWrite(const std::string& output);
void OnWebRtcEventLogWrite(const String& output);

protected:
webrtc::PeerConnectionInterface* native_peer_connection() {
Expand Down Expand Up @@ -234,15 +234,15 @@ class MODULES_EXPORT RTCPeerConnectionHandler
std::vector<blink::RtpTransceiverState> transceiver_states,
bool is_remote_description);
void OnDataChannel(scoped_refptr<webrtc::DataChannelInterface> channel);
void OnIceCandidate(const std::string& sdp,
const std::string& sdp_mid,
void OnIceCandidate(const String& sdp,
const String& sdp_mid,
int sdp_mline_index,
int component,
int address_family);
void OnIceCandidateError(const std::string& host_candidate,
const std::string& url,
void OnIceCandidateError(const String& host_candidate,
const String& url,
int error_code,
const std::string& error_text);
const String& error_text);
void OnInterestingUsage(int usage_pattern);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_RTC_EVENT_LOG_OUTPUT_SINK_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_PEERCONNECTION_RTC_EVENT_LOG_OUTPUT_SINK_H_

#include <string>

#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

class PLATFORM_EXPORT RtcEventLogOutputSink {
public:
virtual ~RtcEventLogOutputSink() = default;

virtual void OnWebRtcEventLogWrite(const std::string& output) = 0;
virtual void OnWebRtcEventLogWrite(const WTF::String& output) = 0;
};

} // namespace blink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "base/logging.h"
#include "third_party/blink/renderer/platform/peerconnection/rtc_event_log_output_sink.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {

Expand All @@ -27,7 +28,7 @@ bool RtcEventLogOutputSinkProxy::IsActive() const {
}

bool RtcEventLogOutputSinkProxy::Write(const std::string& output) {
sink_->OnWebRtcEventLogWrite(output);
sink_->OnWebRtcEventLogWrite(String::FromUTF8(output.c_str()));
return true;
}

Expand Down

0 comments on commit 6774083

Please sign in to comment.