Index: google_apis/gcm/engine/connection_handler_impl.h |
diff --git a/google_apis/gcm/engine/connection_handler.h b/google_apis/gcm/engine/connection_handler_impl.h |
similarity index 61% |
copy from google_apis/gcm/engine/connection_handler.h |
copy to google_apis/gcm/engine/connection_handler_impl.h |
index 6dd838c86946473e583c01be2850cdbd05c6f096..110cdcdddda51d7e228fb30bb73fef25799dc68e 100644 |
--- a/google_apis/gcm/engine/connection_handler.h |
+++ b/google_apis/gcm/engine/connection_handler_impl.h |
@@ -2,43 +2,22 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_ |
-#define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_ |
+#ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |
+#define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |
#include "base/memory/weak_ptr.h" |
+#include "base/time/time.h" |
#include "base/timer/timer.h" |
-#include "google_apis/gcm/base/gcm_export.h" |
-#include "google_apis/gcm/protocol/mcs.pb.h" |
+#include "google_apis/gcm/engine/connection_handler.h" |
-namespace net{ |
-class StreamSocket; |
-} |
+namespace mcs_proto { |
+class LoginRequest; |
+} // namespace mcs_proto |
namespace gcm { |
-class SocketInputStream; |
-class SocketOutputStream; |
- |
-// Handles performing the protocol handshake and sending/receiving protobuf |
-// messages. Note that no retrying or queueing is enforced at this layer. |
-// Once a connection error is encountered, the ConnectionHandler will disconnect |
-// the socket and must be reinitialized with a new StreamSocket before |
-// messages can be sent/received again. |
-class GCM_EXPORT ConnectionHandler { |
+class GCM_EXPORT ConnectionHandlerImpl : public ConnectionHandler { |
public: |
- typedef base::Callback<void(scoped_ptr<google::protobuf::MessageLite>)> |
- ProtoReceivedCallback; |
- typedef base::Closure ProtoSentCallback; |
- typedef base::Callback<void(int)> ConnectionChangedCallback; |
- |
- explicit ConnectionHandler(base::TimeDelta read_timeout); |
- ~ConnectionHandler(); |
- |
- // Starts a new MCS connection handshake (using |login_request|) and, upon |
- // success, begins listening for incoming/outgoing messages. A successful |
- // handshake is when a mcs_proto::LoginResponse is received, and is signaled |
- // via the |read_callback|. |
- // Outputs: |
// |read_callback| will be invoked with the contents of any received protobuf |
// message. |
// |write_callback| will be invoked anytime a message has been successfully |
@@ -46,21 +25,19 @@ class GCM_EXPORT ConnectionHandler { |
// other end received it. |
// |connection_callback| will be invoked with any fatal read/write errors |
// encountered. |
- // |
- // Note: It is correct and expected to call Init more than once, as connection |
- // issues are encountered and new connections must be made. |
- void Init(scoped_ptr<net::StreamSocket> socket, |
- const google::protobuf::MessageLite& login_request, |
- const ProtoReceivedCallback& read_callback, |
- const ProtoSentCallback& write_callback, |
- const ConnectionChangedCallback& connection_callback); |
- |
- // Checks that a handshake has been completed and a message is not already |
- // in flight. |
- bool CanSendMessage() const; |
- |
- // Send an MCS protobuf message. CanSendMessage() must be true. |
- void SendMessage(const google::protobuf::MessageLite& message); |
+ ConnectionHandlerImpl( |
+ base::TimeDelta read_timeout, |
+ const ProtoReceivedCallback& read_callback, |
+ const ProtoSentCallback& write_callback, |
+ const ConnectionChangedCallback& connection_callback); |
+ virtual ~ConnectionHandlerImpl(); |
+ |
+ // ConnectionHandler implementation. |
+ virtual void Init(const mcs_proto::LoginRequest& login_request, |
+ scoped_ptr<net::StreamSocket> socket) OVERRIDE; |
+ virtual bool CanSendMessage() const OVERRIDE; |
+ virtual void SendMessage(const google::protobuf::MessageLite& message) |
+ OVERRIDE; |
private: |
// State machine for handling incoming data. See WaitForData(..) for usage. |
@@ -116,7 +93,7 @@ class GCM_EXPORT ConnectionHandler { |
// TODO(zea): consider enforcing a separate timeout when waiting for |
// a message to send. |
const base::TimeDelta read_timeout_; |
- base::OneShotTimer<ConnectionHandler> read_timeout_timer_; |
+ base::OneShotTimer<ConnectionHandlerImpl> read_timeout_timer_; |
// This connection's socket and the input/output streams attached to it. |
scoped_ptr<net::StreamSocket> socket_; |
@@ -135,11 +112,11 @@ class GCM_EXPORT ConnectionHandler { |
ProtoSentCallback write_callback_; |
ConnectionChangedCallback connection_callback_; |
- base::WeakPtrFactory<ConnectionHandler> weak_ptr_factory_; |
+ base::WeakPtrFactory<ConnectionHandlerImpl> weak_ptr_factory_; |
- DISALLOW_COPY_AND_ASSIGN(ConnectionHandler); |
+ DISALLOW_COPY_AND_ASSIGN(ConnectionHandlerImpl); |
}; |
} // namespace gcm |
-#endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_ |
+#endif // GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_IMPL_H_ |