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

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

Issue 689783002: Refactor RtcDataChannelHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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/threading/non_thread_safe.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/threading/thread_checker.h"
10 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
11 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h " 13 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
12 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h" 14 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h"
13 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" 15 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 // RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel 19 // RtcDataChannelHandler is a delegate for the RTC PeerConnection DataChannel
18 // API messages going between WebKit and native PeerConnection DataChannels in 20 // API messages going between WebKit and native PeerConnection DataChannels in
19 // libjingle. Instances of this class are owned by WebKit. 21 // libjingle. Instances of this class are owned by WebKit.
20 // WebKit call all of these methods on the main render thread. 22 // WebKit call all of these methods on the main render thread.
21 // Callbacks to the webrtc::DataChannelObserver implementation also occur on 23 // Callbacks to the webrtc::DataChannelObserver implementation also occur on
22 // the main render thread. 24 // the main render thread.
23 class CONTENT_EXPORT RtcDataChannelHandler 25 class CONTENT_EXPORT RtcDataChannelHandler
24 : NON_EXPORTED_BASE(public blink::WebRTCDataChannelHandler), 26 : 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 explicit RtcDataChannelHandler(webrtc::DataChannelInterface* channel); 28 // This object can* be constructed on libjingle's signaling thread and then
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);
29 virtual ~RtcDataChannelHandler(); 40 virtual ~RtcDataChannelHandler();
30 41
31 // blink::WebRTCDataChannelHandler implementation. 42 // blink::WebRTCDataChannelHandler implementation.
32 virtual void setClient( 43 virtual void setClient(
33 blink::WebRTCDataChannelHandlerClient* client) override; 44 blink::WebRTCDataChannelHandlerClient* client) override;
34 virtual blink::WebString label() override; 45 virtual blink::WebString label() override;
35 virtual bool isReliable() override; 46 virtual bool isReliable() override;
36 virtual bool ordered() const override; 47 virtual bool ordered() const override;
37 virtual unsigned short maxRetransmitTime() const override; 48 virtual unsigned short maxRetransmitTime() const override;
38 virtual unsigned short maxRetransmits() const override; 49 virtual unsigned short maxRetransmits() const override;
39 virtual blink::WebString protocol() const override; 50 virtual blink::WebString protocol() const override;
40 virtual bool negotiated() const override; 51 virtual bool negotiated() const override;
41 virtual unsigned short id() const override; 52 virtual unsigned short id() const override;
42 virtual unsigned long bufferedAmount() override; 53 virtual unsigned long bufferedAmount() override;
43 virtual bool sendStringData(const blink::WebString& data) override; 54 virtual bool sendStringData(const blink::WebString& data) override;
44 virtual bool sendRawData(const char* data, size_t length) override; 55 virtual bool sendRawData(const char* data, size_t length) override;
45 virtual void close() override; 56 virtual void close() override;
46 57
47 // webrtc::DataChannelObserver implementation. 58 const scoped_refptr<webrtc::DataChannelInterface>& channel() const;
48 void OnStateChange() override;
49 void OnMessage(const webrtc::DataBuffer& buffer) override;
50 59
51 private: 60 private:
61 void OnStateChange(webrtc::DataChannelInterface::DataState state);
62 void OnMessage(scoped_ptr<webrtc::DataBuffer> buffer);
52 void RecordMessageSent(size_t num_bytes); 63 void RecordMessageSent(size_t num_bytes);
53 64
54 scoped_refptr<webrtc::DataChannelInterface> channel_; 65 class CONTENT_EXPORT Observer
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
55 blink::WebRTCDataChannelHandlerClient* webkit_client_; 98 blink::WebRTCDataChannelHandlerClient* webkit_client_;
56 }; 99 };
57 100
58 } // namespace content 101 } // namespace content
59 102
60 #endif // CONTENT_RENDERER_MEDIA_RTC_DATA_CHANNEL_HANDLER_H_ 103 #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