win: wstring->string16 in chrome/installer/util/html_dialog
[chromium-blink-merge.git] / remoting / protocol / channel_dispatcher_base.h
blob9a25cd0cfc6a111831056d5db144234dd3e3c35f
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
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
6 #define REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "remoting/base/buffered_socket_writer.h"
14 #include "remoting/protocol/errors.h"
15 #include "remoting/protocol/message_reader.h"
17 namespace net {
18 class StreamSocket;
19 } // namespace net
21 namespace remoting {
22 namespace protocol {
24 struct ChannelConfig;
25 class StreamChannelFactory;
26 class Session;
28 // Base class for channel message dispatchers. It's responsible for
29 // creating the named channel. Derived dispatchers then dispatch
30 // incoming messages on this channel as well as send outgoing
31 // messages.
32 class ChannelDispatcherBase {
33 public:
34 class EventHandler {
35 public:
36 EventHandler() {}
37 virtual ~EventHandler() {}
39 virtual void OnChannelInitialized(
40 ChannelDispatcherBase* channel_dispatcher) = 0;
41 virtual void OnChannelError(ChannelDispatcherBase* channel_dispatcher,
42 ErrorCode error) = 0;
45 // The callback is called when initialization is finished. The
46 // parameter is set to true on success.
47 typedef base::Callback<void(bool)> InitializedCallback;
49 virtual ~ChannelDispatcherBase();
51 // Creates and connects the channel in the specified
52 // |session|. Caller retains ownership of the Session.
53 void Init(Session* session,
54 const ChannelConfig& config,
55 EventHandler* event_handler);
57 const std::string& channel_name() { return channel_name_; }
59 // Returns true if the channel is currently connected.
60 bool is_connected() { return channel_ != nullptr; }
62 protected:
63 explicit ChannelDispatcherBase(const char* channel_name);
65 BufferedSocketWriter* writer() { return &writer_; }
66 MessageReader* reader() { return &reader_; }
68 private:
69 void OnChannelReady(scoped_ptr<net::StreamSocket> socket);
70 void OnWriteFailed(int error);
72 std::string channel_name_;
73 StreamChannelFactory* channel_factory_;
74 EventHandler* event_handler_;
75 scoped_ptr<net::StreamSocket> channel_;
77 BufferedSocketWriter writer_;
78 MessageReader reader_;
80 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase);
83 } // namespace protocol
84 } // namespace remoting
86 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_