| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |
| 6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // encountered. | 27 // encountered. |
| 28 ConnectionHandlerImpl( | 28 ConnectionHandlerImpl( |
| 29 base::TimeDelta read_timeout, | 29 base::TimeDelta read_timeout, |
| 30 const ProtoReceivedCallback& read_callback, | 30 const ProtoReceivedCallback& read_callback, |
| 31 const ProtoSentCallback& write_callback, | 31 const ProtoSentCallback& write_callback, |
| 32 const ConnectionChangedCallback& connection_callback); | 32 const ConnectionChangedCallback& connection_callback); |
| 33 virtual ~ConnectionHandlerImpl(); | 33 virtual ~ConnectionHandlerImpl(); |
| 34 | 34 |
| 35 // ConnectionHandler implementation. | 35 // ConnectionHandler implementation. |
| 36 virtual void Init(const mcs_proto::LoginRequest& login_request, | 36 virtual void Init(const mcs_proto::LoginRequest& login_request, |
| 37 scoped_ptr<net::StreamSocket> socket) OVERRIDE; | 37 net::StreamSocket* socket) OVERRIDE; |
| 38 virtual bool CanSendMessage() const OVERRIDE; | 38 virtual bool CanSendMessage() const OVERRIDE; |
| 39 virtual void SendMessage(const google::protobuf::MessageLite& message) | 39 virtual void SendMessage(const google::protobuf::MessageLite& message) |
| 40 OVERRIDE; | 40 OVERRIDE; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 // State machine for handling incoming data. See WaitForData(..) for usage. | 43 // State machine for handling incoming data. See WaitForData(..) for usage. |
| 44 enum ProcessingState { | 44 enum ProcessingState { |
| 45 // Processing the version, tag, and size packets (assuming minimum length | 45 // Processing the version, tag, and size packets (assuming minimum length |
| 46 // size packet). Only used during the login handshake. | 46 // size packet). Only used during the login handshake. |
| 47 MCS_VERSION_TAG_AND_SIZE = 0, | 47 MCS_VERSION_TAG_AND_SIZE = 0, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // Timeout policy: the timeout is only enforced while waiting on the | 89 // Timeout policy: the timeout is only enforced while waiting on the |
| 90 // handshake (version and/or LoginResponse) or once at least a tag packet has | 90 // handshake (version and/or LoginResponse) or once at least a tag packet has |
| 91 // been received. It is reset every time new data is received, and is | 91 // been received. It is reset every time new data is received, and is |
| 92 // only stopped when a full message is processed. | 92 // only stopped when a full message is processed. |
| 93 // TODO(zea): consider enforcing a separate timeout when waiting for | 93 // TODO(zea): consider enforcing a separate timeout when waiting for |
| 94 // a message to send. | 94 // a message to send. |
| 95 const base::TimeDelta read_timeout_; | 95 const base::TimeDelta read_timeout_; |
| 96 base::OneShotTimer<ConnectionHandlerImpl> read_timeout_timer_; | 96 base::OneShotTimer<ConnectionHandlerImpl> read_timeout_timer_; |
| 97 | 97 |
| 98 // This connection's socket and the input/output streams attached to it. | 98 // This connection's socket and the input/output streams attached to it. |
| 99 scoped_ptr<net::StreamSocket> socket_; | 99 net::StreamSocket* socket_; |
| 100 scoped_ptr<SocketInputStream> input_stream_; | 100 scoped_ptr<SocketInputStream> input_stream_; |
| 101 scoped_ptr<SocketOutputStream> output_stream_; | 101 scoped_ptr<SocketOutputStream> output_stream_; |
| 102 | 102 |
| 103 // Whether the MCS login handshake has successfully completed. See Init(..) | 103 // Whether the MCS login handshake has successfully completed. See Init(..) |
| 104 // description for more info on what the handshake involves. | 104 // description for more info on what the handshake involves. |
| 105 bool handshake_complete_; | 105 bool handshake_complete_; |
| 106 | 106 |
| 107 // State for the message currently being processed, if there is one. | 107 // State for the message currently being processed, if there is one. |
| 108 uint8 message_tag_; | 108 uint8 message_tag_; |
| 109 uint32 message_size_; | 109 uint32 message_size_; |
| 110 | 110 |
| 111 ProtoReceivedCallback read_callback_; | 111 ProtoReceivedCallback read_callback_; |
| 112 ProtoSentCallback write_callback_; | 112 ProtoSentCallback write_callback_; |
| 113 ConnectionChangedCallback connection_callback_; | 113 ConnectionChangedCallback connection_callback_; |
| 114 | 114 |
| 115 base::WeakPtrFactory<ConnectionHandlerImpl> weak_ptr_factory_; | 115 base::WeakPtrFactory<ConnectionHandlerImpl> weak_ptr_factory_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(ConnectionHandlerImpl); | 117 DISALLOW_COPY_AND_ASSIGN(ConnectionHandlerImpl); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace gcm | 120 } // namespace gcm |
| 121 | 121 |
| 122 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ | 122 #endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |
| OLD | NEW |