1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 6#define CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 7 8#include "base/memory/ref_counted.h" 9#include "base/threading/non_thread_safe.h" 10#include "content/common/content_export.h" 11#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h" 12#include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h" 13#include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" 14 15namespace content { 16 17// RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel 18// API messages going between WebKit and native PeerConnection DataChannels in 19// libjingle. Instances of this class are owned by WebKit. 20// WebKit call all of these methods on the main render thread. 21// Callbacks to the webrtc::DataChannelObserver implementation also occur on 22// the main render thread. 23class CONTENT_EXPORT RtcDataChannelHandler 24 : NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler), 25 NON_EXPORTED_BASE(public webrtc::DataChannelObserver), 26 NON_EXPORTED_BASE(public base::NonThreadSafe) { 27 public: 28 explicit RtcDataChannelHandler(webrtc::DataChannelInterface* channel); 29 virtual ~RtcDataChannelHandler(); 30 31 // blink::WebRTCDataChannelHandler implementation. 32 virtual void setClient( 33 blink::WebRTCDataChannelHandlerClient* client) OVERRIDE; 34 virtual blink::WebString label() OVERRIDE; 35 virtual bool isReliable() OVERRIDE; 36 virtual bool ordered() const OVERRIDE; 37 virtual unsigned short maxRetransmitTime() const OVERRIDE; 38 virtual unsigned short maxRetransmits() const OVERRIDE; 39 virtual blink::WebString protocol() const OVERRIDE; 40 virtual bool negotiated() const OVERRIDE; 41 virtual unsigned short id() const OVERRIDE; 42 virtual unsigned long bufferedAmount() OVERRIDE; 43 virtual bool sendStringData(const blink::WebString& data) OVERRIDE; 44 virtual bool sendRawData(const char* data, size_t length) OVERRIDE; 45 virtual void close() OVERRIDE; 46 47 // webrtc::DataChannelObserver implementation. 48 virtual void OnStateChange() OVERRIDE; 49 virtual void OnMessage(const webrtc::DataBuffer& buffer) OVERRIDE; 50 51 private: 52 void RecordMessageSent(size_t num_bytes); 53 54 scoped_refptr<webrtc::DataChannelInterface> channel_; 55 blink::WebRTCDataChannelHandlerClient* webkit_client_; 56}; 57 58} // namespace content 59 60#endif // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 61