Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / google_apis / gcm / engine / connection_handler.h
blob7b265f9d3bc0321f14d1e660d4e6525c62251ad2
1 // Copyright 2013 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 GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_
6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_
8 #include "base/callback.h"
9 #include "google_apis/gcm/base/gcm_export.h"
11 namespace net{
12 class StreamSocket;
13 } // namespace net
15 namespace google {
16 namespace protobuf {
17 class MessageLite;
18 } // namespace protobuf
19 } // namepsace google
21 namespace mcs_proto {
22 class LoginRequest;
25 namespace gcm {
27 class SocketInputStream;
28 class SocketOutputStream;
30 // Handles performing the protocol handshake and sending/receiving protobuf
31 // messages. Note that no retrying or queueing is enforced at this layer.
32 // Once a connection error is encountered, the ConnectionHandler will disconnect
33 // the socket and must be reinitialized with a new StreamSocket before
34 // messages can be sent/received again.
35 class GCM_EXPORT ConnectionHandler {
36 public:
37 typedef base::Callback<void(scoped_ptr<google::protobuf::MessageLite>)>
38 ProtoReceivedCallback;
39 typedef base::Closure ProtoSentCallback;
40 typedef base::Callback<void(int)> ConnectionChangedCallback;
42 ConnectionHandler();
43 virtual ~ConnectionHandler();
45 // Starts a new MCS connection handshake (using |login_request|) and, upon
46 // success, begins listening for incoming/outgoing messages.
48 // Note: It is correct and expected to call Init more than once, as connection
49 // issues are encountered and new connections must be made.
50 virtual void Init(const mcs_proto::LoginRequest& login_request,
51 net::StreamSocket* socket) = 0;
53 // Resets the handler and any internal state. Should be called any time
54 // a connection reset happens externally to the handler.
55 virtual void Reset() = 0;
57 // Checks that a handshake has been completed and a message is not already
58 // in flight.
59 virtual bool CanSendMessage() const = 0;
61 // Send an MCS protobuf message. CanSendMessage() must be true.
62 virtual void SendMessage(const google::protobuf::MessageLite& message) = 0;
65 } // namespace gcm
67 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_