namespace gcm {
+class CollapseKey;
class ConnectionFactory;
struct ReliablePacketInfo;
};
enum MessageSendStatus {
- // Message sent succcessfully.
- SUCCESS,
+ // Message was queued succcessfully.
+ QUEUED,
+ // Message was sent to the server and the ACK was received.
+ SENT,
// Message not saved, because total queue size limit reached.
QUEUE_SIZE_LIMIT_REACHED,
// Messgae not saved, because app queue size limit reached.
const std::string& message_id,
MessageSendStatus status)> OnMessageSentCallback;
- MCSClient(base::Clock* clock,
+ MCSClient(const std::string& version_string,
+ base::Clock* clock,
ConnectionFactory* connection_factory,
GCMStore* gcm_store);
virtual ~MCSClient();
// with a valid LoginResponse.
// Login failure (typically invalid id/token) will shut down the client, and
// |initialization_callback| to be invoked with |success = false|.
- void Login(uint64 android_id, uint64 security_token);
+ virtual void Login(uint64 android_id, uint64 security_token);
// Sends a message, with or without reliable message queueing (RMQ) support.
// Will asynchronously invoke the OnMessageSent callback regardless.
// open. |ttl > 0| will keep the message saved for |ttl| seconds, after which
// it will be dropped if it was unable to be sent. When a message is dropped,
// |message_sent_callback_| is invoked with a TTL expiration error.
- void SendMessage(const MCSMessage& message);
+ virtual void SendMessage(const MCSMessage& message);
// Disconnects the client and permanently destroys the persistent GCM store.
// WARNING: This is permanent, and the client must be recreated with new
// credentials afterwards.
+ // TODO(jianli): destroying the persistent GCM store should be moved to
+ // GCMClient.
void Destroy();
// Returns the current state of the client.
State state() const { return state_; }
+ protected:
+ // Sets a |gcm_store| for testing. Does not take ownership.
+ // TODO(fgorski): Remove this method. Create GCMEngineFactory that will create
+ // components of the engine.
+ void SetGCMStoreForTesting(GCMStore* gcm_store);
+
private:
typedef uint32 StreamId;
typedef std::string PersistentId;
void NotifyMessageSendStatus(const google::protobuf::MessageLite& protobuf,
MessageSendStatus status);
+ // Pops the next message from the front of the send queue (cleaning up
+ // any associated state).
+ MCSPacketInternal PopMessageForSend();
+
+ // Local version string. Sent on login.
+ const std::string version_string_;
+
// Clock for enforcing TTL. Passed in for testing.
base::Clock* const clock_;
std::deque<MCSPacketInternal> to_send_;
std::deque<MCSPacketInternal> to_resend_;
+ // Map of collapse keys to their pending messages.
+ std::map<CollapseKey, ReliablePacketInfo*> collapse_key_map_;
+
// Last device_to_server stream id acknowledged by the server.
StreamId last_device_to_server_stream_id_received_;
// Last server_to_device stream id acknowledged by this device.