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

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

Issue 1649063003: Add MessagePipe interface. Use it in ChannelDispatcherBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simple_parser
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 | « remoting/protocol/audio_writer.cc ('k') | 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" 13 #include "remoting/base/buffered_socket_writer.h"
14 #include "remoting/protocol/errors.h" 14 #include "remoting/protocol/errors.h"
15 #include "remoting/protocol/message_reader.h"
16 15
17 namespace remoting { 16 namespace remoting {
17
18 class CompoundBuffer;
19
18 namespace protocol { 20 namespace protocol {
19 21
22 class MessagePipe;
23 class P2PStreamSocket;
20 class StreamChannelFactory; 24 class StreamChannelFactory;
21 25
22 // Base class for channel message dispatchers. It's responsible for 26 // Base class for channel message dispatchers. It's responsible for
23 // creating the named channel. Derived dispatchers then dispatch 27 // creating the named channel. Derived dispatchers then dispatch
24 // incoming messages on this channel as well as send outgoing 28 // incoming messages on this channel as well as send outgoing
25 // messages. 29 // messages.
26 class ChannelDispatcherBase { 30 class ChannelDispatcherBase {
27 public: 31 public:
28 class EventHandler { 32 class EventHandler {
29 public: 33 public:
(...skipping 12 matching lines...) Expand all
42 46
43 virtual ~ChannelDispatcherBase(); 47 virtual ~ChannelDispatcherBase();
44 48
45 // Creates and connects the channel in the specified 49 // Creates and connects the channel in the specified
46 // |session|. Caller retains ownership of the Session. 50 // |session|. Caller retains ownership of the Session.
47 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler); 51 void Init(StreamChannelFactory* channel_factory, EventHandler* event_handler);
48 52
49 const std::string& channel_name() { return channel_name_; } 53 const std::string& channel_name() { return channel_name_; }
50 54
51 // Returns true if the channel is currently connected. 55 // Returns true if the channel is currently connected.
52 bool is_connected() { return channel_ != nullptr; } 56 bool is_connected() { return message_pipe() != nullptr; }
53 57
54 protected: 58 protected:
55 explicit ChannelDispatcherBase(const char* channel_name); 59 explicit ChannelDispatcherBase(const char* channel_name);
56 60
57 BufferedSocketWriter* writer() { return &writer_; } 61 MessagePipe* message_pipe() { return message_pipe_.get(); }
58 62
59 // Child classes must override this method to handle incoming messages. 63 // Child classes must override this method to handle incoming messages.
60 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message) = 0; 64 virtual void OnIncomingMessage(scoped_ptr<CompoundBuffer> message) = 0;
61 65
62 private: 66 private:
63 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket); 67 void OnChannelReady(scoped_ptr<P2PStreamSocket> socket);
64 void OnReadWriteFailed(int error); 68 void OnPipeError(int error);
65 69
66 std::string channel_name_; 70 std::string channel_name_;
67 StreamChannelFactory* channel_factory_; 71 StreamChannelFactory* channel_factory_;
68 EventHandler* event_handler_; 72 EventHandler* event_handler_;
69 scoped_ptr<P2PStreamSocket> channel_;
70 73
71 BufferedSocketWriter writer_; 74 scoped_ptr<MessagePipe> message_pipe_;
72 MessageReader reader_;
73 75
74 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase); 76 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase);
75 }; 77 };
76 78
77 } // namespace protocol 79 } // namespace protocol
78 } // namespace remoting 80 } // namespace remoting
79 81
80 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_ 82 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
OLDNEW
« no previous file with comments | « remoting/protocol/audio_writer.cc ('k') | remoting/protocol/channel_dispatcher_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698