blob: 181ba9717beac2edc876617403ab55f58ede5104 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
#define CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
#include "base/memory/ref_counted.h"
#include "base/threading/non_thread_safe.h"
#include "content/common/content_export.h"
#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
#include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h"
#include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
namespace content {
// RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel
// API messages going between WebKit and native PeerConnection DataChannels in
// libjingle. Instances of this class are owned by WebKit.
// WebKit call all of these methods on the main render thread.
// Callbacks to the webrtc::DataChannelObserver implementation also occur on
// the main render thread.
class CONTENT_EXPORT RtcDataChannelHandler
: NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler),
NON_EXPORTED_BASE(public webrtc::DataChannelObserver),
NON_EXPORTED_BASE(public base::NonThreadSafe) {
public:
explicit RtcDataChannelHandler(webrtc::DataChannelInterface* channel);
virtual ~RtcDataChannelHandler();
// blink::WebRTCDataChannelHandler implementation.
virtual void setClient(
blink::WebRTCDataChannelHandlerClient* client) override;
virtual blink::WebString label() override;
virtual bool isReliable() override;
virtual bool ordered() const override;
virtual unsigned short maxRetransmitTime() const override;
virtual unsigned short maxRetransmits() const override;
virtual blink::WebString protocol() const override;
virtual bool negotiated() const override;
virtual unsigned short id() const override;
virtual unsigned long bufferedAmount() override;
virtual bool sendStringData(const blink::WebString& data) override;
virtual bool sendRawData(const char* data, size_t length) override;
virtual void close() override;
// webrtc::DataChannelObserver implementation.
void OnStateChange() override;
void OnMessage(const webrtc::DataBuffer& buffer) override;
private:
void RecordMessageSent(size_t num_bytes);
scoped_refptr<webrtc::DataChannelInterface> channel_;
blink::WebRTCDataChannelHandlerClient* webkit_client_;
};
} // namespace content
#endif // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_