Reland r247589: <webview>: Fix text selection features in mac.
[chromium-blink-merge.git] / remoting / protocol / channel_dispatcher_base.h
blob906d0f9bb2da1cc7e85512d80d5b949f03060622
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"
14 namespace net {
15 class StreamSocket;
16 } // namespace net
18 namespace remoting {
19 namespace protocol {
21 struct ChannelConfig;
22 class ChannelFactory;
23 class Session;
25 // Base class for channel message dispatchers. It's responsible for
26 // creating the named channel. Derived dispatchers then dispatch
27 // incoming messages on this channel as well as send outgoing
28 // messages.
29 class ChannelDispatcherBase {
30 public:
31 // The callback is called when initialization is finished. The
32 // parameter is set to true on success.
33 typedef base::Callback<void(bool)> InitializedCallback;
35 virtual ~ChannelDispatcherBase();
37 // Creates and connects the channel in the specified
38 // |session|. Caller retains ownership of the Session.
39 void Init(Session* session,
40 const ChannelConfig& config,
41 const InitializedCallback& callback);
43 // Returns true if the channel is currently connected.
44 bool is_connected() { return channel() != NULL; }
46 protected:
47 explicit ChannelDispatcherBase(const char* channel_name);
49 net::StreamSocket* channel() { return channel_.get(); }
51 // Called when channel is initialized. Must be overriden in the
52 // child classes. Should not delete the dispatcher.
53 virtual void OnInitialized() = 0;
55 private:
56 void OnChannelReady(scoped_ptr<net::StreamSocket> socket);
58 std::string channel_name_;
59 ChannelFactory* channel_factory_;
60 InitializedCallback initialized_callback_;
61 scoped_ptr<net::StreamSocket> channel_;
63 DISALLOW_COPY_AND_ASSIGN(ChannelDispatcherBase);
66 } // namespace protocol
67 } // namespace remoting
69 #endif // REMOTING_PROTOCOL_CHANNEL_DISPATCHER_BASE_H_