// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/cast/message_port/blink_message_port_adapter.h" #include <string_view> #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" #include "components/cast/message_port/cast/message_port_cast.h" #include "components/cast/message_port/platform_message_port.h" namespace cast_api_bindings { namespace { // MessagePortAdapters are used to adapt between two different implementations // of cast_api_bindings::MessagePort. // // PostMessageWithTransferables flow including adaptation: //+---+ +-------+ +---------+ +---------+ +-------+ +---+ //| A | | PortA | | AdptrA | | AdptrB | | PortB | | B | //+---+ +-------+ +---------+ +---------+ +-------+ +---+ // | Post | | | | | // |---------->| | | | | // | | OnMsg | | | | // | |------------>| | | | // | | | Adapt Ports | | | // | | |-----------| | | | // | | |<----------| | | | // | | | Post | | | // | | |----------------->| | | // | | | | OnMsg | | // | | | |----------->| | // | | | | | OnMsg | // | | | | |-------->| // // Error flow including deletion, for example when OnMessage fails // | | | | | false | // | | | | |<--------| // | | | | OnErr | | // | | | |<-----------| | // | | | delete | | | // | | |<-----------------| | | // | | delete | | | | // | |<------------| | | | // | OnErr | | | | | // |<----------| | | | | // | | | | delete | | // | | | |------| | | // | | | |<-----| | | class MessagePortAdapter : public MessagePort::Receiver { … }; } // namespace // static std::unique_ptr<MessagePort> BlinkMessagePortAdapter::ToClientPlatformMessagePort( blink::WebMessagePort&& client) { … } // static blink::WebMessagePort BlinkMessagePortAdapter::FromServerPlatformMessagePort( std::unique_ptr<MessagePort> server) { … } } // namespace cast_api_bindings