Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: content/renderer/media/rtc_data_channel_handler.h

Issue 686183002: Revert of Refactor RtcDataChannelHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/media/rtc_data_channel_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
6 #define CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 6 #define CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/threading/non_thread_safe.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_checker.h"
12 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h " 11 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
14 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h" 12 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h"
15 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" 13 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
16 14
17 namespace content { 15 namespace content {
18 16
19 // RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel 17 // RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel
20 // API messages going between WebKit and native PeerConnection DataChannels in 18 // API messages going between WebKit and native PeerConnection DataChannels in
21 // libjingle. Instances of this class are owned by WebKit. 19 // libjingle. Instances of this class are owned by WebKit.
22 // WebKit call all of these methods on the main render thread. 20 // WebKit call all of these methods on the main render thread.
23 // Callbacks to the webrtc::DataChannelObserver implementation also occur on 21 // Callbacks to the webrtc::DataChannelObserver implementation also occur on
24 // the main render thread. 22 // the main render thread.
25 class CONTENT_EXPORT RtcDataChannelHandler 23 class CONTENT_EXPORT RtcDataChannelHandler
26 : NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler) { 24 : NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler),
25 NON_EXPORTED_BASE(public webrtc::DataChannelObserver),
26 NON_EXPORTED_BASE(public base::NonThreadSafe) {
27 public: 27 public:
28 // This object can* be constructed on libjingle's signaling thread and then 28 explicit RtcDataChannelHandler(webrtc::DataChannelInterface* channel);
29 // ownership is passed to the UI thread where it's eventually given to WebKit.
30 // The reason we must construct and hook ourselves up as an observer on the
31 // signaling thread is to avoid missing out on any state changes or messages
32 // that may occur before we've fully connected with webkit.
33 // This period is basically between when the ctor is called and until
34 // setClient is called.
35 // * For local data channels, the object will be construced on the main thread
36 // and we don't have the issue described above.
37 RtcDataChannelHandler(
38 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
39 webrtc::DataChannelInterface* channel);
40 virtual ~RtcDataChannelHandler(); 29 virtual ~RtcDataChannelHandler();
41 30
42 // blink::WebRTCDataChannelHandler implementation. 31 // blink::WebRTCDataChannelHandler implementation.
43 virtual void setClient( 32 virtual void setClient(
44 blink::WebRTCDataChannelHandlerClient* client) override; 33 blink::WebRTCDataChannelHandlerClient* client) override;
45 virtual blink::WebString label() override; 34 virtual blink::WebString label() override;
46 virtual bool isReliable() override; 35 virtual bool isReliable() override;
47 virtual bool ordered() const override; 36 virtual bool ordered() const override;
48 virtual unsigned short maxRetransmitTime() const override; 37 virtual unsigned short maxRetransmitTime() const override;
49 virtual unsigned short maxRetransmits() const override; 38 virtual unsigned short maxRetransmits() const override;
50 virtual blink::WebString protocol() const override; 39 virtual blink::WebString protocol() const override;
51 virtual bool negotiated() const override; 40 virtual bool negotiated() const override;
52 virtual unsigned short id() const override; 41 virtual unsigned short id() const override;
53 virtual unsigned long bufferedAmount() override; 42 virtual unsigned long bufferedAmount() override;
54 virtual bool sendStringData(const blink::WebString& data) override; 43 virtual bool sendStringData(const blink::WebString& data) override;
55 virtual bool sendRawData(const char* data, size_t length) override; 44 virtual bool sendRawData(const char* data, size_t length) override;
56 virtual void close() override; 45 virtual void close() override;
57 46
58 const scoped_refptr<webrtc::DataChannelInterface>& channel() const; 47 // webrtc::DataChannelObserver implementation.
48 void OnStateChange() override;
49 void OnMessage(const webrtc::DataBuffer& buffer) override;
59 50
60 private: 51 private:
61 void OnStateChange(webrtc::DataChannelInterface::DataState state);
62 void OnMessage(scoped_ptr<webrtc::DataBuffer> buffer);
63 void RecordMessageSent(size_t num_bytes); 52 void RecordMessageSent(size_t num_bytes);
64 53
65 class CONTENT_EXPORT Observer 54 scoped_refptr<webrtc::DataChannelInterface> channel_;
66 : public NON_EXPORTED_BASE(
67 base::RefCountedThreadSafe<RtcDataChannelHandler::Observer>),
68 public NON_EXPORTED_BASE(webrtc::DataChannelObserver) {
69 public:
70 Observer(RtcDataChannelHandler* handler,
71 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
72 webrtc::DataChannelInterface* channel);
73
74 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread() const;
75 const scoped_refptr<webrtc::DataChannelInterface>& channel() const;
76
77 void ClearHandler();
78
79 private:
80 friend class base::RefCountedThreadSafe<RtcDataChannelHandler::Observer>;
81 ~Observer() override;
82
83 // webrtc::DataChannelObserver implementation.
84 void OnStateChange() override;
85 void OnMessage(const webrtc::DataBuffer& buffer) override;
86
87 void OnStateChangeImpl(webrtc::DataChannelInterface::DataState state);
88 void OnMessageImpl(scoped_ptr<webrtc::DataBuffer> buffer);
89
90 RtcDataChannelHandler* handler_;
91 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
92 const scoped_refptr<webrtc::DataChannelInterface> channel_;
93 };
94
95 scoped_refptr<Observer> observer_;
96 base::ThreadChecker thread_checker_;
97
98 blink::WebRTCDataChannelHandlerClient* webkit_client_; 55 blink::WebRTCDataChannelHandlerClient* webkit_client_;
99 }; 56 };
100 57
101 } // namespace content 58 } // namespace content
102 59
103 #endif // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 60 #endif // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/rtc_data_channel_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698