#include "google_apis/gcm/engine/mcs_client.h"
#include <stddef.h>
#include <set>
#include <utility>
#include "base/containers/circular_deque.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "google_apis/gcm/base/mcs_util.h"
#include "google_apis/gcm/base/socket_stream.h"
#include "google_apis/gcm/engine/connection_factory.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
namespace gcm {
namespace {
MCSProto;
const char kMCSCategory[] = …;
const char kGCMFromField[] = …;
const char kIdleNotification[] = …;
const char kHeartbeatIntervalSettingName[] = …;
const int kNoCustomHeartbeat = …;
const int kUnackedMessageBeforeStreamAck = …;
const size_t kMaxSendQueueSize = …;
const int kMaxMessageBytes = …;
bool BuildPersistentIdListFromProto(const std::string& bytes,
std::vector<std::string>* id_list) { … }
}
class CollapseKey { … };
CollapseKey::CollapseKey(const mcs_proto::DataMessageStanza& message)
: … { … }
CollapseKey::~CollapseKey() { … }
bool CollapseKey::IsValid() const { … }
bool CollapseKey::operator<(const CollapseKey& right) const { … }
struct ReliablePacketInfo { … };
ReliablePacketInfo::ReliablePacketInfo() : … { … }
ReliablePacketInfo::~ReliablePacketInfo() = default;
int MCSClient::GetSendQueueSize() const { … }
int MCSClient::GetResendQueueSize() const { … }
std::string MCSClient::GetStateString() const { … }
MCSClient::MCSClient(const std::string& version_string,
base::Clock* clock,
ConnectionFactory* connection_factory,
GCMStore* gcm_store,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
GCMStatsRecorder* recorder)
: … { … }
MCSClient::~MCSClient() = default;
void MCSClient::Initialize(
const ErrorCallback& error_callback,
const OnMessageReceivedCallback& message_received_callback,
const OnMessageSentCallback& message_sent_callback,
std::unique_ptr<GCMStore::LoadResult> load_result) { … }
void MCSClient::Login(uint64_t android_id, uint64_t security_token) { … }
void MCSClient::SendMessage(const MCSMessage& message) { … }
void MCSClient::UpdateHeartbeatTimer(
std::unique_ptr<base::RetainingOneShotTimer> timer) { … }
void MCSClient::AddHeartbeatInterval(const std::string& scope,
int interval_ms) { … }
void MCSClient::RemoveHeartbeatInterval(const std::string& scope) { … }
int MCSClient::GetMinHeartbeatIntervalMs() { … }
void MCSClient::ResetStateAndBuildLoginRequest(
mcs_proto::LoginRequest* request) { … }
void MCSClient::SendHeartbeat() { … }
void MCSClient::OnGCMUpdateFinished(bool success) { … }
void MCSClient::MaybeSendMessage() { … }
void MCSClient::SendPacketToWire(ReliablePacketInfo* packet_info) { … }
void MCSClient::HandleMCSDataMesssage(
std::unique_ptr<google::protobuf::MessageLite> protobuf) { … }
void MCSClient::HandlePacketFromWire(
std::unique_ptr<google::protobuf::MessageLite> protobuf) { … }
void MCSClient::HandleStreamAck(StreamId last_stream_id_received) { … }
void MCSClient::HandleSelectiveAck(const PersistentIdList& id_list) { … }
void MCSClient::HandleServerConfirmedReceipt(StreamId device_stream_id) { … }
MCSClient::PersistentId MCSClient::GetNextPersistentId() { … }
void MCSClient::OnConnectionResetByHeartbeat(
ConnectionFactory::ConnectionResetReason reason) { … }
void MCSClient::NotifyMessageSendStatus(
const google::protobuf::MessageLite& protobuf,
MessageSendStatus status) { … }
MCSClient::MCSPacketInternal MCSClient::PopMessageForSend() { … }
}