12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/threading/non_thread_safe.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/content_export.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h"
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content {
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// API messages going between WebKit and native PeerConnection DataChannels in
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// libjingle. Instances of this class are owned by WebKit.
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WebKit call all of these methods on the main render thread.
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Callbacks to the webrtc::DataChannelObserver implementation also occur on
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the main render thread.
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CONTENT_EXPORT RtcDataChannelHandler
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    : NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler),
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NON_EXPORTED_BASE(public webrtc::DataChannelObserver),
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      NON_EXPORTED_BASE(public base::NonThreadSafe) {
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit RtcDataChannelHandler(webrtc::DataChannelInterface* channel);
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~RtcDataChannelHandler();
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // blink::WebRTCDataChannelHandler implementation.
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void setClient(
33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      blink::WebRTCDataChannelHandlerClient* client) OVERRIDE;
34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual blink::WebString label() OVERRIDE;
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool isReliable() OVERRIDE;
36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual bool ordered() const OVERRIDE;
37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual unsigned short maxRetransmitTime() const OVERRIDE;
38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual unsigned short maxRetransmits() const OVERRIDE;
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual blink::WebString protocol() const OVERRIDE;
40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual bool negotiated() const OVERRIDE;
41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  virtual unsigned short id() const OVERRIDE;
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual unsigned long bufferedAmount() OVERRIDE;
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual bool sendStringData(const blink::WebString& data) OVERRIDE;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool sendRawData(const char* data, size_t length) OVERRIDE;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void close() OVERRIDE;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // webrtc::DataChannelObserver implementation.
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnStateChange() OVERRIDE;
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnMessage(const webrtc::DataBuffer& buffer) OVERRIDE;
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void RecordMessageSent(size_t num_bytes);
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<webrtc::DataChannelInterface> channel_;
55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  blink::WebRTCDataChannelHandlerClient* webkit_client_;
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace content
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
61