Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1892)

Unified Diff: google_apis/gcm/engine/connection_handler.h

Issue 54743007: [GCM] Add connection factory for creating MCS connections (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: google_apis/gcm/engine/connection_handler.h
diff --git a/google_apis/gcm/engine/connection_handler.h b/google_apis/gcm/engine/connection_handler.h
index 6dd838c86946473e583c01be2850cdbd05c6f096..5b9ea715c7803d4ac9ec7ff9ba076ab4049c7101 100644
--- a/google_apis/gcm/engine/connection_handler.h
+++ b/google_apis/gcm/engine/connection_handler.h
@@ -5,13 +5,21 @@
#ifndef GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_
#define GOOGLE_APIS_GCM_ENGINE_CONNECTION_HANDLER_H_
-#include "base/memory/weak_ptr.h"
-#include "base/timer/timer.h"
+#include "base/callback.h"
#include "google_apis/gcm/base/gcm_export.h"
-#include "google_apis/gcm/protocol/mcs.pb.h"
namespace net{
class StreamSocket;
+} // namespace net
+
+namespace google {
+namespace protobuf {
+class MessageLite;
+} // namespace protobuf
+} // namepsace google
+
+namespace mcs_proto {
+class LoginRequest;
}
namespace gcm {
@@ -31,113 +39,23 @@ class GCM_EXPORT ConnectionHandler {
typedef base::Closure ProtoSentCallback;
typedef base::Callback<void(int)> ConnectionChangedCallback;
- explicit ConnectionHandler(base::TimeDelta read_timeout);
- ~ConnectionHandler();
+ ConnectionHandler();
+ virtual ~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
- // sent. Note: this just means the data was sent to the wire, not that the
- // other end received it.
- // |connection_callback| will be invoked with any fatal read/write errors
- // encountered.
+ // success, begins listening for incoming/outgoing messages.
//
// 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);
+ virtual void Init(const mcs_proto::LoginRequest& login_request,
+ scoped_ptr<net::StreamSocket> socket) = 0;
// Checks that a handshake has been completed and a message is not already
// in flight.
- bool CanSendMessage() const;
+ virtual bool CanSendMessage() const = 0;
// Send an MCS protobuf message. CanSendMessage() must be true.
- void SendMessage(const google::protobuf::MessageLite& message);
-
- private:
- // State machine for handling incoming data. See WaitForData(..) for usage.
- enum ProcessingState {
- // Processing the version, tag, and size packets (assuming minimum length
- // size packet). Only used during the login handshake.
- MCS_VERSION_TAG_AND_SIZE = 0,
- // Processing the tag and size packets (assuming minimum length size
- // packet). Used for normal messages.
- MCS_TAG_AND_SIZE,
- // Processing a maximum length size packet (for messages with length > 128).
- // Used when a normal size packet was not sufficient to read the message
- // size.
- MCS_FULL_SIZE,
- // Processing the protocol buffer bytes (for those messages with non-zero
- // sizes).
- MCS_PROTO_BYTES
- };
-
- // Sends the protocol version and login request. First step in the MCS
- // connection handshake.
- void Login(const google::protobuf::MessageLite& login_request);
-
- // SendMessage continuation. Invoked when Socket::Write completes.
- void OnMessageSent();
-
- // Starts the message processing process, which is comprised of the tag,
- // message size, and bytes packet types.
- void GetNextMessage();
-
- // Performs any necessary SocketInputStream refreshing until the data
- // associated with |packet_type| is fully ready, then calls the appropriate
- // OnGot* message to process the packet data. If the read times out,
- // will close the stream and invoke the connection callback.
- void WaitForData(ProcessingState state);
-
- // Incoming data helper methods.
- void OnGotVersion();
- void OnGotMessageTag();
- void OnGotMessageSize();
- void OnGotMessageBytes();
-
- // Timeout handler.
- void OnTimeout();
-
- // Closes the current connection.
- void CloseConnection();
-
- // Timeout policy: the timeout is only enforced while waiting on the
- // handshake (version and/or LoginResponse) or once at least a tag packet has
- // been received. It is reset every time new data is received, and is
- // only stopped when a full message is processed.
- // 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_;
-
- // This connection's socket and the input/output streams attached to it.
- scoped_ptr<net::StreamSocket> socket_;
- scoped_ptr<SocketInputStream> input_stream_;
- scoped_ptr<SocketOutputStream> output_stream_;
-
- // Whether the MCS login handshake has successfully completed. See Init(..)
- // description for more info on what the handshake involves.
- bool handshake_complete_;
-
- // State for the message currently being processed, if there is one.
- uint8 message_tag_;
- uint32 message_size_;
-
- ProtoReceivedCallback read_callback_;
- ProtoSentCallback write_callback_;
- ConnectionChangedCallback connection_callback_;
-
- base::WeakPtrFactory<ConnectionHandler> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(ConnectionHandler);
+ virtual void SendMessage(const google::protobuf::MessageLite& message) = 0;
};
} // namespace gcm
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl_unittest.cc ('k') | google_apis/gcm/engine/connection_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698