Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / google_apis / gcm / engine / mcs_client.h
index 1b27950..a81643b 100644 (file)
@@ -35,6 +35,7 @@ class LoginRequest;
 
 namespace gcm {
 
+class CollapseKey;
 class ConnectionFactory;
 struct ReliablePacketInfo;
 
@@ -52,8 +53,10 @@ class GCM_EXPORT MCSClient {
   };
 
   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.
@@ -81,7 +84,8 @@ class GCM_EXPORT MCSClient {
            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();
@@ -107,7 +111,7 @@ class GCM_EXPORT 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.
@@ -116,16 +120,24 @@ class GCM_EXPORT MCSClient {
   // 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;
@@ -182,6 +194,13 @@ class GCM_EXPORT MCSClient {
   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_;
 
@@ -212,6 +231,9 @@ class GCM_EXPORT MCSClient {
   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.