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

Side by Side Diff: remoting/protocol/channel_dispatcher_base.h

Issue 2146213002: Add support for dynamic channels in WebrtcTransport. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
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 REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ 5 #ifndef REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ 6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "remoting/protocol/errors.h" 13 #include "remoting/protocol/errors.h"
14 #include "remoting/protocol/message_pipe.h"
14 15
15 namespace remoting { 16 namespace remoting {
16 17
17 class CompoundBuffer; 18 class CompoundBuffer;
18 19
19 namespace protocol { 20 namespace protocol {
20 21
21 class MessageChannelFactory; 22 class MessageChannelFactory;
22 class MessagePipe;
23 23
24 // Base class for channel message dispatchers. It's responsible for 24 // Base class for channel message dispatchers. It's responsible for
25 // creating the named channel. Derived dispatchers then dispatch 25 // creating the named channel. Derived dispatchers then dispatch
26 // incoming messages on this channel as well as send outgoing 26 // incoming messages on this channel as well as send outgoing
27 // messages. 27 // messages.
28 class ChannelDispatcherBase { 28 class ChannelDispatcherBase : public MessagePipe::EventHandler {
29 public: 29 public:
30 class EventHandler { 30 class EventHandler {
31 public: 31 public:
32 EventHandler() {} 32 EventHandler() {}
33 virtual ~EventHandler() {} 33 virtual ~EventHandler() {}
34 34
35 // Called after the channel is initialized.
35 virtual void OnChannelInitialized( 36 virtual void OnChannelInitialized(
36 ChannelDispatcherBase* channel_dispatcher) = 0; 37 ChannelDispatcherBase* channel_dispatcher) = 0;
38
39 // Called after the channel is closed.
40 virtual void OnChannelClosed(ChannelDispatcherBase* channel_dispatcher) = 0;
37 }; 41 };
38 42
39 // The callback is called when initialization is finished. The 43 // The callback is called when initialization is finished. The
40 // parameter is set to true on success. 44 // parameter is set to true on success.
41 typedef base::Callback<void(bool)> InitializedCallback; 45 typedef base::Callback<void(bool)> InitializedCallback;
42 46
43 virtual ~ChannelDispatcherBase(); 47 ~ChannelDispatcherBase() override;
44 48
45 // Creates and connects the channel in the specified 49 // Creates and connects the channel using |channel_factory|.
46 // |session|. Caller retains ownership of the Session.
47 void Init(MessageChannelFactory* channel_factory, 50 void Init(MessageChannelFactory* channel_factory,
48 EventHandler* event_handler); 51 EventHandler* event_handler);
49 52
53 // Initialized the channel using |message_pipe| that's already connected.
Jamie 2016/07/19 18:24:47 s/Initialized/Initializes/
Sergey Ulanov 2016/07/19 23:38:43 Done.
54 void Init(std::unique_ptr<MessagePipe> message_pipe,
55 EventHandler* event_handler);
56
50 const std::string& channel_name() { return channel_name_; } 57 const std::string& channel_name() { return channel_name_; }
51 58
52 // Returns true if the channel is currently connected. 59 // Returns true if the channel is currently connected.
53 bool is_connected() { return message_pipe() != nullptr; } 60 bool is_connected() { return message_pipe() != nullptr; }
54 61
55 protected: 62 protected:
56 explicit ChannelDispatcherBase(const char* channel_name); 63 explicit ChannelDispatcherBase(const char* channel_name);
57 64
58 MessagePipe* message_pipe() { return message_pipe_.get(); } 65 MessagePipe* message_pipe() { return message_pipe_.get(); }
59 66
60 // Child classes must override this method to handle incoming messages. 67 // Child classes must override this method to handle incoming messages.
61 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message) = 0; 68 virtual void OnIncomingMessage(std::unique_ptr<CompoundBuffer> message) = 0;
62 69
63 private: 70 private:
64 void OnChannelReady(std::unique_ptr<MessagePipe> message_pipe); 71 void OnChannelReady(std::unique_ptr<MessagePipe> message_pipe);
65 void OnPipeError(int error); 72
73 // MessagePipe::EventHandler interface.
74 void OnMessageReceived(std::unique_ptr<CompoundBuffer> message) override;
75 void OnMessagePipeClosed() override;
66 76
67 std::string channel_name_; 77 std::string channel_name_;
68 MessageChannelFactory* channel_factory_ = nullptr; 78 MessageChannelFactory* channel_factory_ = nullptr;
69 EventHandler* event_handler_ = nullptr; 79 EventHandler* event_handler_ = nullptr;
70 80
71 std::unique_ptr<MessagePipe> message_pipe_; 81 std::unique_ptr<MessagePipe> message_pipe_;
72 82
73 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); 83 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase);
74 }; 84 };
75 85
76 } // namespace protocol 86 } // namespace protocol
77 } // namespace remoting 87 } // namespace remoting
78 88
79 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ 89 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | remoting/protocol/channel_dispatcher_base.cc » ('j') | remoting/protocol/message_pipe.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698