Commit d1950e84 authored by Jiawei Li's avatar Jiawei Li Committed by Commit Bot

[cast_bindings] Refactor MessagePort GN targets.

This CL adds |public|, |mesage_port_fuchsia|, and |message_port_cast| to be
used for specifying a implementation for platform agnostic testing.

Bug: Internal b/168598365
Test: bindings_manager_cast_browwsertest, named_message_port_connector_fuchsia_browsertest
Change-Id: I4abfbb6a5bcfc19dbddb7634543a72f5bd288fdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2489024
Commit-Queue: Jiawei Li <lijiawei@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822487}
parent 94a5492a
...@@ -5,34 +5,59 @@ ...@@ -5,34 +5,59 @@
import("//build/config/features.gni") import("//build/config/features.gni")
source_set("message_port") { source_set("message_port") {
if (is_fuchsia) {
public_deps = [ ":message_port_fuchsia" ]
} else if (is_chromecast) {
public_deps = [ ":message_port_cast" ]
}
}
source_set("public") {
sources = [ sources = [
"message_port.cc", "message_port.cc",
"message_port.h", "message_port.h",
] ]
deps = [ deps = [
"//base", "//base",
"//components/cast:export", "//components/cast:export",
] ]
defines = [ "CAST_COMPONENT_IMPLEMENTATION" ] defines = [ "CAST_COMPONENT_IMPLEMENTATION" ]
if (is_fuchsia) { visibility = [ ":*" ]
sources += [ }
"message_port_fuchsia.cc",
"message_port_fuchsia.h", if (is_fuchsia) {
] source_set("message_port_fuchsia") {
public = [ "message_port_fuchsia.h" ]
sources = [ "message_port_fuchsia.cc" ]
public_deps = [ public_deps = [
":public",
"//fuchsia:cast_fidl", "//fuchsia:cast_fidl",
"//fuchsia/base", "//fuchsia/base",
] ]
} else if (is_chromecast) {
sources += [ deps = [ "//base" ]
"message_port_cast.cc",
"message_port_cast.h",
]
deps += [ "//third_party/blink/public/common" ]
} }
} }
source_set("message_port_cast") {
public = [ "message_port_cast.h" ]
sources = [ "message_port_cast.cc" ]
public_deps = [ ":public" ]
deps = [
":public",
"//base",
"//third_party/blink/public/common",
]
}
source_set("test_message_port_receiver") { source_set("test_message_port_receiver") {
testonly = true testonly = true
sources = [ sources = [
......
...@@ -9,13 +9,14 @@ ...@@ -9,13 +9,14 @@
#include <vector> #include <vector>
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "components/cast/cast_component_export.h"
namespace cast_api_bindings { namespace cast_api_bindings {
// HTML5 MessagePort abstraction; allows usage of the platform MessagePort type // HTML5 MessagePort abstraction; allows usage of the platform MessagePort type
// without exposing details of the message format, paired port creation, or // without exposing details of the message format, paired port creation, or
// transfer of ports. // transfer of ports.
class MessagePort { class CAST_COMPONENT_EXPORT MessagePort {
public: public:
// Implemented by receivers of messages from the MessagePort class. // Implemented by receivers of messages from the MessagePort class.
class Receiver { class Receiver {
......
...@@ -195,6 +195,15 @@ class MessagePortFuchsiaServer : public MessagePortFuchsia, ...@@ -195,6 +195,15 @@ class MessagePortFuchsiaServer : public MessagePortFuchsia,
}; };
} // namespace } // namespace
// static
void MessagePort::CreatePair(std::unique_ptr<MessagePort>* client,
std::unique_ptr<MessagePort>* server) {
fidl::InterfaceHandle<fuchsia::web::MessagePort> port0;
fidl::InterfaceRequest<fuchsia::web::MessagePort> port1 = port0.NewRequest();
*client = MessagePortFuchsia::Create(std::move(port0));
*server = MessagePortFuchsia::Create(std::move(port1));
}
// static // static
std::unique_ptr<MessagePort> MessagePortFuchsia::Create( std::unique_ptr<MessagePort> MessagePortFuchsia::Create(
fidl::InterfaceHandle<::fuchsia::web::MessagePort> handle) { fidl::InterfaceHandle<::fuchsia::web::MessagePort> handle) {
...@@ -214,15 +223,6 @@ MessagePortFuchsia* MessagePortFuchsia::FromMessagePort(MessagePort* port) { ...@@ -214,15 +223,6 @@ MessagePortFuchsia* MessagePortFuchsia::FromMessagePort(MessagePort* port) {
return static_cast<MessagePortFuchsia*>(port); return static_cast<MessagePortFuchsia*>(port);
} }
// static
void MessagePort::CreatePair(std::unique_ptr<MessagePort>* client,
std::unique_ptr<MessagePort>* server) {
fidl::InterfaceHandle<fuchsia::web::MessagePort> port0;
fidl::InterfaceRequest<fuchsia::web::MessagePort> port1 = port0.NewRequest();
*client = MessagePortFuchsia::Create(std::move(port0));
*server = MessagePortFuchsia::Create(std::move(port1));
}
// static // static
fuchsia::web::WebMessage MessagePortFuchsia::CreateWebMessage( fuchsia::web::WebMessage MessagePortFuchsia::CreateWebMessage(
base::StringPiece message, base::StringPiece message,
......
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