OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 COMPONENTS_DEVTOOLS_BRIDGE_ABSTRACT_DATA_CHANNEL_H_ | |
6 #define COMPONENTS_DEVTOOLS_BRIDGE_ABSTRACT_DATA_CHANNEL_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/ref_counted.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 | |
14 namespace devtools_bridge { | |
15 | |
16 /** | |
17 * WebRTC DataChannel adapter for DevTools bridge. Not thread safe. | |
18 */ | |
19 class AbstractDataChannel { | |
20 public: | |
21 AbstractDataChannel() {} | |
22 virtual ~AbstractDataChannel() {} | |
23 | |
24 /** | |
25 * Called on WebRTC signaling thread. | |
26 */ | |
27 class Observer { | |
28 public: | |
29 Observer() {} | |
30 virtual ~Observer() {} | |
31 | |
32 virtual void OnOpen() = 0; | |
33 virtual void OnClose() = 0; | |
34 | |
35 virtual void OnMessage(const void* data, size_t length) = 0; | |
36 | |
37 private: | |
38 DISALLOW_COPY_AND_ASSIGN(Observer); | |
39 }; | |
40 | |
41 /** | |
42 * Proxy for accessing data channel from a different thread. | |
43 * May outlive data channel (methods will have no effect if DataChannel | |
44 * destroyed). | |
45 */ | |
46 class Proxy : public base::RefCountedThreadSafe<Proxy> { | |
47 public: | |
48 virtual void SendBinaryMessage(const void* data, size_t length) = 0; | |
49 virtual void Close() = 0; | |
50 | |
51 protected: | |
52 Proxy() {} | |
53 virtual ~Proxy() {} | |
54 | |
55 private: | |
56 friend class base::RefCountedThreadSafe<Proxy>; | |
57 | |
58 DISALLOW_COPY_AND_ASSIGN(Proxy); | |
59 }; | |
60 | |
61 virtual void RegisterObserver(scoped_ptr<Observer> observer) = 0; | |
62 virtual void UnregisterObserver() = 0; | |
63 | |
64 virtual void SendBinaryMessage(void* data, size_t length) = 0; | |
65 virtual void SendTextMessage(void* data, size_t length) = 0; | |
66 | |
67 virtual void Close() = 0; | |
68 | |
69 virtual scoped_refptr<Proxy> proxy() = 0; | |
70 | |
71 private: | |
72 DISALLOW_COPY_AND_ASSIGN(AbstractDataChannel); | |
73 }; | |
74 | |
75 } // namespace devtools_bridge | |
76 | |
77 #endif // COMPONENTS_DEVTOOLS_BRIDGE_ABSTRACT_DATA_CHANNEL_H_ | |
OLD | NEW |