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

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

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

Powered by Google App Engine
This is Rietveld 408576698