| 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_MCS_CLIENT_H_ | 5 #ifndef GOOGLE_APIS_GCM_ENGINE_MCS_CLIENT_H_ | 
| 6 #define GOOGLE_APIS_GCM_ENGINE_MCS_CLIENT_H_ | 6 #define GOOGLE_APIS_GCM_ENGINE_MCS_CLIENT_H_ | 
| 7 | 7 | 
|  | 8 #include <stdint.h> | 
|  | 9 | 
| 8 #include <deque> | 10 #include <deque> | 
| 9 #include <map> | 11 #include <map> | 
| 10 #include <string> | 12 #include <string> | 
| 11 #include <vector> | 13 #include <vector> | 
| 12 | 14 | 
| 13 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" | 
|  | 16 #include "base/macros.h" | 
| 14 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" | 
| 15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" | 
| 16 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" | 
| 17 #include "google_apis/gcm/base/gcm_export.h" | 20 #include "google_apis/gcm/base/gcm_export.h" | 
| 18 #include "google_apis/gcm/base/mcs_message.h" | 21 #include "google_apis/gcm/base/mcs_message.h" | 
| 19 #include "google_apis/gcm/engine/connection_factory.h" | 22 #include "google_apis/gcm/engine/connection_factory.h" | 
| 20 #include "google_apis/gcm/engine/connection_handler.h" | 23 #include "google_apis/gcm/engine/connection_handler.h" | 
| 21 #include "google_apis/gcm/engine/gcm_store.h" | 24 #include "google_apis/gcm/engine/gcm_store.h" | 
| 22 #include "google_apis/gcm/engine/heartbeat_manager.h" | 25 #include "google_apis/gcm/engine/heartbeat_manager.h" | 
| 23 | 26 | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 84 | 87 | 
| 85   // Callback for MCSClient's error conditions. | 88   // Callback for MCSClient's error conditions. | 
| 86   // TODO(fgorski): Keeping it as a callback with intention to add meaningful | 89   // TODO(fgorski): Keeping it as a callback with intention to add meaningful | 
| 87   // error information. | 90   // error information. | 
| 88   typedef base::Callback<void()> ErrorCallback; | 91   typedef base::Callback<void()> ErrorCallback; | 
| 89   // Callback when a message is received. | 92   // Callback when a message is received. | 
| 90   typedef base::Callback<void(const MCSMessage& message)> | 93   typedef base::Callback<void(const MCSMessage& message)> | 
| 91       OnMessageReceivedCallback; | 94       OnMessageReceivedCallback; | 
| 92   // Callback when a message is sent (and receipt has been acknowledged by | 95   // Callback when a message is sent (and receipt has been acknowledged by | 
| 93   // the MCS endpoint). | 96   // the MCS endpoint). | 
| 94   typedef base::Callback< | 97   typedef base::Callback<void(int64_t user_serial_number, | 
| 95       void(int64 user_serial_number, | 98                               const std::string& app_id, | 
| 96            const std::string& app_id, | 99                               const std::string& message_id, | 
| 97            const std::string& message_id, | 100                               MessageSendStatus status)> OnMessageSentCallback; | 
| 98            MessageSendStatus status)> OnMessageSentCallback; |  | 
| 99 | 101 | 
| 100   MCSClient(const std::string& version_string, | 102   MCSClient(const std::string& version_string, | 
| 101             base::Clock* clock, | 103             base::Clock* clock, | 
| 102             ConnectionFactory* connection_factory, | 104             ConnectionFactory* connection_factory, | 
| 103             GCMStore* gcm_store, | 105             GCMStore* gcm_store, | 
| 104             GCMStatsRecorder* recorder); | 106             GCMStatsRecorder* recorder); | 
| 105   virtual ~MCSClient(); | 107   virtual ~MCSClient(); | 
| 106 | 108 | 
| 107   // Initialize the client. Will load any previous id/token information as well | 109   // Initialize the client. Will load any previous id/token information as well | 
| 108   // as unacknowledged message information from the GCM storage, if it exists, | 110   // as unacknowledged message information from the GCM storage, if it exists, | 
| 109   // passing the id/token information back via |initialization_callback| along | 111   // passing the id/token information back via |initialization_callback| along | 
| 110   // with a |success == true| result. If no GCM information is present (and | 112   // with a |success == true| result. If no GCM information is present (and | 
| 111   // this is therefore a fresh client), a clean GCM store will be created and | 113   // this is therefore a fresh client), a clean GCM store will be created and | 
| 112   // values of 0 will be returned via |initialization_callback| with | 114   // values of 0 will be returned via |initialization_callback| with | 
| 113   // |success == true|. | 115   // |success == true|. | 
| 114   // If an error loading the GCM store is encountered, | 116   // If an error loading the GCM store is encountered, | 
| 115   // |initialization_callback| will be invoked with |success == false|. | 117   // |initialization_callback| will be invoked with |success == false|. | 
| 116   void Initialize(const ErrorCallback& initialization_callback, | 118   void Initialize(const ErrorCallback& initialization_callback, | 
| 117                   const OnMessageReceivedCallback& message_received_callback, | 119                   const OnMessageReceivedCallback& message_received_callback, | 
| 118                   const OnMessageSentCallback& message_sent_callback, | 120                   const OnMessageSentCallback& message_sent_callback, | 
| 119                   scoped_ptr<GCMStore::LoadResult> load_result); | 121                   scoped_ptr<GCMStore::LoadResult> load_result); | 
| 120 | 122 | 
| 121   // Logs the client into the server. Client must be initialized. | 123   // Logs the client into the server. Client must be initialized. | 
| 122   // |android_id| and |security_token| are optional if this is not a new | 124   // |android_id| and |security_token| are optional if this is not a new | 
| 123   // client, else they must be non-zero. | 125   // client, else they must be non-zero. | 
| 124   // Successful login will result in |message_received_callback| being invoked | 126   // Successful login will result in |message_received_callback| being invoked | 
| 125   // with a valid LoginResponse. | 127   // with a valid LoginResponse. | 
| 126   // Login failure (typically invalid id/token) will shut down the client, and | 128   // Login failure (typically invalid id/token) will shut down the client, and | 
| 127   // |initialization_callback| to be invoked with |success = false|. | 129   // |initialization_callback| to be invoked with |success = false|. | 
| 128   virtual void Login(uint64 android_id, uint64 security_token); | 130   virtual void Login(uint64_t android_id, uint64_t security_token); | 
| 129 | 131 | 
| 130   // Sends a message, with or without reliable message queueing (RMQ) support. | 132   // Sends a message, with or without reliable message queueing (RMQ) support. | 
| 131   // Will asynchronously invoke the OnMessageSent callback regardless. | 133   // Will asynchronously invoke the OnMessageSent callback regardless. | 
| 132   // Whether to use RMQ depends on whether the protobuf has |ttl| set or not. | 134   // Whether to use RMQ depends on whether the protobuf has |ttl| set or not. | 
| 133   // |ttl == 0| denotes the message should only be sent if the connection is | 135   // |ttl == 0| denotes the message should only be sent if the connection is | 
| 134   // open. |ttl > 0| will keep the message saved for |ttl| seconds, after which | 136   // open. |ttl > 0| will keep the message saved for |ttl| seconds, after which | 
| 135   // it will be dropped if it was unable to be sent. When a message is dropped, | 137   // it will be dropped if it was unable to be sent. When a message is dropped, | 
| 136   // |message_sent_callback_| is invoked with a TTL expiration error. | 138   // |message_sent_callback_| is invoked with a TTL expiration error. | 
| 137   virtual void SendMessage(const MCSMessage& message); | 139   virtual void SendMessage(const MCSMessage& message); | 
| 138 | 140 | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 158   // to be between GetMax/GetMinClientHeartbeatIntervalMs of HeartbeatManager, | 160   // to be between GetMax/GetMinClientHeartbeatIntervalMs of HeartbeatManager, | 
| 159   // otherwise the setting won't take effect. | 161   // otherwise the setting won't take effect. | 
| 160   void AddHeartbeatInterval(const std::string& scope, int interval_ms); | 162   void AddHeartbeatInterval(const std::string& scope, int interval_ms); | 
| 161   void RemoveHeartbeatInterval(const std::string& scope); | 163   void RemoveHeartbeatInterval(const std::string& scope); | 
| 162 | 164 | 
| 163   HeartbeatManager* GetHeartbeatManagerForTesting() { | 165   HeartbeatManager* GetHeartbeatManagerForTesting() { | 
| 164     return &heartbeat_manager_; | 166     return &heartbeat_manager_; | 
| 165   } | 167   } | 
| 166 | 168 | 
| 167  private: | 169  private: | 
| 168   typedef uint32 StreamId; | 170   typedef uint32_t StreamId; | 
| 169   typedef std::string PersistentId; | 171   typedef std::string PersistentId; | 
| 170   typedef std::vector<StreamId> StreamIdList; | 172   typedef std::vector<StreamId> StreamIdList; | 
| 171   typedef std::vector<PersistentId> PersistentIdList; | 173   typedef std::vector<PersistentId> PersistentIdList; | 
| 172   typedef std::map<StreamId, PersistentId> StreamIdToPersistentIdMap; | 174   typedef std::map<StreamId, PersistentId> StreamIdToPersistentIdMap; | 
| 173   typedef linked_ptr<ReliablePacketInfo> MCSPacketInternal; | 175   typedef linked_ptr<ReliablePacketInfo> MCSPacketInternal; | 
| 174 | 176 | 
| 175   // Resets the internal state and builds a new login request, acknowledging | 177   // Resets the internal state and builds a new login request, acknowledging | 
| 176   // any pending server-to-device messages and rebuilding the send queue | 178   // any pending server-to-device messages and rebuilding the send queue | 
| 177   // from all unacknowledged device-to-server messages. | 179   // from all unacknowledged device-to-server messages. | 
| 178   // Should only be called when the connection has been reset. | 180   // Should only be called when the connection has been reset. | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 237 | 239 | 
| 238   // Client state. | 240   // Client state. | 
| 239   State state_; | 241   State state_; | 
| 240 | 242 | 
| 241   // Callbacks for owner. | 243   // Callbacks for owner. | 
| 242   ErrorCallback mcs_error_callback_; | 244   ErrorCallback mcs_error_callback_; | 
| 243   OnMessageReceivedCallback message_received_callback_; | 245   OnMessageReceivedCallback message_received_callback_; | 
| 244   OnMessageSentCallback message_sent_callback_; | 246   OnMessageSentCallback message_sent_callback_; | 
| 245 | 247 | 
| 246   // The android id and security token in use by this device. | 248   // The android id and security token in use by this device. | 
| 247   uint64 android_id_; | 249   uint64_t android_id_; | 
| 248   uint64 security_token_; | 250   uint64_t security_token_; | 
| 249 | 251 | 
| 250   // Factory for creating new connections and connection handlers. | 252   // Factory for creating new connections and connection handlers. | 
| 251   ConnectionFactory* connection_factory_; | 253   ConnectionFactory* connection_factory_; | 
| 252 | 254 | 
| 253   // Connection handler to handle all over-the-wire protocol communication | 255   // Connection handler to handle all over-the-wire protocol communication | 
| 254   // with the mobile connection server. | 256   // with the mobile connection server. | 
| 255   ConnectionHandler* connection_handler_; | 257   ConnectionHandler* connection_handler_; | 
| 256 | 258 | 
| 257   // -----  Reliablie Message Queue section ----- | 259   // -----  Reliablie Message Queue section ----- | 
| 258   // Note: all queues/maps are ordered from oldest (front/begin) message to | 260   // Note: all queues/maps are ordered from oldest (front/begin) message to | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 305   GCMStatsRecorder* recorder_; | 307   GCMStatsRecorder* recorder_; | 
| 306 | 308 | 
| 307   base::WeakPtrFactory<MCSClient> weak_ptr_factory_; | 309   base::WeakPtrFactory<MCSClient> weak_ptr_factory_; | 
| 308 | 310 | 
| 309   DISALLOW_COPY_AND_ASSIGN(MCSClient); | 311   DISALLOW_COPY_AND_ASSIGN(MCSClient); | 
| 310 }; | 312 }; | 
| 311 | 313 | 
| 312 } // namespace gcm | 314 } // namespace gcm | 
| 313 | 315 | 
| 314 #endif  // GOOGLE_APIS_GCM_ENGINE_MCS_CLIENT_H_ | 316 #endif  // GOOGLE_APIS_GCM_ENGINE_MCS_CLIENT_H_ | 
| OLD | NEW | 
|---|